var uagent = navigator.userAgent.toLowerCase();
function getDocHeight() {
//	alert($(document).height() +" - "+ $(window).height());
    return Math.max(
        $(document).height(),
        $(window).height(),
        /* For opera: */
        document.documentElement.clientHeight
    );

}
function resetSizes(){
	var viewportwidth;
	 var viewportheight;
  var viewportwidth = 0, viewportheight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    viewportwidth = window.innerWidth;
    viewportheight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    viewportwidth = document.documentElement.clientWidth;
    viewportheight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    viewportwidth = document.body.clientWidth;
    viewportheight = document.body.clientHeight;
  }
if(uagent.search('iphone') > -1 || uagent.search('ipad') > -1) {
	if(viewportwidth < 1000) viewportwidth = $(window).width();
}else if(viewportwidth < 1101) viewportwidth = 1101;

  var width = (viewportwidth - 1600)/2;
	//alert(viewportwidth+"_"+$(window).width());
	$('#slider').css('left',width+'px');
			$('.slider-wrap').css('overflow','hidden');
			$('body').css('width',viewportwidth+'px');
			$('html').css('width',viewportwidth+'px');
			if(viewportwidth <= 1101){
				$('html').css('overflow-x','scroll');
				$('body').css('overflow-x','scroll');
			}else{
				$('html').css('overflow-x','hidden');
				$('body').css('overflow-x','hidden');
			}
			$('.slider-wrap').css('width',viewportwidth+'px');
			var width = (1600 - 961)/2;
			$('.slider_title').css('left',width+'px');
			$('.nivo-nextNav').css('right',(width+0)+'px');
			$('.nivo-prevNav').css('right',(width+33)+'px');
			var width = (viewportwidth - 961)/2;
			$('.slider-up').css('right',(width+0)+'px');
			$('.slider-down').css('right',(width+0)+'px');
	if(close == ''){

		//console.log('open');

		if((getDocHeight()-590) < viewportheight)
		{	
			$('.background-wrap').css('height',(getDocHeight()-590)+'px');
		}
		else
		{
			$('.background-wrap').css('height',$('.contents').height()+'px');
		}
			
	}
	else
	{
		//console.log('gesloten');
		if((getDocHeight()-130) < viewportheight)
		{
			//console.log(1);
			$('.background-wrap').css('height',(getDocHeight()-230)+'px');
		}
		else
		{
			//console.log(2);
			$('.background-wrap').css('height',$('.contents').height()+'px');
		}
		$('.nivo-nextNav').hide();
					$('.nivo-prevNav').hide();
					$('.slider-down').show();
	}
	jQuery.ajax({
			type: "POST",
			url: site+"js/ajax.php",
			data: "sizes=yes&width="+viewportwidth+"&height="+viewportheight+"",
			success: function(msg){
				
			}
		});
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
 // silder
	   $(document).ready(function() {
			$('#slider').nivoSlider({
				effect:'fade', 
				animSpeed:900, 
				pauseTime:3000,
				manualAdvance:false
			});
			//if(sizes != 'yes') 
			//resetSizes();
			
		});
	   
	   var resizeTimer;
		$(window).resize(function() {
			var ie = getInternetExplorerVersion();
			if(ie == -1){
				clearTimeout(resizeTimer);
				resizeTimer = setTimeout(resetSizes, 100);
			}
			//console.log('resized timer');
		});
		
		//$(window).load(function() {
		jQuery(document).ready(function() {
			resetSizes();							
		});

		function openSlider(){
			jQuery.ajax({
				type: "POST",
				url: site+"js/ajax.php",
				data: "slider=open",
				success: function(msg){
					
				}
			});
						
			var viewportwidth;
			var viewportheight;
			  var viewportwidth = 0, viewportheight = 0;
			  if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				viewportwidth = window.innerWidth;
				viewportheight = window.innerHeight;
			  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				viewportwidth = document.documentElement.clientWidth;
				viewportheight = document.documentElement.clientHeight;
			  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				viewportwidth = document.body.clientWidth;
				viewportheight = document.body.clientHeight;
			}
				if(uagent.search('iphone') > -1 || uagent.search('ipad') > -1) {
					if(viewportwidth < 1000) viewportwidth = $(window).width();
				}			  
			if(($('.contents').height()+630) < viewportheight){
				$('.background-wrap').animate({
					height: (getDocHeight()-630)+'px',
					marginTop: '0px'
				  }, 1000,function(){
						$('.nivo-nextNav').show();
						$('.nivo-prevNav').show();
						$('.slider-down').hide();
				  });
			}else{
				$('.background-wrap').animate({
					height: ($('.contents').height())+'px',
					marginTop: '0px'
				  }, 1000,function(){
						$('.nivo-nextNav').show();
						$('.nivo-prevNav').show();
						$('.slider-down').hide();
				  });

			}
		}
		function closeSlider(){
			
			jQuery.ajax({
				type: "POST",
				url: site+"js/ajax.php",
				data: "slider=close",
				success: function(msg){
					
				}
			});
		var viewportwidth;
			var viewportheight;
			  var viewportwidth = 0, viewportheight = 0;
			  if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				viewportwidth = window.innerWidth;
				viewportheight = window.innerHeight;
			  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				viewportwidth = document.documentElement.clientWidth;
				viewportheight = document.documentElement.clientHeight;
			  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				viewportwidth = document.body.clientWidth;
				viewportheight = document.body.clientHeight;
			  }
			if(uagent.search('iphone') > -1 || uagent.search('ipad') > -1) {
				if(viewportwidth < 1000) viewportwidth = $(window).width();
			}
			if(($('.contents').height()+290) < viewportheight){
				
				$('.background-wrap').animate({
					height: (viewportheight-290)+'px',
					marginTop: '-379px'
				  }, 1000,function(){
						$('.nivo-nextNav').hide();
						$('.nivo-prevNav').hide();
						$('.slider-down').show();
				  });
			}else{
				$('.background-wrap').animate({
					marginTop: '-379px'
				  }, 1000,function(){
						$('.nivo-nextNav').hide();
						$('.nivo-prevNav').hide();
						$('.slider-down').show();
				  });
			}
			
		}
		// menu
		function sett(){
			jQuery('.main-menu').find('li').each(function(){
				if(jQuery(this).find('.submenu')){
					jQuery(this).find('.submenu').css('display','block');
					var width = 0;
					jQuery(this).find('.submenu').find('a').each(function(){
						var wid = 0;
						jQuery(this).find('.cufon').each(function(){
							wid += (jQuery(this).width()+0);
						});
						
						jQuery(this).css('width',wid+'px');
						width += (wid+30);
						
					});
					jQuery(this).find('.submenu').css('width',(width)+'px');
					jQuery(this).find('.submenu').css('position','absolute');
					jQuery(this).find('.submenu').css('visibility','visible');
				}
			});
			jQuery('.submenu').hide();
		}
		jQuery(document).ready(function() {
			jQuery(this).find('.submenu').css('visibility','visible');
			var t=setTimeout("sett()",100);
			jQuery('.main-menu').find('li').hover(
			  function () {
				jQuery(this).addClass('menu-extra');
				//if(jQuery(this).find('.submenu').css('display') == 'none') 
				jQuery(this).find('.submenu').show();
				//jQuery(this).find('.submenu').fadeIn();
			  }, 
			  function () {
				//jQuery(this).find('.submenu').fadeOut();
				jQuery(this).find('.submenu').hide();
				jQuery(this).removeClass('menu-extra');
			  }
			);
		});
		function requestInfo(site,which,url){
	jQuery.ajax({
			type: "POST",
			url: site+"js/ajax.php",
			data: "getInfo=yes&which="+which+"",
			success: function(msg){
				window.location = url;
			}
		});
	return false;
}
function checkInput(text,ref){
	if(ref.value == text) ref.value='';
}
function checkInput2(text,ref){
	if(ref.value == '') ref.value=text;
}
function getRoute(site,address,text,toaddress){
	if(address != '' && address != text){
		$('#address').removeClass('activee')
		window.open('http://maps.google.nl/maps?f=d&source=s_d&saddr='+address+'&daddr='+toaddress+'&hl=nl&geocode=&mra=ls');
	}else{
		$('#address').addClass('activee')
	}
	return false;
}
