/*
 * Common code to run site animations
 * Date: 2009-04-20
 */
function load_portfolio_image(image, page) {
	$("#image-wrapper").addClass('loading');
	$("#image-wrapper").html("");
	var image_height = 400;
	
	switch(page) {
	case 'brand-ippr':
	case 'exhibition-uk-skills':
	case 'print-labour-party':
	case 'print-weston':
	image_height = 600;
	}
	
	var img = new Image();
	$(img).load(function () {
		$("#image-wrapper").removeClass('loading').html(this).hide();
		$("#header-image").animate({height: (image_height)+'px'},500,'linear',function(){
			$("#image-wrapper").css({height:image_height+'px'});
			$("#image-wrapper").fadeIn("slow", function () {
				var portfolio_note_height = $("#portfolio-note").height();										 
				$("#portfolio-note").css({top:(image_height - portfolio_note_height) + 'px'}).show("slow");
			});
		});
		// change portflio text on main image and in portfolio description
		$("#portfolio-note").html($("#note-" + page).html());
	}).attr('src', image);
	
	
}
jQuery(document).ready(function() {

	$("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;
		
		//load main image
		load_portfolio_image(image, page);

		return false;
	});
	
});