/*
 * Fix IE background image flicker (via http://www.mister-pixel.com/)
 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

/*
 * methods to run on DOM ready
 */
$(document).ready(function() {
	var mainNavFunctionality = function()
	{
		// header nav drop-down functionality (IE doesn't support li:hover)
		$("div#header > ul > li").hover(function() {
			$(this).addClass("over");
		}, function() {
			$(this).removeClass("over");
		});
	}();
	
	var artworkFunctionality = function()
	{
		var thumbnailSeed = "-sm";
		
		// remove right margin and reset width on nav list items and list
		// (this is done in JS instead of adding a custom class to ever item)
		$("div#nav li:odd").css("margin-right", 0);
		$("div#nav ul").css("width", 109);
		
		// hide all artwork info (h2)
		if ($("body.artwork").length != 0)
		{
			// use this syntax for PC IE 5.5
			$("body.artwork > div#container > div#content > div#nav > ul > li > h2").hide();
		}
		
		// capture default "main focus" area content
		var focusAreaDefaultContent = $("div#focus").html();
		
		var setArtworkImageInfo = function(imageObj)
		{
			// remove "on" state of any previous selected thumbnail
			$("a[@class=on]").removeClass("on");
			// empty "main focus" area
			$("div#focus").empty();
			// add image to "main focus" area
			$("div#focus").append("<a href=\"#\"><img alt=\"" + $(imageObj).attr("alt") + "\" src=\"" + $(imageObj).attr("src").split(thumbnailSeed)[0] + ".jpg\" width=\"400\" height=\"400\" /></a>");
			// get image info
			var imageInfo = $(imageObj).parent().siblings("h2").html();
			// add image info to "main focus" area
			$("div#focus").append("<h2>" + imageInfo + "</h2>");
			// highlight "on" thumbnail
			$(imageObj).parent().addClass("on");
			
			// add "main image" click events
			$("div#focus img").click(function() {
				// remove "on" state of any previous selected thumbnail
				$("a[@class=on]").removeClass("on");
				// empty "main focus" area
				$("div#focus").empty();
				// set "main focus" area to default content
				$("div#focus").html(focusAreaDefaultContent);
				
				return false;
			});
		};
		
		// add artwork nav click events
		$("div#nav a").click(function() {
			setArtworkImageInfo($(this).children("img"));
		});
		
		// check url for hash value
		if (location.hash)
		{
		    setArtworkImageInfo($("a[@href=" + location.hash + "]").children("img"));
		}
	}();
	
	var exitLinkFunctionality = function()
	{
		$("a.exit").click(function() {
			window.open($(this).attr("href"));
			
			return false;
		});
	}();
	
	// detach all handlers
	$(window).unload(function() {
	    $("*").unbind();
	});
});