function accordian(div) {
	if (div == "#Clients") {
		dropLogo();
	} else {
		raiseLogo();
	}
	
	$("#Recentwork").slideUp("slow");
	$("#Identity").slideUp("slow");
	$("#Print").slideUp("slow");
	$("#Interactive").slideUp("slow");
	$("#Archive").slideUp("slow");
	$("#Clients").slideUp("slow");
	$(div).slideDown("slow");

}

function dropLogo() {
	var dropDepth = 200;
	$("#Clients").slideDown(0);
	dropDepth += $("#Clients").height();
	$("#Clients").slideUp(0);
	$(".logo").animate({'top': dropDepth}, "slow");
}

function raiseLogo() {
	var dropDepth = 450;
	$(".logo").animate({'top': dropDepth}, "slow");
}

$(document).ready(function(){

	//Close all sub navs
	$("#Recentwork").slideUp(0);
	$("#Identity").slideUp(0);
	$("#Print").slideUp(0);
	$("#Interactive").slideUp(0);
	$("#Archive").slideUp(0);
	$("#Clients").slideUp(0);

	//Open chosen category
	if (chosenCatergory != "#") {
		$(chosenCatergory).slideDown(0);
	}	
	
	if (chosenCatergory == "#Clients") {
		var dropDepth = 200;
		dropDepth += $("#Clients").height();
		$(".logo").animate({'top': dropDepth}, 0);
	}
	
	if (showBG) {
		$('img.bgmaximage').maxImage({
			isBackground: true,
			verticalAlign: 'top',
			zIndex: -10
		});
	}

	//Assign dropdowns
	var sectionList = $("#nav li a:not(.sublink)");
	$.each(sectionList, function() {
		//alert($(this)); 
		$(this).click( function() {
			var div = "#";
			div += $(this).attr("class");
			accordian(div);
			return false;
		})
	});
	
	//Assign client actions
	$(".Clients").click( function() {
		var div = "#Clients";
		accordian(div);
		return false;
	});
	
	
	//Navigate between panels of content	
	var panelList = $(".panel");	
	var panelTextList = $(".panelText");
		
	$(window).load(function() { posContentNav(); }); 
	
	
	function posContentNav() {
		//alert("posContentNav");
		//work out the correct depth of the content nav
		$.each(panelList, function() { 
			//if this panel is the biggest so far:
		     if ($(this).height() > panelHeight) {
				panelHeight = $(this).height();
			}
			//alert(panelHeight);
			//$("#contentNav").css({'top' : panelHeight});
		});

		//alert(panelHeight);
		/*$.each(panelList, function() { 
			$("this").css({'min-height' : panelHeight});
		});
		*/
		
		if (panelHeight <10) {
			panelHeight = 420;
		}
		
		panelHeight = panelHeight +28;
		$("#contentNav").animate({'top' : panelHeight}, 300);

		panelHeight = panelHeight +13;
		$(".panelText").animate({'top' : panelHeight}, 300);
	}
	

	
	function slidePanels(panelName, link) {  // set of elements with class 'panel' 
		var panelTextName = panelName + "Text";
		$(openPanel).stop().hide("slide", {direction: "left"}, 300, function() {
			$(panelName).stop().show("slide", {direction: "right"}, 300);
		});
		$(openTextPanel).stop().hide("slide", {direction: "left"}, 300, function() {
			$(panelTextName).stop().show("slide", {direction: "right"}, 300);
		});
		openPanel = panelName;
		openTextPanel = panelTextName;
		removeActiveClass();
		$(link).addClass("active");
		
	}
	
	function removeActiveClass() {
		var linkList = $("#contentNav a");  // find all content links
		$.each(linkList, function() { 
		     $(this).removeClass("active");
		});
	}
	
	function hidePanels() {  // set of elements with class 'panel' 
		$.each(panelList, function() { 
		     $(this).hide(); 
		});
		$.each(panelTextList, function() { 
		     $(this).hide(); 
		});
	}
	
	hidePanels();
	var openPanel = panelList[0];
	var openTextPanel = panelTextList[0];
	$(openPanel).show();
	$(openTextPanel).show();
	
	var linkList = $("#contentNav a");  // find all content links
	$.each(linkList, function() { 
	     $(this).click(function () {
			//Associate the link to a panel via the class name
			var panelName = "#";
			panelName += $(this).attr("class");
			slidePanels(panelName, $(this)); return false;
		} );
	});
	
	$(linkList[0]).addClass("active");
	
	//make all images links?
	var linkImageList = $(".panel img");  // find all content links
	$.each(linkImageList, function() { 
		
		//alert("Hi");
	     $(this).click(function () {
			//Associate the link to a panel via the class name
			
			panelName = "#panel_"
			panelName += $(this).attr("class");
			
			//to make content nav appear active
			linkName = ".panel_"
			linkName += $(this).attr("class");
			
			//alert(panelName);
			slidePanels(panelName, linkName); return false;
			
		});
		
	});
	
	$('img.bgmaximage').maxImage({
	 isBackground: true,
	 verticalAlign: 'top',
	 zIndex: -10
	});
	
	
});