/*************************************************************************
*
*   jQuery Custom Settings for Magnetics
*   jquery-settings.js
*   	
*   Last Updated By: Ryan Perry
*   Last Updated: 7/24/2009
*
*************************************************************************/
$(document).ready(function(){
	/*************************************************************************
	*  Main Menu Drop-Down Navigation Bar
	*************************************************************************/
	$("ul.mainMenu li").superfish({
		hoverClass: 'sfhover',
		autoArrows:	false,
		delay: 200, 			
		animation:	{opacity:'show',height:'show'}	
	});
	
	
	/*************************************************************************
	*  Removes the Right Border on the the Last Top Level Menu Item
	*************************************************************************/
	$("ul.mainMenu li:last-child, ul.langaugeNAV li:last-child").addClass("noRightBorder");
	
	
	/*************************************************************************
	*  Adds a special background and padding on the Last Second Level Menu Item
	*************************************************************************/
	$("ul.mainMenu li ul li:last-child").addClass("secondLevelLast");
	
	
	/*************************************************************************
	*  Adds Alternating Background Color for Odd Rows
	*************************************************************************/
	if ($("table").hasClass("zebraTable")) {
		//$(this).find("tr:nth-child(odd)").addClass("evenRowBG");
		$(this).find("table.zebraTable tr:nth-child(odd)").addClass("oddRowBG");
		//$(this).find("td").parent("tr").removeClass("evenRowBG");
		//$(this).find("tr.totalRow").removeClass("evenRowBG");
		$(this).find("tr.totalRow").removeClass("oddRowBG");
		$(this).find("tr td:last-child").addClass("noBorder");
		$(this).find("tr td.newOrderRemove").prev("td").addClass("noBorder");
		$(this).find("tr.buttonRow").removeClass("oddRowBG");
	};
		
	//$("table.zebraTable tr:nth-child(odd)").addClass("oddRowBG");
	$("table.zebraAccordionTable tr:nth-child(odd)").addClass("oddAccordionRow");
	$('.sampleOrderOutputContainer table.zebraTable tr td:last-child').addClass("noBorder");
	
	$(".popupContainer table tr:last-child .row-title, .popupContainer table tr:last-child .row-data").css({"border-bottom" : "none"});
	
	/*************************************************************************
	*  Removes the Alternating Background Color if the class is applied to the TR of 
	*  Total Row, the Button Row and Title Row Accordion Table
	*************************************************************************/
	//$("table.zebraTable tr.totalRow, table.zebraTable tr.buttonRow").removeClass("oddRowBG");
	$("table.zebraAccordionTable tr.titleRow").removeClass("oddAccordionRow");

	
	/*************************************************************************
	*  Adds 8px Padding to the top of the TD of the first Data Row.
	*************************************************************************/
	$("table.nonZebraTable tr:eq(1) td, table.zebraTable tr:eq(1) td").addClass("topPadding8");
	$("table.checkPricingResultTable tr:eq(2) td:child").addClass("topPadding8");
	
	
	/*************************************************************************
	*  Removes 8px Padding to the top of the TD of the first Data Row.
	*************************************************************************/	
	$("table.checkPricingResultTable tr:eq(2) td table.checkPricingResultSubTable tr td").removeClass("topPadding8");
	
	
	/*************************************************************************
	*  Removes Border on last Column and Last list items.
	*************************************************************************/
	$("table tr td:last-child, ul.dividerList li:last-child").addClass("noRightBorder");

	
	/*************************************************************************
	*  Adds Right Border to Rowspan TD
	*************************************************************************/
	$("table.checkPricingResultTable tr:eq(1) td:last-child").addClass("rightBorder");


	
	/*************************************************************************
	*  Adds Hover Class Fixes Bug in IE6
	*************************************************************************/
	$("h3.accordionHeader").hover(function() {
		$(this).addClass("accordionHeaderHover");
		}, function() {
			$(this).removeClass("accordionHeaderHover");
		}
	);
	
	
	/*************************************************************************
	*  Adds Tooltip display for Check Pricing
	*************************************************************************/
	if(jQuery().toolTip) {
		//jQuery plugin exists
		$(".toolTip a, .toolTip").tooltip({
			showURL: false,
			track: true,
			delay: 0,
			extraClass: "toolTipOverlay", 
			fixPNG: true,
			showBody: " - ",
			left: -120
		});
	} else {
		//jQuery plugin DOES NOT exist
    
	};
	
	
/*================================================
 Fix Search Arrow for IE8
================================================*/
if($.browser.msie){
	
	if ($.browser.version == 8) {
		$(".headerSearchButton").css({"top" : "6px"});
		//alert($.browser.version);
		//alert("Browser is IE8");
		//$('.header-container .nav li').bgiframe();
	}else {
		//alert("Browser is not IE6");
	};
};
		
		
	/*************************************************************************
	*  Add Remove Icon if more than 1 Check Pricing Result
	*  If Remove Button is pressed the row is removed from the results and a function
	*  call to determin the number of remaining rows, if result rows count is only one  the
	*  Remove Icon is not displayed for the associated row
	*************************************************************************/	
	var cpResultCount = $("td.checkPricingRemoveData").length;
	
	$("td.checkPricingRemoveData:gt(0)").ready(function() {
		$("td.checkPricingRemoveData").append("<a href='#/' title='Remove From Results' class='checkPricingRemoveIcon toolTip'>remove</a>");
	});
	
	(function($) {
		$.fn.checkPricingResultDisplay = function() {
			//alert(cpResultCount);
		
			if (cpResultCount == 1) {
				//alert(cpResultCount);
				$("td.checkPricingRemoveData").fadeOut(1000);
			}
		};
	})(jQuery);
	
	$(".checkPricingRemoveIcon").click(function(){
		$(this).parent().parent().fadeOut(1000);
		cpResultCount = cpResultCount - 1;
		$(cpResultCount).checkPricingResultDisplay();
	});
	
	
	/*************************************************************************
	*  New order part number  input
	*************************************************************************/		
	$(".newOrderInputPart:text").blur(function() {
		//$("newOrderMuitipleReleasePart").previous(".newOrderInputPart:text");
	});
	
	
	$(".formSelectAllButton, .formSelectAll2Button").click( function() {
		$("form :checkbox").attr("checked", true);
		return false;
	});
	
	$(".formDeselectAllButton, .formDeselectAll2Button").click( function() {
		$("form :checkbox").attr("checked", false);
		return false;
	});	
	
	
	/*************************************************************************
	*  Customer Login 
	*************************************************************************/		
	$(".customerLoginLink").click( function() {
		$(".customerLogin").slideDown("slow");
	});
	
	
});	