$(document).ready(function() {
	
	//Fixes IE6 Lack of Support for :hover pseudo-class on anything other than 'a'
	$('#nav-header #dept-head.active,#nav-header #product_type-head.active,#content .related-products,#categories h4').hover(function() {																					
  
		$(this).addClass('any-hover');
		}, function() {
  			$(this).removeClass('any-hover');			
	});
	
	//Swaps Menu on Click
	$('#nav-header #dept-head a,#nav-header #product-head a').click(function() {
		// Get the ids of the tabs
		
		
		var tabID = $('#nav-header li');	
		var thisTarget = $(this).parent('li').attr('id');
		
		
		activateTab(tabID, thisTarget);
		
		$.cookie('T', thisTarget, {expires: 365}); // user upper case cookie names, use 365 because jQuery doesn't have the 30 year option
		
		
	});
	

	
	// Creates Collapseable Categories on Listing Page
	
  	$('#categories > ul').hide();
 	$('#categories > h4').click(function() {
		$(this).next().slideToggle('fast');
		if($(this).hasClass("selected")) {
			$(this).removeClass("selected");
		} else {
			$(this).addClass("selected");
		}
			
  	});
	
	//show all featture
	// feature transplanted to listing.js
	//$("#categories").before("<p><a style='text-decoration:underline;' id='show_all' href='#' >Show All Products</a></p>");
	

	// If anything needs to be preselected ... do that now ...
	$("#categories > .selected").next().show();

		
	$('#show_all').toggle(function() {
  $('#categories > ul:hidden').slideDown('fast');
 if($('#categories > h4').hasClass("selected")) {
			$('#categories > h4').removeClass("selected");
		} else {
			$('#categories > h4').addClass("selected");
		}
  $(this).text('Hide All Products');
}, function() {
  $('#categories > ul:visible').slideUp('fast');
   if($('#categories > h4').hasClass("selected")) {
			$('#categories > h4').removeClass("selected");
		} else {
			$('#categories > h4').addClass("selected");
		}
  $(this).text('Show All Products');
});

	
	//Show/Hide extra Details
		
		//Inserts the Link only if JS is enabled
		if($("#data-product-title").length > 0){
		var productTitle = document.getElementById("data-product-title").innerHTML;
		
		$("#hidden").before("<a id='full-desc' class='collapsed' href='##'>Show Full Description for " + productTitle + "</a>");
		$("#hidden").hide();
		
		//Show and hide the text
		$('#full-desc').click(function() {
			$("#hidden").toggle();
			
		});
		}

		
		//Change text depending on state
		$('#full-desc').toggle(function(){						
			$(this).text("Hide Full Description for " + productTitle);
			$(this).removeClass("collapsed");
			$(this).addClass("shown");
			},function(){
			$(this).text("Show Full Description for " + productTitle);
			$(this).removeClass("shown");
			$(this).addClass("collapsed");
		});
		
		//Get the link of the Realted item and assign it to the DL
//		$("dl.related-products").click(function(){												
//			var linkage = $(this).find('a').eq(0).attr("href");
//			window.location = linkage;
//		});
		
		//Chnages additional options based on the payment selection
		
		if($('#visa, #mc, #amex, #ds').is(':checked')){
			$("#po_info").hide();
		} else if($('#bill').is(':checked')) {
			$("#cc_info, #po_info").hide();
		} else {
			$("#cc_info").hide();
		}
		
		$("#visa, #mc, #amex, #ds").click(function(){
			$("#cc_info").show();
			$("#po_info").hide();
			$("#payment_method").removeClass("no_addOptions");
			});
		$("#po").click(function(){
			$("#cc_info").hide();
			$("#po_info").show();
			$("#payment_method").removeClass("no_addOptions");
			});
		$("#bill, #fax").click(function(){
			$("#payment_method").addClass("no_addOptions");
			$("#cc_info").hide();
			$("#po_info").hide();
			
			});
		
		//prevents user from clicking button more than once
		/*$("#btnReset, input[type='image'], #button").click(function(){
			$(this).attr("disabled","disabled");							  
		});*/
		
		//this class is added to page anchor links where the content is not visible
		//added for web support request#43222  20090211
		$('a.clickPageAnchor').click(function(){						
			$('#full-desc').click();
			});
	
});// EOF
function activateTab(tabID, thisTarget) {
		
		// Assigns "active" to clicked item,  "inactive" to all others
		// Displays appropriate menu based on which is 'active'
		var list, dash, listName;	
		//alert(tabID.length);
		for (var i = 0; i < tabID.length; i++)    {
			
			list = tabID[i].id;
			dash = list.indexOf("-");
			listName = list.substring(0,dash);
			if(thisTarget == tabID[i].id){		
					
			  $(tabID[i]).removeClass().addClass("active");
			  $('#'+listName).css("display","block");
			} else {
			
			 $(tabID[i]).removeClass().addClass("inactive");
			 $('#'+listName).css("display","none");
		   	}
		
		}		
		
}

function rememberTabSelection() {
	
	// userTab will be null if the cookie does not exist
	var userTab = $.cookie('T'); // uppercase cookie names are more x-platform
	var tabID = $('#nav-header li');	
	
	if (userTab) {
		activateTab(tabID, userTab);
	}
	
}