$(document).ready(function() {
	// --- Product details
	// Image Gallery
	if ($("#image-gallery > ul > li").length) {
		$("#image-gallery > ul > li").each(function() {
			$(this).find("a").attr("href","javascript:;");
			$(this).click(function() {
				if (slideShow != undefined) slideShow.goTo($(this).find("a").attr("rel"));
			});
		});
	}

	// Details Tabs
	if ($(".product_information > ul.tabs > li").length) {
		$(".product_information > ul.tabs > li").each(function() {
			$(this).find("a").attr("href","javascript:;");
			$(this)
				.click(function() {
					$(".product_information > div").hide();
					$(".product_information > div[@rel=tab_" + $(this).find("a").attr("rel") + "]").show();
					$(this).parent().find("li").removeClass("selected")
					$(this).addClass("selected");
					
					// Set all other tabs to off
					$(".product_information > ul.tabs img").each(function() {
						var imgSrc = $(this).attr("src");
						var imgSrcName = imgSrc.substring(0, imgSrc.lastIndexOf("_"));
						var imgExt = imgSrc.substring(imgSrc.lastIndexOf(".")+1, imgSrc.length);
						$(this).attr("src", imgSrcName + "_off." + imgExt);
					});

					// Set current tab to on
					var img = $(this).find("img:first");
					var imgSrc = img.attr("src");
					var imgSrcName = imgSrc.substring(0, imgSrc.lastIndexOf("_"));
					var imgExt = imgSrc.substring(imgSrc.lastIndexOf(".")+1, imgSrc.length);
					img.attr("src", imgSrcName + "_on." + imgExt);					
				});
		});
		$(".product_information > ul.tabs > li:first").click();
	}
});

var oldOnLoad = window.onload;
window.onload = function() {
	if (oldOnLoad != undefined) oldOnLoad();
	
	if ($("div.product-image img").length) {
		var maxHeight = 0;
		$("div.product-image img").each(function() {
			if ($(this).height() > maxHeight) maxHeight = $(this).height();
		});
		if (maxHeight > 0) $("div.product-image").css("height", maxHeight);
	}
}