$(document).ready(function(){

	var initialID;
	var currentID;
	var lastID = null;

	if($("#nav li#initial").length) {
		initialID = $("#nav li#initial").attr("title");
		showSection(initialID);
	}

	$("#nav li").hover(function(){
		$("#nav li.on").removeClass("on");
		$(this).addClass("on");
		currentID = $(this).attr("title");

		if($("#"+currentID).length) {
			showSection(currentID)			
		}
	},function(){});

	function showSection(currentID) {
		if(lastID != currentID) {
			if(lastID != null) {
				$("#"+lastID).fadeOut("fast");
				$("#"+lastID).css("z-index","0");
			}
			
			$("#section").css("background","url(images/ajax-loader-white.gif) center center no-repeat");
			
			bkimg = $("#"+currentID).css("background-image").substr(4);
			bkimg2 = bkimg.substr(0,(bkimg.length-1));
			bkimg_nice = bkimg2.replace(/\"/g,'')

			var im = new Image();
			im.src = bkimg_nice;
			im.onload = function() {

				$("#"+currentID).css("z-index","10000");
				$("#"+currentID).fadeIn("slow");
				lastID = currentID;
				
				im.onload=function(){};
			}
			im.src = bkimg_nice;

		}
	}

});
