$(document).ready(function() {
/*
	if (($("#leftnav li").length == 0) && ($("#leftnav a").length == 0)) {
		$("#leftnav").hide();
		$("#leftbottom").hide();
	}
*/
	$("#item-image").width("auto");
	$("#product-images .scroll a img").width("auto");
	$(".leftblue").hover(
		function() {
			$(this).css("background-image", "url('images/leftgreen.jpg')");
		},
		function() {
			$(this).css("background-image", "url('images/leftblue.jpg')");
		}
	);
	$(".stico_default").css("background", "url('images/sharethis.jpg') no-repeat");
	$("#stwrapper").css("left", "2000");
	
	var i=1;
	for(i=1; i<=6; i++) {
		var banner_link = $('#banner-' + i).val();
		//if(banner_link != '') $('#s4 img:eq(' + parseInt(i-1) + ')').wrap('<a href="' + banner_link + '" />');
	}
});

var helvetica = { src: 'fonts/helveticaneueltstd-lt.swf' };
sIFR.activate(helvetica);
sIFR.replace(helvetica, {
  wmode: 'transparent',
  selector: 'h1',
  css: '.sIFR-root { color: #164B88;}',
  offsetTop:5
});
sIFR.replace(helvetica, {
  wmode: 'transparent',
  selector: 'h2',
  sFlashVars: 'tuneHeight=10&offsetTop=5',
  css: '.sIFR-root { leading: -2; transparent; color: #1f5d72; }, #cities h2 { background-color: #EAF2F4; }',
  offsetTop:5
});
sIFR.replace(helvetica, {
  wmode: 'transparent',
  selector: '#leftnav h4',
  css: '.sIFR-root { transparent; color: #003E7B; }',
  offsetTop:5
});

$(document).ready(function() {
	jQuery.each(jQuery.browser, function(i, val) {
		if(i != "msie" && jQuery.browser.version.substr(0,3) != "6.0") {
			$("#navbar li.top-level a").hover(
				function() {
					$(this).css("background", "#48838d");
				},
				function() {
					$(this).css("background", "none");
				}
			);
			$("#navbar li:not(.top-level) a").hover(
				function() {
					$(this).css("background", "none");
				}
			);
			$("#navbar #hot-tubs .mega").hover(
				function() {
					$("#navbar #hot-tubs a.top-level").css("background", "#48838d");
				},
				function() {
					$("#navbar #hot-tubs a.top-level").css("background", "none");
				}
			);
			$("#navbar #saunas .mega").hover(
				function() {
					$("#navbar #saunas a.top-level").css("background", "#48838d");
				},
				function() {
					$("#navbar #saunas a.top-level").css("background", "none");
				}
			);
			$("#navbar #water-care .single-dropdown").hover(
				function() {
					$("#navbar #water-care a.top-level").css("background", "#48838d");
				},
				function() {
					$("#navbar #water-care a.top-level").css("background", "none");
				}
			);
			$("#navbar #health-benefits .single-dropdown").hover(
				function() {
					$("#navbar #health-benefits a.top-level").css("background", "#48838d");
				},
				function() {
					$("#navbar #health-benefits a.top-level").css("background", "none");
				}
			);
			$("#navbar #repair .single-dropdown").hover(
				function() {
					$("#navbar #repair a.top-level").css("background", "#48838d");
				},
				function() {
					$("#navbar #repair a.top-level").css("background", "none");
				}
			);
			$("#navbar #services .mega").hover(
				function() {
					$("#navbar #services a.top-level").css("background", "#48838d");
				},
				function() {
					$("#navbar #services a.top-level").css("background", "none");
				}
			);
		}
	});
	
	$(".mega").each(function() {
	    var largest_ul = 0;
	    $(this).children("ul").each(function() {
	        var ul_children = $(this).children("li").length;
	        if(largest_ul < ul_children) largest_ul = ul_children;
	    });
	    
	    
	    $(this).children("ul").each(function() {
	    	var current_ul_children = $(this).children("li").length;
	    	var children_difference = parseInt(largest_ul) - parseInt(current_ul_children);
	    	if(children_difference != 0) {
	    		var i = 1;
	    		for(i=1; i<=children_difference; i++) {
	    			$(this).append('<li class="no-bg">&nbsp;</li>');
	    		}
	    	}
	    });
	});
	
	$(".mega").each(function() {
		$(this).children("ul:last").children("li").css("border", "0");
	});
	
	$(".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()) - 65;
			$(this).css("left", "19px");
		}
		$(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();
		}
		if($(".specs-small table").is(":hidden")) {
			$(this).children("span").html("hide");
			$("#hot-tub-specs-small").css("background-image", "url('images/up_hot_tub_specs.gif')");
			$(".specs-small table").slideDown();
			$(".bl").hide();
			$(".br").hide();
		}
		else if($(".specs-small table").is(":visible")) {
			$(this).children("span").html("expand");
			$("#hot-tub-specs-small").css("background-image", "url('images/down_hot_tub_specs.gif')");
			$(".specs-small 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").hoverIntent(
		function() { 
			$(this).addClass("add-background");
			$(this).children("ul").slideDown();
		},
		function() { 
			$(this).children("ul").slideUp();
			$(this).removeClass("add-background");
		}
	);
	$(".currentpage").next("ul").show();
	$("ul").has("li.currentpage").css("display", "block");
	$(".categories ul li a").hover(
		function() {
			$(this).css("background", "url(/images/left_nav_hover.jpg) no-repeat");
			$(this).css("color", "#ffffff");
		},
		function() {
			$(this).css("background", "none");
			$(this).css("color", "#367384");
		}
	);
	$(".mega ul").has("li.currentpage").css("display", "block");
	$("#footernav #pipe:last").hide();
	$("#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; width:500px; border:0px;" 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);
	});
	
	$("#spec-table tr:even").addClass("even");
	


});