// JavaScript Document
//<![CDATA[

$(document).ready(function(){
	
var n = $(this).closest('article').children('.work_visual_overlay');
var aantaltoe = $(this).closest('section').children('article').children('.infobox.closed').size();	

	/*General Controller for infopanes work*/
	$('.general_controller .controls').click(function(){
		  
		  if(
			 
			$(this).hasClass('closed')&(aantaltoe=!0)){	
				
				$(this).closest('section').children('article').children('.infobox.closed').animate({
					left:'+=120',
					easing:'swing'
				}, 500);
				$(this).closest('section').children('article').children('.infobox').children('.controls').removeClass('closed').addClass('open');
				$(this).closest('section').children('article').children('.infobox').removeClass('closed').addClass('open');
				var n = $(this).closest('section').children('article').children('.work_visual_overlay');
				  $(n).fadeOut(500);
				  var t = $(this).closest('section').children('article').children('.infobox').children('.text');
				  $(t).fadeIn(500);
				  
				/*
				$(this).removeClass('closed').addClass('open');
				*/
				return false;	
			} else if(
				$(this).hasClass('open')){
				
				$(this).closest('section').children('article').children('.infobox.open').animate({
					left:'-=120',
					easing:'swing'
				}, 500);
				$(this).closest('section').children('article').children('.infobox').children('.controls').removeClass('open').addClass('closed');
				$(this).closest('section').children('article').children('.infobox').removeClass('open').addClass('closed');
				var n = $(this).closest('section').children('article').children('.work_visual_overlay');
				  $(n).fadeIn(500);
				  var t = $(this).closest('section').children('article').children('.infobox').children('.text');
				  $(t).fadeOut(500);
				  
				/*  
				$(this).removeClass('open').addClass('closed');
				*/
				return false;	
			}
			else	{alert("Something went wrong! Please contact me and tell me when you encountered this, so I can fix it!");
			 // Stop the link click from doing its normal thing
			   return false;	  } 
	 
    });

	/*Individual Controller for infopanes work*/
	$('section .controls').each(function() {
		$(this).click(function(){
			if(
			  $(this).hasClass('closed')){
				  $(this).parent('.infobox.closed').animate({
					  left:'+=120',
					  easing:'swing'
				  }, 500);
				  var n = $(this).closest('article').children('.work_visual_overlay');
				  $(n).fadeOut(500);
				  var t = $(this).parent('.infobox').children('.text');
				  $(t).fadeIn(500);
				  $(this).removeClass('closed').addClass('open');
				  $(this).parent('.infobox').removeClass('closed').addClass('open');
				  return false;	
			  } else if(
				  $(this).hasClass('open')){
				  //alert("clickedopen");
				  $(this).parent('.infobox.open').animate({
					  left:'-=120',
					  easing:'swing'
				  }, 500);
				  var n = $(this).closest('article').children('.work_visual_overlay');
				  $(n).fadeIn(500);
				  var t = $(this).parent('.infobox').children('.text');
				  $(t).fadeOut(500);
				  $(this).removeClass('open').addClass('closed');
				  $(this).parent('.infobox').removeClass('open').addClass('closed');
				  return false;	
			  }
			  else	{alert("Something went wrong! Please contact me and tell me when you encountered this, so I can fix it!");
			   // Stop the link click from doing its normal thing
				 return false;	  } 
		});
	 
    });
	
	
	
	
	/*Count amaount of displayed works*/
	var q = $('#slidebox').children('article').size();
	//$('#slidebox').css('width', q * 510);
	
	/*Slide Right*/
	
	var i = 0;
	
	var w = $(window).width();
	
	var v = Math.floor(w/510);
	
	var s = q-v;
	
	//alert("het venster is: "+w+" en het totaal aantal slides is "+q+" en aantal zichtbare slides is: "+v+" en aantal nodige slides is: "+s);
	
	/*Slide to right
	$('#next').click(function(){
		if(i < s){
			$('#slide_controlbox #prev').animate({opacity:1});
			$('#slidebox').animate({left:'-=510',easing:'swing'}, 1000);
			i ++;
			if(i == s){
				$('#slide_controlbox #next').animate({opacity:0.2});
			}
		} else {
			return false;
		};
	});*/
	
	/*Slide to lef
	$('#prev').click(function(){
		if(i == 1){
			$('#slidebox').animate({left:'+=510',easing:'swing'}, 1000);
			i -=1;
			$('#slide_controlbox #prev').animate({opacity:0.2});
		
		} else if(i > 1){
			$('#slide_controlbox #next').animate({opacity:1});
			$('#slidebox').animate({left:'+=510',easing:'swing'}, 1000);
			i -=1;
		} else {
			return false;
		};
	});t*/
	
	
	/*ContactPane*/
	$('#contactbox .controls').click(function(){
		  if(
			$(this).hasClass('closed')){
				$(this).parent('#contactbox').animate({
					left:'+=120',
					easing:'swing'
				}, 500);
				$(this).parent('#orangeoverlay').fadeIn();
				$(this).removeClass('closed').addClass('open');
			} else if(
				$(this).hasClass('open')){
				//alert("clickedopen");
				$(this).parent('#contactbox').animate({
					left:'-=120',
					easing:'swing'
				}, 500);
				$(this).removeClass('open').addClass('closed');
			}
			else	{alert("iets fout");
			 // Stop the link click from doing its normal thing
			   return false;	  } 
    });
	
});
 //]]>

 
 
 
 
