/* Predefined variables */
$(document).ready(function() {
	/* PrettyPhoto for jQuery */
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'facebook'});
	/* Youtube z-index */	
	$("iframe").each(function(){
      var ifr_source = $(this).attr('src');
      var wmode = "?wmode=transparent";
      $(this).attr('src',ifr_source+wmode);
	});
	
	ExternalLinks();
	slider();
	bindRichInteraction();
});

function jsAlert(title,content)
{
	var boxHeight = 300;
	var box = '';
	    box += '<strong>'+title+'</strong><br/><br/>'
	    box += '<p>'+content+'</p>'
			$.fn.prettyPhoto({social_tools:false,theme:'facebook'});
			$.prettyPhoto.open('/images/knvts.png', '','<h3 class="center">'+title+'</h3><br/><br/><p class="black font11 center">'+content+'</p><br/>');
}

function ExternalLinks()
{
	var hostname = window.location.hostname;
 hostname = hostname.replace("www.","").toLowerCase();
 var a = document.getElementsByTagName("a");
 this.check = function(obj) { var href = obj.href.toLowerCase(); return(href.indexOf("http://")!=-1&&href.indexOf(hostname)==-1)?true:false; };
 this.set=function(obj) { obj.target="_blank"; };
 for (var i=0;i<a.length;i++) { if (a[i].getAttribute('rel') != 'popup') { if (check(a[i])) { set(a[i]); } } }
}
  
function slider(){
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
}

function bindRichInteraction(){

		/* Clear & Restore input
	$('input[type=text]').bind({
		focus: function(){ if ($(this).val() == $(this)[0].defaultValue) $(this).val(''); },
		blur:  function(){ if ($(this).val() == "") $(this).val($(this)[0].defaultValue); }
	});
*/
	/* Producten aanklikbaar */
	$("#producten li").bind({
		click: 			function(){ window.location = $(this).find("a").attr("href"); },
		mouseenter: function(){ $(this).addClass("active") },
		mouseleave: function(){ $(this).removeClass("active") }
	});
	$("#producten li").addClass("clickable");	
	$("span.close").addClass("clickable");
	
	/* In uitschakelen formulier elementen */
	$('.toggleFormParts').each(function(){ toggleFormPart($(this)) } );
	
	$('.toggleFormParts').bind({ click: function(){ toggleFormPart($(this)) } });
	
	function toggleFormPart(e){
		var targetE = '#part'+ e.attr('rel') +'Adres';
		var targetSpry = e.attr('rel');
		var eVisible = e.is(':checked');
		if (eVisible){
			$(targetE).removeClass("jsHide");
			// Spryregels toevoegen op basis van variabele targetSpry
		}else{
			$(targetE).addClass("jsHide");
			// Spryregels verwijderen op basis van variabele targetSpry
		}
	}
	
}
