$(document).ready(function() {
    
    //Recensie button
    $('.recensiebutton').click(function(e){
        e.preventDefault();
        
        url = $(this).attr('data-url');
        
        $.colorbox({
            href: url,
            iframe:true, 
            width: 350, 
            height: 400
        });	   
    })
    
	//Instellen van alle onderdelen op de pagina die bijgeschaald moeten worden
	function stel_pagina_in(){
		hoogte_pagina = $("#content").outerHeight();
		hoogte_submenu = $("#submenu").outerHeight();
		hoogte_venster = $(window).height();
		if(hoogte_pagina>hoogte_submenu){
			$("#submenu").css("height",(hoogte_pagina-315)+"px");
		}		
		totale_hoogte_content = $("#dummy_site_container").outerHeight();
		if(hoogte_venster>totale_hoogte_content){
			$("#site_footer_container").css("margin-top",(hoogte_venster-totale_hoogte_content)+"px");	
		} else {
			$("#site_footer_container").css("margin-top", "0px");
		}
		//Hoogte footermenu
		hoogte_footerblok=0;
		$('.site_footer_contentblok').each(function(){
			if($(this).height() > hoogte_footerblok){hoogte_footerblok=$(this).height();}			
		});
		$('.site_footer_contentblok').css("height",hoogte_footerblok+"px")
	}
	
	//Weergeven van de twitterfeed
	$("#homepagina_twitter_feeds").tweet({
		username: "verkeerspro",
		avatar_size: 0,
		count: 3,
		refresh_interval: 100,
		loading_text: "Tweets laden..."
	},  function(){
		//Callback na het laden van de tweets
		stel_pagina_in();		
	}).bind("loaded",function(){$(this).find("a").attr("target","_blank");});
	
	stel_pagina_in();
	$(window).resize(function(){
		stel_pagina_in();
	});
	
	setTimeout(stel_pagina_in,700);
	
	var huidig_homeblok=1;
	
	$(".homepagina_blokken_content_klein").click(function(){
		activeer_homeblok($(this).attr("rel"));
	});
	
	$(".homepagina_blokken_content_groot").click(function(){
		window.location.replace($(this).attr("href"));
	});
	
	//Werking van de homeblokken
	function activeer_homeblok(nieuwe){
		snelheid=500;
		$(".homepagina_blokken_content_groot[rel='"+huidig_homeblok+"']").slideUp(snelheid, 'easeInOutSine');
		$(".homepagina_blokken_content_klein[rel='"+huidig_homeblok+"']").slideDown(snelheid, 'easeInOutSine');
		$(".homepagina_blokken_content_groot[rel='"+nieuwe+"']").slideDown(snelheid, 'easeInOutSine');
		$(".homepagina_blokken_content_klein[rel='"+nieuwe+"']").slideUp(snelheid, 'easeInOutSine');
		$("#homepagina_blokken_foto_slider").animate({marginTop:-((nieuwe-1)*266)},{queue:false, duration: snelheid, easing: 'easeInOutSine'});	
		huidig_homeblok = nieuwe;
	}
	
	//Werking van de Aanbiedingen fader
	$('#homepagina_aanbiedingen_slider').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 5000,
		type: 'random',
		containerheight: '162px'
	});
	//Werking van de Nieuwe producten fader
	$('#homepagina_nieuwe_producten_slider').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 5000,
		type: 'random',
		containerheight: '162px'
	});
	//Werking van de Online cursussen fader
	$('#homepagina_online_cursussen_slider').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 5000,
		type: 'random',
		containerheight: '162px'
	});
	
	//Slider van de random producten
	$("#homepagina_random_knoplinks").mouseover(function() {
		RandomSlider = setInterval(function(){
			margin_left = $('#homepagina_random_slide').css("margin-left");
			margin_left = margin_left.replace("px","");
			if(margin_left=="auto"){margin_left=0;}
			$breedte_slider=$("#homepagina_random_slide .breedte_dummy").width();
			if(Math.abs(margin_left)==0){ 
				margin_left=0; 
			} else { 
				margin_left++; 
			}
			$('#homepagina_random_slide').css("margin-left", margin_left + "px");
		},6);
	}).mouseout(function(){
		window.clearInterval(RandomSlider);
	});
	
	//Slider van de random producten
	$("#homepagina_random_knoprechts").mouseover(function() {
		RandomSlider = setInterval(function(){
			margin_left = $('#homepagina_random_slide').css("margin-left");
			margin_left = margin_left.replace("px","");
			if(margin_left=="auto"){margin_left=0;}
			breedte_slider=$("#homepagina_random_slide .breedte_dummy").width();
			if(Math.abs(margin_left)==breedte_slider){ 
				margin_left=breedte_slider; 
			} else { 
				margin_left--; 
			}
			$('#homepagina_random_slide').css("margin-left", margin_left + "px");
		},6);
	}).mouseout(function(){
		window.clearInterval(RandomSlider);
	});
	
	
	
	//Handlers van de opties bij een product ( recensies en send a friend weergave);
	$(".optie_product_klik_weergave").click(function() {
		$(".product_detail_optie").fadeOut(50);
		$("."+$(this).attr("id")).slideDown(750);
	});
	
	//Handler bij het klikken op een thumbnail van een product bij de productview
	$(".verander_hoofdfoto_product").click(function() {
		$(".verander_hoofdfoto_product").removeClass("actief");
		$(this).addClass("actief");
		$("#fotolink").attr({
			href: 'shop_images/'+$(this).attr("rel")+'_'+$(this).attr("id")+'_large.jpg',
			title:  $(this).attr("data-title")
		});
		$("#grotefoto").attr({
			src: 'shop_images/'+$(this).attr("rel")+'_'+$(this).attr("id")+'_medium.jpg',
			alt:  $(this).attr("data-title")
		});

	});
	
	
}); 
