jQuery.preloadImages = function()
{
	preload = arguments[0];
	
	for(var i = 0; i<arguments[0].length; i++)
	{
	$(document.createElement('img')).bind('load', function(){
         if(preload[0]) this.src = preload.shift();
        }).trigger('load');
	}
}

$(document).ready(function(){	
	
	var projectImages = new Array();

	$("#projectImageMenu img").each(function() {
		projectImages[projectImages.length] = $(this).attr("longdesc");
	});
	
	$.preloadImages(projectImages);
	
	$("#projectImg p").text($("#projectImageMenu img.current").attr("alt"));
	
	$("#projectImageMenu img").hover(
		function() {
			$("#projectImg img#mainImg").attr("src", $(this).attr("longdesc"));
			$("#projectImageMenu img").each(function() {
				$(this).removeClass("current");
			});
			$(this).addClass("current");
			$("#projectImg p").text($(this).attr("alt"));
		},
		function () { }
	);
	
	// new project nav popups
	$("#projectNavNew li").hover(
		function() {
			$("p", this).show();
		},
		function() {
			$("p", this).hide();
		}
	);
	
	// applying the settings
	$("#theMenu").Accordion({
		active: '.selected',
		header: '.head',
		alwaysOpen: false,
		animated: true,
		showSpeed: 400,
		hideSpeed: 800
	});
	
	$("#theMenu a.head").click(function() {
		if($(this).attr("id") == "work") {
			$("#projectNavNew ul").slideToggle(400);
		} else {
			$("#projectNavNew ul").slideUp(800);
		}
	});
	
	
});	