$(document).ready(function() {
	$(".mega").each(function() {
		var columns = $(this).children("ul").length;
		var mega_width = parseInt(columns) * 128;
		if($(this).children("ul#hot-tub-services").length == 1) mega_width = parseInt(mega_width) + 50;
		if(mega_width > $("#navbar").width()) {
			var offset = parseInt(mega_width) - parseInt($("#navbar").width()) + 38;
			$(this).css("left", "-" + offset + "px");
		}
		$(this).css("width", mega_width);
		$(this).children(".left").css("height", $(this).height());	
		$(this).children(".right").css("height", $(this).height());
	});

	$(".single-dropdown").each(function() {
		$(this).children(".right").css("height", $(this).height() + 29);
	});
	$(".mega ul").css("min-height", $(".mega").height() - 50);
	jQuery.each(jQuery.browser, function(i, val) {
		if(i != "msie" && jQuery.browser.version.substr(0,3) != "6.0") {
			$(".mega ul li, .single-dropdown li:not(.right)").hover(
				function() {
					$(this).css("background", "url('images/mega-list-item-hover.png') no-repeat");
				},
				function() {
					$(this).css("background", "none");
				}
			);
		}
	});
	//$(".hot-tub-content").children(".specs").hide();
	$("#specs-link").click(function() {
		if($(".specs table").is(":hidden")) {
			$(this).children("span").html("hide");
			$("#hot-tub-specs").css("background-image", "url('images/up_hot_tub_specs.gif')");
			$(".specs table").slideDown();
			$(".bl").hide();
			$(".br").hide();
		}
		else {
			$(this).children("span").html("expand");
			$("#hot-tub-specs").css("background-image", "url('images/down_hot_tub_specs.gif')");
			$(".specs table").slideUp();
			$(".bl").show();
			$(".br").show();
		}
	});
    $("#navbar li.top-level").hoverIntent(
        function() { 
			var navbar_positions = new Object;
			navbar_positions['hot-tubs'] = '0';
			navbar_positions['saunas'] = '-102';
			navbar_positions['water-care'] = '-194';
			navbar_positions['health-benefits'] = '-315';
			navbar_positions['repair'] = '-473';
			navbar_positions['services'] = '-558';
			var current_id = $(this).attr("id");
			
			$("ul", this).fadeIn("fast");
			$("#navbar #" + current_id + " a.top-level").css("background-position", navbar_positions[current_id] + "px -43px");
		}, 
        function() { 
			var navbar_positions = new Object;
			navbar_positions['hot-tubs'] = '0';
			navbar_positions['saunas'] = '-102';
			navbar_positions['water-care'] = '-194';
			navbar_positions['health-benefits'] = '-315';
			navbar_positions['repair'] = '-473';
			navbar_positions['services'] = '-558';
			var current_id = $(this).attr("id");
			$("ul", this).fadeOut("fast");
			$("#navbar #" + current_id + " a.top-level").css("background-position", navbar_positions[current_id] + "px 0px");
		}
    );
	$("#e-store li").hover(
		function() {
			$(this).addClass("store-li-hover");
			$(this).children("a").addClass("store-li-a");
		},
		function() {
			$(this).removeClass("store-li-hover");
			$(this).children("a").removeClass("store-li-a");
		}
	);
	$(".categories li:not(.activeparent)").hoverIntent(
		function() { 
			$(this).addClass("add-background");
			$(this).children("ul").slideDown();
		},
		function() { 
			$(this).children("ul").slideUp();
			$(this).removeClass("add-background");
		}
	);
	$(".currentpage").next("ul").show();
	$("#financing-form").submit(function() {
		window.location = $("#gourl").val();
		return false;
	});
	//Input the energy calculator, since CMS hates iframes
	$("#energy-calculator").replaceWith('<iframe id="energy-calculator" style="height:600px;" src="http://www.hotspring.com/cgi-bin/energy_calc.cgi" scrolling="no"></iframe>');
	//Get the width of the image to overlay the sold out badge in the cart
	$(".sold-out").each(function() {
		var img_width = $(this).parent().parent().width();
		$(this).css("width", img_width);
	});
});
function popitup(url) {
	newwindow=window.open(url,'name','height=359,width=455');
	if (window.focus) {newwindow.focus()}
	return false;
}