/* Predefined variables */
var postonwall;
$(document).ready(function() {

	$('a[rel="blank"]').each(function(){
     $(this).attr('target', '_blank');
  });

 //Pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed:'slow',theme:'facebook',default_width:800,default_height:500,overlay_gallery: false,
				 social_tools: '<div class="pp_social">\
												<a class="addthis"></a>\
												<div class="h20"></div>\
  											</div>'
												,changepicturecallback: function(){addthis.button('.addthis');}
	});	
	/* Youtube z-index */	
	$("iframe").each(function(){
      var ifr_source = $(this).attr('src');
      var wmode = "?wmode=transparent";
      $(this).attr('src',ifr_source+wmode);
	});
	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.getAttribute('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(check(a[i])) set(a[i]); }; 	
};



  
function slider(){
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:8000,
		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
		}
	}
	
}
