/* Predefined variables */
$(document).ready(function() {
	
	ExternalLinks();
	
	/* Lightbox for jQuery */
	$("a[rel=fancybox]").fancybox();
	$("a[rel=lightbox]").fancybox();

  jQuery('#blok_products_2').jcarousel();
	
	slider();
	slider_small();
	bindRichInteraction();
  Vraag();	
  Logo();

});

function ExternalLinks()
{
	var hostname=window.location.hostname;hostname=hostname.replace("www.","").toLowerCase();	var a=document.getElementsByTagName("a"); this.check=function(obj){ var href = obj.getAttribute('href').toLowerCase(); return(href.indexOf("http://")!=-1&&href.indexOf(hostname)==-1)?true:false; }; this.set=function(obj){ obj.target="_blank"; obj.className="external"; }; for(var i=0;i<a.length;i++){ if(check(a[i])) set(a[i]); }; 	
};

function Vraag()
{
	$('#tekst_blok').innerfade({
		animationtype: 'fade',
		speed: 400,
		timeout: 6000,
		type: 'sequence'
	});
}

function Logo()
{
	$('.logos').innerfade({
		animationtype: 'fade',
		speed: 400,
		timeout: 6000,
		type: 'sequence'
	});
}

function slider_small(){
	$('#slider_small').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:true, //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:true, //Force manual transitions
		captionOpacity:1, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
}
  
function slider(){
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:true, //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(){ $(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
		}
	}
	
}
