// JavaScript Document
$(document).ready(function(){  

	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 30, // number = milliseconds for onMouseOver polling interval    
		 over: uitschuiven, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: inschuiven // function = onMouseOut callback (REQUIRED)    
	};


	function uitschuiven(){
      if (!$(this).children(".textoverlay").is(':animated') ) { 
	  $(this).children(".textoverlay").animate({ 
        top: "56px"
      }, 400, "easeInOutBack" );
	  }
    };
	
	function inschuiven(){
	$(this).stop();
      if (!$(this).children(".textoverlay").is(':animated') ) { 
	  $(this).children(".textoverlay").animate({ 
        top: "115px"
      }, 400, "easeInOutBack" );
	  }
    };
	
	$(".fotoframe a").mouseover(function(){
	 	$(this).children(".overlay").css('display','block');
	});	
	$(".fotoframe a").mouseout(function(){
	 	$(this).children(".overlay").css('display','none');
	});	

   // Using multiple unit types within one animation.
    $(".block").hoverIntent( config );

	$('.pics').cycle({ 
		fx:    'fade',
		speed:    1000, 
	    timeout:  5000 
	 });

	$(".ref-detail").click(function() { 
		$(".projectlink").css("display","block");

		//$(".projectcontent").slideUp(300);
		$(".projectcontent").css("display","none");
		
		$(this).parent().css("display","none");
		
		//setTimeout ($(this).parent().next().slideDown(), 1500);
		$(this).parent().next().css("display","block");
		return false;
	});
	
   	$("#zoeken").click(function(){
      $("#zoeken").addClass("search-wrapper-active");
	  $("#zoeken").removeClass("search-wrapper-inactive");
	  $("#zoeken").attr({value:""});
    });
   	$("#nieuwsbrief-veld").click(function(){
      $("#nieuwsbrief-veld").addClass("search-wrapper-active");
	  $("#nieuwsbrief-veld").removeClass("search-wrapper-inactive");
	  $("#nieuwsbrief-veld").attr({value:""});
    });	
   	$("#zoek-knop").click(function(){
	 	document.frm_zoeken.submit();
		return false;
	});
   	$("#verzend-nieuwsbrief").click(function(){
	 	document.frm_nieuwsbrief.submit();
		return false;
	});	
	var n = 1;
	$(".popeye1").each(function() {
		$(this).attr("id", "thumbnail" + n);
		var selector = "#" + $(this).attr("id");
		$(selector).popeye();
		n++;
	});

	for (i=0; i<20; i++) { 
		$("a[rel='cbox"+i+"']").colorbox({transition:"elastic"});
	}
	
	$("a[rel='video']").colorbox({transition:"elastic", iframe:"true", width: "650px", height: "541px", overlayClose: false });

	$(".email-knop").colorbox({}, function(){
		 Cufon.replace('#mailcontainer h1', 'Trebuchet_MS_400');
		$("#verzenden").click(function(){   
			var patroon = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var dopost = true;
			if ($("#inp_af_naam").val() == '' || $("#inp_ont_naam").val() == ''){
				dopost = false;
			}
			if (patroon.test($("#inp_af_email").val())==false || patroon.test($("#inp_ont_email").val())==false) {
				dopost = false;
			}
			if (dopost) { 
				$.post("pages/verwerkemail.php",{   
				   inp_af_naam: $("#inp_af_naam").val(),
				   inp_af_email: $("#inp_af_email").val(),
				   inp_ont_naam: $("#inp_ont_naam").val(),
				   inp_ont_email: $("#inp_ont_email").val(),
				   inp_opmerking: $("#inp_opmerking").val(),
				   txt_id: $("#txt_id").val(),			   
				   url: $("#url").val()			   
				});   
				$("#mailform").empty().html("Uw email is verzonden.<br /><br /><a href='javascript:$.fn.colorbox.close();' id='sluiten'>Sluiten</a>");
			} else { 
				$("#foutmeldingemail").css("display","block");
			}			
			return false;   
		});
	});


	$(".block").click(function() { 
		var ref = $(this).children(".textoverlay").children(".introduction").children("a:first").attr("href");
		document.location.href = "/"+ref;
	});

	$("#verzenden").click(function(){
	  if(checkform()){document.frm_contact.submit();}
  	  return false;
	});
	$(".required").focus(function(){
	focusForm($(this));
	});
	$(".required").blur(function(){
	checkObj($(this));
	});	

 Cufon.replace('#container-mid h1', 'Trebuchet_MS_400');
 Cufon.replace('#container-mid h2', 'Trebuchet_MS_400');
 Cufon.replace('#hoofdmenu li a',{ textShadow:'#000000 1px 1px', hover:true}, 'Trebuchet_MS_400');
 Cufon.replace('#container-header-blocks h1',{ textShadow:'#916528 1px 1px', hover:true}, 'Trebuchet_MS_400');
 Cufon.replace('#spoed-container', 'Trebuchet_MS_400');
 Cufon.replace('#verzenden', 'Trebuchet_MS_400');
 Cufon.replace('#sluiten', 'Trebuchet_MS_400');
 Cufon.replace('#herstel', 'Trebuchet_MS_400');

 /*
 Cufon.replace('#login-status a',{ textShadow:'#fff 1px 1px', hover:true}, 'Myriad italic');
 Cufon.replace('.contactpersoon',{ textShadow:'#fff 1px 1px', hover:true}, 'Myriad italic');
 Cufon.replace('#subnav a',{ textShadow:'#fff 1px 1px', hover:true}, 'Myriad italic');
*/

 });

function checkform() {
	var dopost = true;
	var patroon = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	$('.required').each(function(index) {
		if ($(this).val() == ''){
			$(this).addClass("alert"); 
			dopost = false;
		} else { 
			$(this).removeClass("alert");
		}
	});
	$('.checkemail').each(function(index) {
		if (patroon.test($(this).val())==false) {
			$(this).addClass("alert"); 
			dopost = false;
		} else { 
			$(this).removeClass("alert");
		}
	});

	if (!dopost) $('#foutmelding').css("display","block");

	return dopost;
}
function focusForm(obj) { 
	obj.removeClass("alert");
}
function checkObj(obj) { 
	if (obj.val()=='') { 
		obj.addClass("alert");
	}
}


