function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
		
		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(); }); 
	$(window).resize(function() { makeImagesBigger(); }); 
	
	function makeImagesBigger() {  // set of elements with class 'panel' 
		$.each($(".fullscreen"), function() { 
			//	alert("hi");
		     //$(this).hide(); 
			var imageHeight = getWindowHeight() - 170;
			if (imageHeight > 560) {
				imageHeight = 560;
			} else if (imageHeight < 420) {
				imageHeight = 420;
			}
			//alert($(this).attr('height'));
			$(this).attr('height', imageHeight);
		});
	}
	
	function posContentNav() {
		makeImagesBigger()
		$.each(panelList, function() { 
		     if ($(this).height() > panelHeight) {
				panelHeight = $(this).height();
			}
		});
		
		if (panelHeight <10) {
			panelHeight = 420;
		}
		
		panelHeight = panelHeight +28;
		//alert(panelHeight);
		$("#contentNav").animate({'top' : panelHeight}, 300);

		panelHeight = panelHeight -7;
		$(".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
	});
	
	
});
