$(document).ready(function() {
	
		$('.scrollpane').jScrollPane({showArrows:true,scrollbarWidth:11, scrollbarMargin:10, arrowSize: 11});
		$('.scrollwide').jScrollPane({showArrows:true,scrollbarWidth:11, scrollbarMargin:10, arrowSize: 11});
		$('.scrollmedium').jScrollPane({showArrows:true,scrollbarWidth:11, scrollbarMargin:10, arrowSize: 11});
		$('.scrollarchief').jScrollPane({showArrows:true,scrollbarWidth:11, scrollbarMargin:10, arrowSize: 11});
		
		
		
		
		//$(".projectenoverzicht .post:not(:first) .entry, .archiefnieuws .post .entry").hover(
		$(".projectenoverzicht .post .entry").hover(
			function () {
				first = $(".projectenoverzicht .post:first .entry").attr("id");
				$("."+first).css("display","none"); 
				var which = $(this).attr("id");
				$("."+which).fadeIn(); 
			}, 
				function () {
				var which = $(this).attr("id");
				$("."+which).fadeOut("fast"); 
			}
		);
		$(".archiefnieuws .post .entry").hover(
			function () {
				first = $(".projectenoverzicht .post:first .entry").attr("id");
				$("."+first).css("display","none"); 
				var which = $(this).attr("id");
				$("."+which).fadeIn(); 
				$("."+which).appendTo(".archiefnieuws")
				//alert(which)
			}, 
				function () {
				var which = $(this).attr("id");
				$("."+which).fadeOut("fast"); 
			}
		);
	
		$(".actueelnieuws .post").hover(
			function () {
				$(this).addClass("posthover");
			}, 
				function () {
				$(this).removeClass("posthover");
			}
		);
	
	$(".showdetail").click(
		function(){
			$(".postinfo").fadeOut("fast")	;
			$(".detailedinfo").fadeIn("slow")	;
			$(".postcontent").fadeIn("slow")	;
			$(this).parent().removeClass("iconpost");
			$(this).parent().addClass("icondetail");
		}
	);
	$(".showpost").click(
		function(){
			$(".detailedinfo").fadeOut("fast")	;
			$(".postinfo").fadeIn("slow")	;
			$(".postcontent").fadeIn("slow")	;
			$(this).parent().removeClass("icondetail");
			$(this).parent().addClass("iconpost");
		}
	);
	
	$(".alleprojecten li:not(:last) .naam").append(",");
	$(".archiefimages div:first").fadeIn();
	$(".projectenoverzicht .post:first .summary").fadeIn();
	$(".detailedinfo").hide();
	
	$(".alleprojecten li:not(:first)").hover( 
		function () {
			postid  = $(this).find(".post").attr("id");
			$(".archiefimages div."+postid).fadeIn("fast");
		}, 
		function () {
			postid  = $(this).find(".post").attr("id");
			$(".archiefimages div."+postid).fadeOut("fast");
		}
	);
	
	createVak();
	
	$(".jScrollPaneDrag").hover(
		function () {
			$(this).css("background-color","#f7931d")
		}, 
		function () {
			$(this).css("background-color","#C2BEBB")
		}
	);
});


$(window).load(function(){
	$(".spinner").fadeOut("fast");
	$(".slide1 .image").fadeIn(2000);
	$(".hokje-1").addClass("currenthokje");  
	$(".slide1").addClass("currentimg");
	
	$(".hokje").click(function () { 
		which = $(this).html(); 
		slideSlide(which);
	});
	if ($(".hokje").length < 2){
		$(".hokjes").css("display","none");
		//oldHTML = $(".slidecontainer .currentimg .image a").html();
		//$(".slidecontainer .currentimg .image").html(oldHTML);
	}
});
function slideshowhome(){
	//$(".slides").unbind(click).bind(click)
	$(".slides .slide a").attr("href", "index.php/bureau/profiel");
	$(".slides .slide a img").unbind("click");
	$(".slides .slide a").unbind("click").bind("click", function(e){
     	document.location.href = "index.php/bureau/profiel";
    });
	$(".slides .slide img").bind("click", function(e){
     	document.location.href = "index.php/bureau/profiel";
    });
	$(".slides .slide a").css("display","none");
	hoeveel = $(".hokje").length;
	deze = $(".currenthokje").text() -0;
	if (deze == hoeveel){
		volgende = 1;
	} else {
		volgende = deze + 1;
	}
	slideSlide(volgende);
	setTimeout(slideshowhome,4000);
}
function createVak(){
	var amount = $(".amount").text();
	for (i=0;i<=11-amount;i++) {
		$(".projectenoverzicht").append("<div class=\"leegvak\"></div>")
	}
	for (i=0;i<=23-amount;i++) {
		$(".archiefnieuws .scrollpane").append("<div class=\"leegvak\"></div>")
	}
}
function slideSlide(which) {
	if ( $(".slide"+which).hasClass("currentimg") ) {
		// can't slide in picture that is allready slided in
	} else {
		if ( $(".slide"+which).length > 0 )  {
			$(".info-icons").removeClass("iconpost").removeClass("icondetail");
			$(".currentimg .image").fadeOut("slow");
			
			$(".slide"+which+" .image").fadeIn("slow");
			
			$(".currentimg .caption").fadeOut("slow");
			$(".currentimg").removeClass("currentimg");
			$(".slide"+which).addClass("currentimg");
			$(".currenthokje").removeClass("currenthokje");
			$(".hokje-"+which).addClass("currenthokje");
			$(".postcontent").fadeOut("slow");
			$(".slide"+which+" .caption").fadeIn("slow");
			if (which == 1){
				$(".currentimg .caption").fadeOut("fast");
				$(".postcontent").fadeIn("fast");
				$(".info-icons").addClass("iconpost");
			}
		} else {
			str = $(".postid").text();
			if (which == 0 ) {
				
				if ($(".link-"+str).prev().length > 0 )  {
				document.location.href = $(".link-"+str).prev().text();
				} else {
					if ($("#mainnavigation  li.this a").length > 0){
					gekozen = $("#mainnavigation  li.this a").attr("href");
					} else if ($("#mainnavigation  li.current_page_item a").length > 0){
					gekozen = $("#mainnavigation  li.current_page_item a").attr("href");
					} else {
					gekozen  = "<?php bloginfo('url'); ?>";
					}	
					document.location.href = ""+gekozen+"";
				}
				
			} else {
						
				if ($(".link-"+str).next().length > 0 )  {
					document.location.href = $(".link-"+str).next().text();
				} else {
					if ($("#mainnavigation  li.this a").length > 0){
					gekozen = $("#mainnavigation  li.this a").attr("href");
					} else if ($("#mainnavigation  li.current_page_item a").length > 0){
					gekozen = $("#mainnavigation  li.current_page_item a").attr("href");
					} else {
					gekozen  = "<?php bloginfo('url'); ?>";
					}	
					document.location.href = ""+gekozen+"";
				}
			}
		}
	}
}
