

$(document).ready(function(){
	background();
	menufunctie();
	mouseOverss();
	caseexpand();
	scolll();
	slidert();
	caseclass();
});

function background() {
	
var z = Math.ceil(Math.random()*5);
	
$("body").css("background-image", "url(http://www.podenemus.com/wp-content/themes/podenemus/images/back" +  z + ".jpg)");  
    
};

function caseexpand() {
		
	
		
	 //klik op plaatsen #expandable expand
	$('.ingeklapt').click(function() { //als je waar op klikt
		var casekeuze = $(this).attr('postid');		
		var selected = $('.uitgeklapt[postid='+casekeuze+']');
		var selectedphoto = $('.ingeklapt[postid='+casekeuze+']');
		var oud = $('.uitgeklapt:visible').not(selected);
		//var casenummer = $(this).attr("postnr");
		//var aantal = $(".case").size();
		//var caseheight = 150;
		//var totalheight = aantal * caseheight;
		//var currentheight = casenummer * caseheight;
		//var newheight = currentheight - 210;
		
		//alert(-newheight);
		
		if(oud.length == 0){ // Als waar je op klikt de eerste klik is:
     		//$('#cases').animate({top : -newheight}, 500);
			
			var uitgeklapt = true;
			
			selected.animate({"height": "toggle"},{ duration: 500 }); //en de geselecteerde binnenkomen
			
     		     		
     	} else {
			oud.animate({"height": "hide"}, 500, function() {
			
			var uitgeklapt = true;
			
			//$('#cases').animate({top : -newheight}, 500);
			selected.animate({"height": "toggle"},{ duration: 500 }); //en de geselecteerde binnenkomen
			
			});
		
		}
		
		//klik op sluiten #expandable sluit
					$(".case_sluit").click(function() { //als je waar op klikt
					selected.animate({"height": "hide"}, 500 );
					uitgeklapt = false;
					});

	
	});
    
};

function menufunctie() {

		
	 //klik op plaatsen #expandable expand
	$('.menulink').click(function() { 
		var target = $(this).attr('link');		

		  $('#'+target).animate({"height": "toggle"}, { duration: 500 });
		  $('html, body').animate({ scrollTop: $('#'+target).offset().top-45 }, 'slow');
    
	});
	
	$('.sluit').click(function() { 
		var doelwit = $(this).attr('link');		

		  $('#'+doelwit).animate({"height": "hide"}, { duration: 500 });
		  $('html, body').animate({ scrollTop: $('body').offset().top }, 'slow');
    
	});
	

};

function mouseOverss() {

	$(".ingeklapt").animate({opacity:0.6 }, 10);

 //mouseover een case button naar opacity 80%
	$(".ingeklapt").mouseover(function(){
    	$(this).animate({opacity:1.0}, 100);
    })
   
   //mouseout een case button terug naar opacity 100%
    $(".ingeklapt").mouseout(function(){
    	$(this).animate({opacity:0.6 }, 100);	
    });
    
    $("#scrollUp").animate({opacity:0.6 }, 10);

 //mouseover een case button naar opacity 80%
	$("#scrollUp").mouseover(function(){
    	$(this).animate({opacity:1.0}, 100);
    })
   
   //mouseout een case button terug naar opacity 100%
    $("#scrollUp").mouseout(function(){
    	$(this).animate({opacity:0.6 }, 100);	
    });
    
    $("#scrollDown").animate({opacity:0.6 }, 10);

 //mouseover een case button naar opacity 80%
	$("#scrollDown").mouseover(function(){
    	$(this).animate({opacity:1.0}, 100);
    })
   
   //mouseout een case button terug naar opacity 100%
    $("#scrollDown").mouseout(function(){
    	$(this).animate({opacity:0.6 }, 100);	
    });
    
    
	
};

function scolll() {

var step = 50;
var scrolling = false;

// Wire up events for the 'scrollUp' link:
$("#scrollUp").bind("click", function(event) {
	$(this).animate({opacity:1.0 }, 100);
	
    event.preventDefault();
    // Animates the scrollTop property by the specified
    // step.
    $("#cases").animate({
        scrollTop: "-=" + step + "px"
    });
}).bind("mouseover", function(event) {
    scrolling = true;
    scrollcases("up");
}).bind("mouseout", function(event) {
    scrolling = false;
});


$("#scrollDown").bind("click", function(event) {
	$(this).animate({opacity:1.0 }, 100);	
	
    event.preventDefault();
    $("#cases").animate({
        scrollTop: "+=" + step + "px"
    });
}).bind("mouseover", function(event) {
    scrolling = true;
    scrollcases("down");
}).bind("mouseout", function(event) {
    scrolling = false;
});

/*
$(".laatste").click( function(event) {
	 var amountx = ("-=500px");
    $("#cases").animate({
        scrollTop: amountx,
    }, 500);
}); 
*/

function scrollcases(direction) {
    var amount = (direction === "up" ? "-=5px" : "+=5px");
    $("#cases").animate({
        scrollTop: amount,
    }, 1, function() {
        if (scrolling) {
            scrollcases(direction);
        }
    });
}

};

function slidert() {

	$("#slider65").easySlider({
		auto: true,
		continuous: false 
	});
	
};

function caseclass() {
	
			$(".case:last").addClass("laatste");
    
};
