$(document).ready(function(){

//png fixing for IE
	$("h2, #footer").supersleight({shim: "../img/x.gif"});

//if browser is IE6 then hide all Javascript	
if(window.XMLHttpRequest == undefined && ActiveXObject != undefined){
}else{
	
//initial section load
	var queryhash = window.location.hash;
	switch (queryhash) {
		case "#avt":
			show("avt", "AV Tech", true);
			break;
		case "#cdl":
			show("cdl", "Content Design &amp; Layout", true);
			break;
		case "#cam":
			show("cam", "Camera", true);
			break;
		default:
			show("hel", "", true);
			break;
	}

//secondary nav links	
	$("#em a").hover(
		function(){
			label(true, "-153px", "-123px", "-113px", "em");
	},
		function(){
			label(false, "-153px", "-123px", "-113px", "em");
	});
	
	$("#cv a").hover(
		function(){
			label(true, "-193px", "-163px", "-153px", "cv");
	},
		function(){
			label(false, "-193px", "-163px", "-153px", "cv");
	});
	
//primary nav links
	$("#nav .avt a").click(function(){
		show("avt", "AV Tech", false);
	});
	
	$("#nav .cdl a").click(function(){
		show("cdl", "Content Design & Layout", false);
	});
	
	$("#nav .cam a").click(function(){
		show("cam", "Camera", false);
	});

}
});

function label(show, start, stop, end, id){
	//if IE7&8 dont fade in and out to prevent horrible "outline"
	if(jQuery.support.objectAll == false){
	
		if(show == true){
			$("#"+id+" a span").show();
			$("#"+id+" a span").animate({
				left: stop
			}, 300 );
		}else{
			$("#"+id+" a span").animate({ 
				left: end
			}, 300 );
			setTimeout("$('#"+id+" a span').hide();", 300);
			$("#"+id+" a span").animate({ 
				left: start
			}, 300 );
		}
		
	}else{
	
		if(show == true){
			$("#"+id+" a span").show();
			$("#"+id+" a span").animate({
				left: stop,
				opacity: 1
			}, 300 );
		}else{
			$("#"+id+" a span").animate({ 
				left: end,
				opacity: 0
			}, 300 );
			setTimeout("$('#"+id+" a span').hide();", 300);
			$("#"+id+" a span").animate({ 
				left: start
			}, 300 );
		}
	}
}

function show(id, section, initial){
	if($("#wrapper").hasClass(id)){
		
		//do nothing because link is already loaded
	
	}else{
	
		if(id == "hel"){
			document.title = "Dan Crooks";
		}else{
			document.title = "Dan Crooks - "+section;
			$("#nav li a").removeClass();
			$("#nav ."+id+" a").addClass("current");
		}
		
		if(initial == false){
			$(".node").slideUp(600);
			$(".node *").fadeOut(600);
			$(".img").fadeOut(600);
			setTimeout("$('.img').remove();", 600);
			setTimeout("$('.node').hide();", 600);
		}else{
			$(".node").hide();
		}

		setTimeout(function(){
			$("#wrapper").removeClass();
			$("#wrapper").addClass(id);
 			$("#"+id).css("background", "transparent");
 			$("#"+id+" *").hide();
 			$("#"+id).slideDown(600);
 			$("#"+id+" *").fadeIn(600);
 			$("#"+id).before('<div class="img"></div>');
 			$(".img").hide();
 			setTimeout("$('.img').fadeIn(400);", 600);
		}, 800);
		
		setTimeout(checkHeight, 1900);
	}
}

function checkHeight(){
	var doc = $(document).height();
	var viewport = $(window).height();
	
	//reset doc height for IE7&8 with -4 because document height is 4 more than it should be in IE8 :s
	if(jQuery.support.objectAll == false){ var doc = $(document).height() - 4; }
	
	//document.title = doc+" / "+viewport;
	
	if(viewport < 588){
		$("body").css("min-height", "588px").css("height", "auto");
	}else{
		if(viewport > 588){
			$("body").css("min-height", "100%").css("height", "100%");
		}
	}
	
	if(viewport < doc){
		$("body").css("min-height", "588px").css("height", "auto");
	}
}
