$(document).ready(function(){
	
	$.preloadCssImages();
	
	Cufon.replace('#mainmenu li a span, h3, #teaser .items li a, .interactionblock strong, h1, h2, #submenu li a, .interactionblock2, ul#persons li strong, h4', { fontFamily: 'Univers', hover:true });
	
	$('a[rel*=external], a[rel*=nofollow]').click(function(){
		 this.target = "_blank";
	});
	
	$('#login input').keypress(function(e) {
        if(e.which == 13) {
       		$('form#login').submit();
        }
    });

	
	
	/*
	$(".interactionblock").hover(function(){
		Cufon.replace('.interactionblock strong', { fontFamily: 'Univers' });		
	},function(){
		Cufon.replace('.interactionblock strong', { fontFamily: 'Univers' });	
	});
	*/
	
	$widthslideshow = $("#teaser.slideshow").width();
	$widthnavigation = $("#teaser.slideshow .navigation").width();
	$left = ($widthslideshow-$widthnavigation)/2;
	$("#teaser.slideshow .navigation").css({"left":$left+"px"});
	
	/* Footer */
	$total = $(".wrapper.content").height()+$(".wrapper.header").height()+$("#footer").height();
	$document = $(document).height();
	if($document-$total>0){ 
		$difference = $document-$total;
		$("#footer").css({'margin-top':$difference+"px"});
	}
	$(window).resize(function(){
		$total = $(".wrapper.content").height()+$(".wrapper.header").height()+$("#footer").height();
		$document = $(document).height();
		if($document-$total>0){ 
			$difference = $document-$total;
			$("#footer").css({'margin-top':$difference+"px"});
		}
	});
	/* Footer */
	
	/* Content height */
	//console.log($("#content #left").height(),$("#content #right").height());
	setTimeout(function(){
		if($("#content #left").height()>$("#content #right").height()){
			$("#content #right").height($("#content #left").height()+"px");
		}
		else {		
			$("#content #left").height($("#content #right").height()+"px");
		}
	},100);
	/* Content height */
	
	
	
	
	
	
	
	
	
	
	/* Slideshow */
	$current = 0;
	$("#teaser .items li, #teaser .navigation li").each(function(){
		$(this).attr("rel",($(this).index()));
	});
	$("#teaser .items li:not(:first)").hide();
	$(".navigation li:first").addClass("active");
	
	$hover = false;
	$("#teaser").hover(function(){
		$hover = true;
	}, function(){
		$hover = false;
	});
	
	$totalslides = $("#total").val();
	$totalslides = $(".items > li").size();
	//alert($(".items > li").size());
	
	
	setInterval(function(){
		if(!$hover){
			$("#teaser .items li:eq("+$current+")").stop(true,true).fadeOut("slow");
			$current++;
			if($current>=($totalslides)){ $current = 0; }
			$("#teaser .items li:eq("+$current+")").stop(true,true).fadeIn("slow");
			//console.log($current,$totalslides);
			updateNavigation($current);
		}
	},4000);
	$active = false;
	$("#next").click(function(){
		if(!$active){
			$active=true;
			$("#teaser .items li:eq("+$current+")").fadeOut(1000);
			$current++;
			if($current>=($totalslides)){ $current = 0; }
			$("#teaser .items li:eq("+$current+")").fadeIn(1000);
			updateNavigation($current);
			setTimeout(function(){$active=false},1000);
		}
	});
	$("#previous").click(function(){
		if(!$active){
			$active=true;
			$("#teaser .items li:eq("+$current+")").fadeOut(1000);
			$current--;
			if($current<0){ $current = $totalslides-1; }
			$("#teaser .items li:eq("+$current+")").fadeIn(1000);
			updateNavigation($current);
			setTimeout(function(){$active=false},1000);
		}
	});
	
	$(".navigation a").click(function(){
		$("#teaser .items li:eq("+$current+")").fadeOut(1000);
		$current =$(this).parent().attr("rel");
		$("#teaser .items li:eq("+$current+")").fadeIn(1000);
		updateNavigation($current);
	});
	/* END Slideshow */
	
	
	
	$("a.forget").click(function(){
		$(".forgetInfo").fadeToggle('slow', function() {
			// Animation complete.
		  });
	});
	
	
	
	
	
	$(".block > .interactionblock:even, ul.newsletters li:even, ul#persons li:even").addClass("even");
	$("#info p:last > a").addClass("more");
	
	Shadowbox.init({onOpen:function(){
		$("iframe").ready(function(){
			setTimeout(function(){Cufon.replace('#sb-title-inner', { fontFamily: 'Univers', hover:true });},400);
		});
	}});
	
	$("select[name=category]").change(function(){
		window.location.href="/referenties/"+$(this).attr("value");
	});
	
	$(".picker a").each(function(){
		$colourBlock = $(this).attr("name");
		$(this).css('background-color', '#'+$colourBlock);
	});
	
		/* Colour app */
	$("#colourapp .picker .left a").click(function(){
		$colour = $(this).attr("name");
		$(this).parent("li").parent("ul").parent(".colorStyle").parent("div").parent(".picker").parent("#colourapp").find("#image").css("background","#"+$colour);
		if($(this).hasClass("wood")){
			$('#texture').css('background', 'url(/~siteDesign/site/~img/kleurenapp/woodtexture.png) left top repeat');
		}else{
			$('#texture').css('background', 'none');
		}
		$(".picker .left a").each(function(){
			$(this).removeClass('active');
		});
		$(this).toggleClass('active');
	});
	$("#colourapp .picker .right a").click(function(e){
		e.preventDefault();
		$kozijn = $(this).html().replace(" ","-").replace("è","e").toLowerCase();
		$("#colourapp > #image > div.left, #colourapp > #image > div.right").remove();
		$("#colourapp > #image").append("<div class=\"left\"><img src=\""+$(this).attr('href')+"\" alt=\"\"/></div><div class=\"right\"><img style=\"margin-left:-393px;\" src=\""+$(this).attr('href')+"\" alt=\"\"/></div>");
		
		$(".picker .right a").each(function(){
			$(this).removeClass('active');
		});
		$(this).toggleClass('active');
	});
	$("#colourapp div.right a").each(function(){
		$("#colourapp").prepend("<img src=\""+$(this).attr('href')+"\" alt=\"\"/>");
	});
	
	
	
	
	$('#colourapp .picker a[title]').tooltip({delay: 0});
	/*$('#colourapp .picker a').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		extraClass: "pretty", 
		fixPNG: true, 
		opacity: 0.95, 
		left: -120 
	});*/
	
	/* Colour app */
	
	
	
});
