// JavaScript Document

var bgstatus;
var old_bgstatus;


function checkSize() { 
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		schermhoogte = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		schermhoogte = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientHeight ) ) {
		//IE 4 compatible
		schermhoogte = document.body.clientHeight;
	}
	if(schermhoogte<=768){ 
	document.write('<link rel="stylesheet" type="text/css" href="http://www.lucaya.nl/css/lores.css" />') ;  
	} 
}
function CufonReplace() {
	Cufon.replace('h1', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('#hoofdmenu-wrapper a', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('#submenu a', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('#item-menu a', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('.tilde', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('.copyright', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('.bedrag', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('.vanafprijs', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('.knop-reserveren', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	
	Cufon.replace('.nieuwskop', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('.replace', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	
	Cufon.replace('#vlakbreed-links ul li a', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('#vlakbreed-links ul li span', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
	Cufon.replace('#vlakbreed-links ul li ul li a', { fontFamily: 'Ocean Sans Std Semibold', hover: true } );
}

/* Backgrounds preloader */
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

/*
jQuery.preLoadImages("image1.jpg", "afbeeldingen/achtergronden/1.jpg");
jQuery.preLoadImages("image2.jpg", "afbeeldingen/achtergronden/2.jpg");
jQuery.preLoadImages("image3.jpg", "afbeeldingen/achtergronden/3.jpg");
jQuery.preLoadImages("image4.jpg", "afbeeldingen/achtergronden/4.jpg");
jQuery.preLoadImages("image5.jpg", "afbeeldingen/achtergronden/5.jpg");
jQuery.preLoadImages("blur.jpg", "afbeeldingen/achtergronden/blur.jpg");*/

function setBgStatus(x){
	bgstatus = x;
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

/* Ipromptu Alternative */
$(document).ready(function(){

	setTimeout(function() { 
		$('#nieuwsticker-wrapper').fadeIn(800); 
		$('#nieuwsticker-wrapper2').fadeIn(800); 
	},1000);
	
	$("#sluiten").click(function(){
	  $("#nieuwsticker-wrapper").fadeOut(600);
	});
	
	var localError = "<p style=\"color: #000;\">Er zijn fouten in deze velden:</p>";
	
	$('#opener').click(function() {
		
		
		var localErrorNo = 0;
		
		$(".form-wrapper1 > input, .form-wrapper1 > div > input, .form-wrapper1 > div > div > input").each(function(){
			var inputval = $(this).val();
			var inputname = $(this).attr("name");
			if (inputname == "Vraag"){
				if (inputval.length <= 1){
					localError = localError + "<p style=\"color: #000; padding-left: 10px;\">" + inputname + "</p>";
					localErrorNo++;
				}
			}else{
				if ((inputval.length <= 1) || (inputval.length > 255)){
					localError = localError + "<p style=\"color: #000; padding-left: 10px;\">" + inputname + "</p>";
					localErrorNo++;
				}
			}
		});
		
		if (localErrorNo == 0){
		$(".form-wrapper1 > input, .form-wrapper1 > div > input, .form-wrapper1 > div > div > input").each(function(){
			var inputval = $(this).val();
			var inputname = $(this).attr("name");
			
			if (inputname == "Email"){
				if (!isValidEmailAddress(inputval)){
					localError = localError + "<p style=\"color: #000; padding-left: 10px;\">" + inputname + " is niet goed.</p>";
					localErrorNo++;
				}
			}
			
			
		});
		}
		
		if (localErrorNo > 0){
			var $dialog = $('<div></div>')
				// Here goes all error messages that popup from the contact form like forgotten mandatory fields
				.html(localError)
				.dialog({
					autoOpen: false,
					title: 'Waarschuwing'
		
				});
			$dialog.dialog( "option", "modal", true );
			$dialog.dialog('open');
			
			localError = "<p style=\"color: #000;\">Er zijn fouten in deze velden:</p>";
			localErrorNo = 0;
			
			return false;
		}else{
			$("#contact_form").submit();
		}
	});


/* Animation & CSS */
	
function help_fix(child){
      	if (child.height() == 0){
			child.stop(true, true).animate({ 
        		height: "46px"
      		}, 300, "swing" );
      	}else{ // we came from child under
      		child.stop(true, true).css("height", "46px");
      	}
	      	
}


	bgstatus = 'link_0';
	old_bgstatus = 'link_0';
		
	$("div#hoofdmenu-wrapper ul li a[id^='link_']").hover(function(){
		var aIdIndex = $(this).attr("id").split("_")[1];
		var bgs = "link_"+aIdIndex;	
		if (bgstatus != bgs) {
			setBgStatus(bgs);
			$(".background").stop(true, true).fadeOut(600,function(){
				$(".background").fadeIn(600).css("background-image", "url("+menu_backgrounds[bgs]+")");
			});				
      	}
	
		$(this).parent().children(".hoofdmenu-subkop").stop(true, true).animate({ 
        		height: "46px"
      		}, 300, "swing" );	
		
	}, function(){
		var aIdIndex = $(this).attr("id").split("_")[1];
		
		$(this).parent().children(".sl_"+aIdIndex).stop(true, true).animate({ 
        		height: "0px"
      		}, 300, "swing" );
      	help_fix(".sl_"+aIdIndex);
      	
	});

	
	$("#hoofdmenu-wrapper li a").mouseleave(function(){
	  $(this).parent().children(".hoofdmenu-subkop").stop(true, true).animate({ 
        height: "0px"
      }, 300, "swing" );
    });
    
    $(".hoofdmenu-subkop").hover(function(){
	    	$(this).stop(true, true).animate({ 
	        		height: "46px"
	      		}, 300, "swing" );

    }, function(){
    	$(this).stop(true, true).animate({ 
        		height: "0px"
      		}, 300, "swing" );
    });
	
	$("#voorwaarden").click(function(){		
	
	if($("#algemene-voorwaarden").height() < 200){
	
		$.ajax({
		  url: 'getVoorwaarden',
		  async: false,
		  success: function(data) {
					var titleinput = data;
					$("#algemene-voorwaarden").html(titleinput);
		  }
		});
	
	  $("#algemene-voorwaarden").animate({ 
        height: "200px"
      }, 300, "swing" );
    }else{
	  $("#algemene-voorwaarden").animate({ 
        height: "0px"
      }, 300, "swing" );
    }
	  return false;
    });
	
	$("#gelezen").click(function(){
	  $("#algemene-voorwaarden").animate({ 
        height: "1px"
      }, 300, "swing" );
	  return false;
    });
	
	$("div#hoofdmenu-wrapper ul").hover(function(){
	}, function(){
		setBgStatus(old_bgstatus);
		$(".background").stop(true, true).fadeOut(600,function(){
			$(".background").fadeIn(600).css("background-image", "url("+menu_backgrounds[old_bgstatus]+")");
		});
	});
	
});
