//document ready function
$(document).ready( function() {
	
	//begin navigation dropdown code
	var i = 1;
	$(".dropdown").each(function () {
		var tempclass;
		if (i < 3) {
			tempclass = "hangright";
		}
		else if (i < 5) {
			tempclass = "hangcenter";
		}
		else {
			tempclass = "hangleft";
		}
		$(this).addClass(tempclass);
		i++;
	});

	$(".primary").after('<div class="topleft"> </div><div class="topright"> </div>');

	$(".nav_item").hover( function() {
		$(this).addClass("active");
	},
	function() {
		$(this).removeClass("active");
	});

	//we need to unhide the dropdowns before we can determine their width and height.  This function
	//makes them present but invisible just long enough to get their dimensions and then hides them again.
	$(".dropcontent").before('<div class="leftdrop"> </div>').after('<div class="rightdrop"> </div>');
	$(".dropcontent").each(function () {
		$(this).parent().css("visibility","hidden").css("display","block");
		$(this).prev().height($(this).height()+28);
		$(this).next().height($(this).height()+28);
		$(this).parent().width($(this).width() + 40);
		if ($(this).parent().hasClass("hangleft")) {
			$(this).parent().css("left",$(this).parent().parent().width() - $(this).parent().width() + 20 + "px");
		}
		else if ($(this).parent().hasClass("hangcenter")) {
			$(this).parent().css("left",$(this).parent().parent().width()/2 - $(this).parent().width()/2 + 5 + "px");
		}
		$(this).children(".standard:first").css("border-top","none");
		$(this).children(".buynowdrop:first").css("border-top","none");
		$(this).parent().css("display","none").css("visibility","visible");
	});
	// end navigation dropdown code

	// Copy replacement in search box
	var staticsearchval = $("#searchval").val();
	$("#searchval").focus(function() {
		if ($("#searchval").val() == staticsearchval) {
			$("#searchval").val("");
		}
	});
	$("#searchval").blur(function() {
		if ($("#searchval").val() == "") {
			$("#searchval").val(staticsearchval);
		}
	});
	
	// add clickable hide/show to faqs
	$("dl.faq dd").css("display","none");
	$("dl.faq dt").css("cursor","pointer").css("background","url(/images/common/icons/plus.gif) no-repeat right 4px");
	$("dl.faq dt").click(function() {
		$(this).next("dd").toggle();
		if ($(this).css("background").indexOf("plus") > -1) {
			$(this).css("background","url(/images/common/icons/minus.gif) no-repeat right 4px");
		}
		else {
			$(this).css("background","url(/images/common/icons/plus.gif) no-repeat right 4px");
		}
	});
	
	//add rounded corners to boxes
	$(".proddetail_box").css("margin-top","0").before('<div class="proddetail_boxtop"></div>').after('<div class="proddetail_boxbtm"></div>');
	$(".promo_expertise_box").css("margin-top","0").before('<div class="promo_expertise_boxtop"></div>').after('<div class="promo_expertise_boxbtm"></div>');
	
	//take any set of tabs/links and deactivate the one which is marked current
	$(".current").click(function() {
		return false;
	});
	
	//Firefox 2 nav problem fix
	if (($.browser.mozilla == true) && ($.browser.version < "1.9")) {
		$(".nav_item").css("float","left");
		$("div.nav").html($("div.nav").html().replace(/\|/g,'<span class="pipe">|</span>'));
		$("span.pipe").css("float","left").css("padding-top","7px");
	}
	
	//various after-the-fact css changes
	$(".subproditem:last").css("border-right","none").css("width","150px").css("margin-top","-17px").css("padding-top","52px");
	$(".nav a:first").css("padding-left","0");
	$(".topleft:first").css("width","15px").css("left","-15px");
	$(".dropdown:first").css("left","-28px");
	$(".individual:last").css("border-bottom","none");
	
	//find height of h2's and p's on the line pages and set all at largest height found naturally
	var tallest_h2 = 0;
	var tallest_p = 0;
	$(".product").each(function () {
		if ($(this).children("h2").height() > tallest_h2 ) {
			tallest_h2 = $(this).children("h2").height();
		}
		if ($(this).children("p").height() > tallest_p ) {
			tallest_p = $(this).children("p").height();
		}
	});
	$(".product h2").css("height",tallest_h2 + 3 + "px");
	$(".product p:even").css("height",tallest_p + 5 + "px");
	
	//allow clicking outside search box to close that box
	$('body').click(function() {
    	$(".searchDropdown").css("display","none");
    });
    $('.searchDropdown, #searchtab').click(function(event){
    	event.stopPropagation();
    });

    //trick to allow promotion-less product detail page without breaking layout
    $("img[src*='nopromo.gif']").css("width","1px").css("height","1px").css("margin","0 207px 108px 0").parent("a").css("cursor","default");

	
});
//end document ready function

