$(document).ready(function() {
	$("#header").hide();
	$.preload('img');

	//sIFR.debug.ratios({ src: '/includes/fonts/tradegothic_lh_extended.swf', selector: 'p.tradegothic, p.photo-title, p.tradegothic-small' });

	sIFR.replace(tradegothic_lh_extended, {
		selector: 'p.tradegothic, p.photo-title, p.photo-surtitle, p.tradegothic-small',
		css: [
			'.sIFR-root { text-align: justify; background-color:#232323; color:#c3c3c3; }'
			,'a { text-decoration: none; padding-right:10px; color:#c3c3c3;}'
			,'a:link { color: #c3c3c3; }'
			,'a:hover { color: #c3c3c3; }'
		],
		ratios: [7,1.47,10,1.43,18,1.36,22,1.34,26,1.32,37,1.31,42,1.3,48,1.29,51,1.3,64,1.29,67,1.28,68,1.29,119,1.28,120,1.27,1.28]
	});

	sIFR.replace(tradegothic_lh_extended_left, {
		selector: 'p.tradegothic_left_small',
		css: [
			'.sIFR-root { text-align: left; background-color:#232323; color:#c3c3c3; }'
			,'a { text-decoration: none; padding-right:10px; color:#c3c3c3;}'
			,'a:link { color: #c3c3c3; }'
			,'a:hover { color: #c3c3c3; }'
		],
		ratios: [7,1.47,10,1.43,18,1.36,22,1.34,26,1.32,37,1.31,42,1.3,48,1.29,51,1.3,64,1.29,67,1.28,68,1.29,119,1.28,120,1.27,1.28]
	});

	sIFR.replace(tradegothic_lh_extended_left, {
		selector: 'p.tradegothic_left',
		css: [
			'.sIFR-root { text-align: left; background-color:#232323; color:#c3c3c3; }'
			,'a { text-decoration: none; padding-right:10px; color:#c3c3c3;}'
			,'a:link { color: #c3c3c3; }'
			,'a:hover { color: #c3c3c3; }'
		],
		ratios: [7,1.47,10,1.43,18,1.36,22,1.34,26,1.32,37,1.31,42,1.3,48,1.29,51,1.3,64,1.29,67,1.28,68,1.29,119,1.28,120,1.27,1.28]
	});

	var windowHeight = $(window).height();
	var wrapperHeight = $("#wrapper").height();

	var wrapperTop;

	if (windowHeight > wrapperHeight && (windowHeight - wrapperHeight) > 40) {
		wrapperTop = (-20 + (windowHeight - wrapperHeight)/2);
		$("#wrapper").css("margin-top", wrapperTop + "px");
	} else {
		wrapperTop = "30"
		$("#wrapper").css("margin-top", wrapperTop + "px");
	}

	var imgBoxHeight = 515;
	var contentHeight = $("#content").height();
	var contentPadding;

	if ($("img.photography").length == 0) {
		contentPadding = ($("#wrapper").height() - contentHeight)/2;
	} else {
		contentPadding = ((imgBoxHeight - contentHeight + 40)/2) + (640-515);
	}


	if ($("#content").hasClass("commercial-section")) {
		contentPadding = contentPadding - 12;
	} else if ($("#content").hasClass("exhibitionMain")) {
		contentPadding = 120;	
	}
	$("#content").css("padding-top", contentPadding + "px");

	// Properly Align Photo Title
	var photoId = $("#photo");
	var imgWidth = $($(photoId).find("img")[0]).width();
	$(photoId).css("padding-left", (($("#wrapper").width() - imgWidth)/2)-20 + "px");
	$("p.photo-title").css("width", imgWidth);

	$("#icon-minus.doHover").hover(
		function() {$(this).attr("src", "/images/icon_minus_light.gif");}, 
		function() {$(this).attr("src", "/images/icon_minus_dark.gif");}
	);

	$("#icon-plus.doHover").hover(
		function() {$(this).attr("src", "/images/icon_plus_light.gif");}, 
		function() {$(this).attr("src", "/images/icon_plus_dark.gif");}
	);

	$(".hover").each(function() {
		var theImage = $($(this).find("img"))[0];
		var imgHeight = $(theImage).height();
		var photography = $($("img.photography"))[0];
		var photographyHeight = $(photography).height() + 40; // + Padding + Title
		var wrapperHeight = $("#wrapper").height();
		$(this).css("height", photographyHeight + "px");
		$(this).css("margin-bottom", "-" + photographyHeight + "px");
		$(theImage).css("margin-top", (photographyHeight - imgHeight)/2 + "px");
		$("#loading").css("top",(4+contentPadding + (photographyHeight - imgHeight)/2) + "px");
	});
	
	$(".hover").click(function() {
		var theLink = $(this).find("a");
		window.location.href = $(theLink).attr("href");
	});

	$(".hover").hover(
		function() {
			$(this).css("cursor", "pointer");
			$(this).find("#icon-minus").attr("src", "/images/icon_minus_light.gif");
			$(this).find("#icon-plus").attr("src", "/images/icon_plus_light.gif");
		},
		function() {
			$(this).css("cursor", "");
			$(this).find("#icon-minus").attr("src", "/images/icon_minus_dark.gif");
			$(this).find("#icon-plus").attr("src", "/images/icon_plus_dark.gif");
		}
	);

	$("#header li img").hover(
		function() {
			$(this).removeClass("nav-faded").addClass("nav-opaque")
			$("#header li img").not(this).not(".nofade").addClass("nav-faded").removeClass("nav-opaque");
		},
		function() {}
	);

	if ($("img.photography").length > 0) {
		$("#loading").animate({width: "100%"}, 4000);
	}

	$(window).load(function() {
		if ($("img.photography").length > 0) {
			$("#loading").stop();
			$("#loading").hide();
		}
		$("#content").css("visibility", "visible");
	});
});

function enableQTPopupTitle() {
	sIFR.replace(tradegothic_lh_extended, {
  	selector: 'p.movie-title',
		css: [
			'.sIFR-root { text-align: justify; background-color:#232323; color:#c3c3c3; }'
			,'a { text-decoration: none; padding-right:10px; color:#c3c3c3;}'
			,'a:link { color: #c3c3c3; }'
			,'a:hover { color: #c3c3c3; }'
		],
		ratios: [7,1.47,10,1.43,18,1.36,22,1.34,26,1.32,37,1.31,42,1.3,48,1.29,51,1.3,64,1.29,67,1.28,68,1.29,119,1.28,120,1.27,1.28]
	});
}

function enableNav(doFade) {
	if (doFade) {
		$("#header").fadeIn("slow");
	} else {
		$("#header li").find("img").not(".nofade").addClass("nav-faded").removeClass("nav-opaque");
		$("#header li.currentNav:last").find("img").not(".nofade").removeClass("nav-faded").addClass("nav-opaque");
		$("#header").show();
	}

	$("ul.navigation").superfish({
		pathClass		: "currentNav",
		pathLevels		: 6,
		delay			: 800,
		animation		: {opacity:'show'},
		speed			: "normal",
		autoArrows		: false,
		dropShadows		: false,
		disableHI		: false
	});
}
