//
// © 2009
// Scripting done by Sjoerd Gal @ Trendesign (trendesign.nl)
//


/* Show Information & Route
/* -------------------------------------------------------------*/
function showInfo(){
	if(  $(".extra-container").is(':hidden') ){
		
		if ( $("#thebiggerpicture").is(':visible') ){
			$("#thebiggerpicture").fadeOut(250, function(){
				
				$(".extra-container .tabnav li:eq(0) a").addClass("active");
				$(".extra-container .tabnav li:eq(1) a").removeClass("active");
				$(".overview, #boxroute, #thebiggermap").css("display", "none");
				$("#boxinfo").css("display", "block");
				$(".extra-container").fadeIn(250);
			});
		} else {
			$(".overview").fadeOut(250, function(){
				$(".extra-container .tabnav li:eq(0) a").addClass("active");
				$(".extra-container .tabnav li:eq(1) a").removeClass("active");
				$("#thebiggerpicture, #boxroute, #thebiggermap").css("display", "none");
				$("#boxinfo").css("display", "block");
				$(".extra-container").fadeIn(250);
			});
		}
	}
};


/* Agenda actions
/* -------------------------------------------------------------*/
function removeBiggerPicture(){
	$(".overview").css("opacity", "1.0");
	
	$("#thebiggerpicture").fadeOut(250, function(){
		$(".overview").fadeIn(250, function(){
			//$("#thebiggerpicture img.biggy").remove();				
			$("#thebiggerpicture img.biggy").css('display','none');
		})
	});
};

/* Get OrderLink */
function getOrderLink( sLink ){
	window.open( sLink );
  return false;
};


/* Info actions
/* -------------------------------------------------------------*/
function closeInfo(){
	$('.extra-container').fadeOut(250, function(){
		$("#thebiggerpicture, #boxinfo, #boxroute").css("display", "none");
		$('.overview').css("opacity", "1.0").fadeIn(250);	
	});
};
	

/* When Document is ready ..
/* -------------------------------------------------------------*/

$(document).ready(function(){
  
  $(".footer a.info").click(function(){ showInfo(); });
  $(".footer a.pics").click(function(){	window.open("http://www.flickr.com/photos/dehoevegroesbeek/"); })


	$(".overview .item:nth-child(4n)").css('margin-right','0');

  
  /* Thumbnail actions
	/* -------------------------------------------------------------*/
	$(".overview img").click(function(){

		// Temp Zomerstop 'return false'
		// Geen actie op images / thumbs
		// ---------------------------------
		// return false;

		var clicker = true;

		var sImg = '';
				sImg = $(this).attr("src").replace("/tn","/big");
		
		var sParent = $(this).parent().children('em');

		// SHOW loading animation		
		$("#loading").css('display','block');
		
		// check for order-link
		$("#orderlink").css('display','none');

		//	Set Visible Block
		if ( sParent.length > 0){
			$("#orderlink").css('display','block');
		}
		
		//	Set Orderlink first time
		if ( sParent.length > 0){
			
			$('#orderlink').unbind('click');
			$("#orderlink").css('display','block').click(function(){ 
				getOrderLink( sParent.text() );  
			});
		}

		$("#thebiggerpicture img.biggy").css('display','none');
		$(".overview").css("opacity", "0.5");

/*
		$("#thebiggerpicture img.biggy").attr('src', sImg );
*/


$('#thebiggerpicture img.biggy').attr('src', sImg).load( function(){

			// HIDE loading animation		
			$("#loading").css('display','none');
			$("#thebiggerpicture img.biggy").css('display','block');	
			$(".overview").fadeOut(250, function(){ $("#thebiggerpicture").fadeIn(250) });

/*         $('.profile').append( $(this) ); */
        // Your other custom code
    });


		// New Image Load - Succes function
/*
		$("#thebiggerpicture img.biggy").load(function(){
					
			$("#thebiggerpicture img.biggy").css('display','block');	
			$(".overview").fadeOut(250, function(){ $("#thebiggerpicture").fadeIn(250) });
			
		}).each( function(){
			if ( this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) ) $(this).trigger("load");
		});
*/
		
		clicker = false;
		
	});


	/* Big Picture actions
	/* -------------------------------------------------------------*/
	$("#thebiggerpicture").click(function(){
		removeBiggerPicture();
		$("#orderlink").css('display','none');
	});

	/* Close Extra Information
	/* -------------------------------------------------------------*/	
	$(".extra-container .bclose").click(function(){
		closeInfo()
	});

	
	/* Extra Information Tabs & Boxes
	/* -------------------------------------------------------------*/	
	$(".tabnav li a").click(function(){

		var sBoxName = $(this).parent().attr('class');
		var sClass = $(this).attr('class');
		var sBox = $(this).attr('class').replace("active","");
		
		if( sClass != "active" ){
			$(this).addClass("active");
			$(this).parent().siblings('li[class!="' + sBoxName + '"]').children('a').removeClass("active");
			
			$('.extra-content div[id!="box' + sBoxName + '"].extra').css("display", "none");
			$('.extra-content div[id="box' + sBoxName + '"]').css("display", "block");
			$('#thebiggermap').css("display", "none");
		};

	});


	/* Extra Information - Route Descriptions
	/* -------------------------------------------------------------*/	
	$("#boxroute .routelisting span a").click(function(){
		$(this).parent().parent().siblings('div[class="routelisting"]').children("table").hide();
		$(this).parent().parent().children("table").toggle();
	});


	/* Extra Information - Route Map
	/* -------------------------------------------------------------*/	
	$("#boxroute .last a").click(function(){
		$("#boxroute").toggle();
		$("#thebiggermap").toggle();
	});
	
	$("#thebiggermap img").click(function(){ 
		$(this).parent().toggle();
		$("#boxroute").toggle();
	});


});
