/* Predefined variables */
$(document).ready(function() {

	/* Lightbox for jQuery */
	$("a[rel=fancybox]").fancybox();
	$("a[rel=lightbox]").fancybox();
	
	//Pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'dark_square',default_width:800,default_height:500});	

 $("a[rel=popup]").fancybox({
		'width'				 : 800,
		'height'			 : 600,
		'titleShow'		 : false,
    'autoScale'    : true,
    'transitionIn' : 'none',
		'transitionOut': 'none',
		'type'				 : 'iframe',
		'scrolling'    : 'yes',
		'showNavArrows': false,
		'centerOnScroll' : true
	});



	ExternalLinks();
	slider();
	bindRichInteraction();
});

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:1, //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
		}
	}
	
}
