jQuery(function($) {
  var laadContent;

  $('#overzicht a').click(function(e) {
	 e.preventDefault();
	// $.ga.trackEvent('Navigatie', '[Overzicht Pagina klik]', $(this).attr('title'), 0);
	 $('#overzicht').fadeOut("fast", loadNextItem);
	 laadContent = $(this).attr('href'); 
	 $('.thumbs').fadeIn();
  });
  
  function loadNextItem() { 
  	$('.loader').fadeIn();
    $('#content .new_item').load(laadContent,'',hideLoader) 
   }
	
  function hideLoader(){
	   $('.loader').fadeOut("fast", showNewContent);
  }
  
  function showNewContent(){
    $('#port_item').css('left','1500');
	$('#port_item').animate({left:'0'},500, 'swing', showTitel);
  }
  
  function showTitel(){
	 showTekst();
	$('.titel').css('display','inline-block');
	$('.titel').animate({left:'-30px'},500, 'swing', showControls);
  }
  
   function showControls(){
	$('.controls').css('left','35px');
	$('.controls').css('display','inline-block');
	$('.controls').animate({left:'+='+$('.titel').width()},500, 'swing');
  }
  
  function showTekst(){
	var topPos = 500 - $('.info_tekst').height();
	$('.info_tekst').css('display','block');
	$('.info_tekst').animate({top:topPos},1000, 'swing');
  }
  
  jQuery.fn.exists = function(){return this.length>0;}

  /* Thumbnails */
   $('.thumbs a').click(function(e) {
	 e.preventDefault();
	 laadContent = $(this).attr('href'); 
	// $.ga.trackEvent('Navigatie', '[Thumbnail Balk klik]', $(this).attr('title'), 0);
	 $('.info_tekst').animate({top:600},1000, 'swing');
	// $('#port_item').fadeOut("fast", loadNextItem);
	
	if ($('.controls').exists()) {
    	$('.controls').animate({left:'-130px'},500, 'swing', hideTitel);
	}else{
		$('#port_item').animate({left:'0'},500, 'swing', hideTitel);
	}
	
	// laadContent = $(this).attr('href'); 
	
	$('html, body').animate({scrollTop:'0'}, 500);
  });
  
  function hideTitel(){
	  $('.titel').animate({left:'-1000px'},500, 'swing', hideItem);
  }
  
  function hideItem(){
	  $('#port_item').animate({left:'-1500'},500, 'swing', loadNextItem);
  }
  
$('.titel_link, #home').click(function(e) {
	 e.preventDefault();
	 //$.ga.trackEvent('Navigatie', '[Home klik]', $(this).attr('title'), 0);
	 laadContent = $(this).attr('href');
	 $('.thumbs').fadeOut();
	 $('#port_item').animate({left:'-1500'},500, 'swing', fadeOverZichtIn);
  });
  
  function fadeOverZichtIn(){
	$('#overzicht').fadeIn("fast");  
  }

});
