/*
 * Common code to run site animations
 * Date: 2009-04-20
 */
function load_portfolio_image(image, page) {
	$('.loading').css('display','block');
	//$("#image-wrapper").html("");
	$("#image-wrapper").children('img').remove();
	var image_height = 400;
	
	switch(page) {
	case 'brand-ippr':
	case 'exhibition-uk-skills':
	case 'print-labour-party':
	case 'print-weston':
	image_height = 600;
	case 'brand-lucius': image_height = 510;
	}
	
	var img = new Image();
	$(img).load(function () {
//		$("#image-wrapper").removeClass('loading').html(this).hide();
		$("#image-wrapper").hide();
		$('.loading').css('display','none');
		$(this).insertBefore('.slides');
		$("#header-image").animate({height: (image_height)+'px'},500,'linear',function(){
			$("#image-wrapper").css({height:image_height+'px'});
			$("#image-wrapper").fadeIn("slow");
		});
	}).attr('src', image);
	
	
}
jQuery(document).ready(function() {
	$('.slideshow, #icon-brand-itf').slideshow({ timeout: 3000, speed: 500 });
	$("a.external").attr("target","_blank");

	$(".main-menu").click ( function() {
		$(this).toggleClass("active-link");
		$(this).next("ul").slideToggle("medium");
	});
	
	previous_page = "home";
	

	$(".sub-menu li a").click ( function() {
		var page = $(this).attr("id");
		
		var image = $(this).attr("href");
		//image = image.substring(image.lastIndexOf("/") + 1);

		/// remove extra stuff from page
		$("li").removeClass("active");												 
		$(this).parent("li").addClass("active");
		$("#portfolio").removeClass("home-style");
		$("#content").remove();
		
		// change protfolio icon image
		$("#portfolio-note").hide();
		$("#icon-" + previous_page).fadeOut("slow");
		$("#icon-" + page).fadeIn("slow");
		$("#portfolio-description").html($("#desc-" + page).html()).fadeIn("slow");
		previous_page = page;
				
		if(page=="print-itf" || page== "print-ww" || page== "brand-itf" || page == "web-colorset"){
			$('.loading').css('display','block');
			$("#image-wrapper").children('img').remove();
			$("#image-wrapper .active").fadeOut(1000).removeClass('active');
			$("#header-image").animate({
				height:'510px'
			},0, function(){
				$('#image-wrapper').animate({
					height:'510px'
				},500,function(){
					$('.'+page).fadeIn(2000).addClass('active');	
				});
			});
			$('.loading').css('display','none');
		}else{
			//load main image
			load_portfolio_image(image, page);
		}

		return false;
	});
	
});
