$(document).ready(function() {
		
/********************** For Hard Parts Image Map - Highlight **********************/
	$("area").click(function() {
		var anchorID = $(this).attr("href");
		var anchorIDfloat = parseFloat(anchorID.substring(1));
		$("ul.partlist li").removeClass("highlight");
		$("ul.partlist li.partnum_" + anchorIDfloat).addClass("highlight");
	});
/********************** Tables **********************/
	$("table.tabdata").filter(function(){
		/* Apply THead Background*/
		$("thead tr:last-child th",this).css("background","#f1f1f1 url('/images/theme/tbl_th_bg.jpg') repeat-x bottom");
		/* Remove Extra Borders */	
		$("tbody tr:first-child td",this).css("border-top","none");	
		$("tbody tr td:last-child, thead tr th:last-child",this).css("border-right","none");
	});
	/* Apply odd Class - Only Works on Simple Tables*/
	$("table.tabdata:not(.no-odd)").each(function(){
			$("tbody tr:odd",this).addClass("odd");
	});
/******************** Accordion ********************/
	//Show First Container and Hide the Rest
	$('.accordioncontainer:not(:first)').hide();
	$('.accordioncontainer:first').show();
	$('.accordiontrigger:first').addClass('accordiontrigger_active');
	
	//Hover Fade Effect
	$('.accordiontrigger').hover(
		function(){$(this).stop().fadeTo("normal", 0.80)},
		function(){$(this).stop().fadeTo("normal", 1);}
	);
	//Accordion Trigger
	$('.accordiontrigger').click(function(){
		if($(this).next().is(':visible')){
			$(this).toggleClass('accordiontrigger_active');
			$(this).next().slideToggle('slow');
		}
		else{
			$('.accordiontrigger').removeClass('accordiontrigger_active');
			$('.accordioncontainer').slideUp('slow');
			$(this).toggleClass('accordiontrigger_active');
			$(this).next().slideToggle('slow');
		}
		return false;
	});
/********************* Slider **********************/
	$('.toggle_trigger').toggle(
		function() {
			//Slides Down the Container
			$(this).next('.toggle_container').slideDown('fast');
		},
		function() {
			//Hides the Object Tag
			$(this).next('.toggle_container').find("object").hide('fast');
			//Slides Up the Container and Shows the Object Tag (so it can be shown if trigger gets click again)
			$(this).next('.toggle_container').slideUp().find("object").show('fast');
		}
	);
/********************** Col1 ***********************/
	$('ul.col1 li:first-child').addClass('border_none');
/*********************** PDF ***********************/
	$("a[href$='.pdf']:not(:has('img'))").addClass("download");
	
// Tabbed Function
	$(".tab_nav li").click(function () {
		$(".selecttab").removeClass("selecttab");
		$(this).addClass("selecttab");
		$(".tabcontent").hide();
		var active_show = $(this).attr("title");
		$("#"+active_show).show();
		return false; 
	});
/******************** ON SALE NOW PAGE ********************/
//Sort Promo with Cat ID /*--Special Deals Page--*/
	$("#catidselector select").change(function() {
		$("ul.col1 li, .js_message").fadeOut('fast');
		var catidVal = $(this).val(); //Get Cat ID
		var catName = $("#catidselector select :selected").text();
		if ($("li").hasClass("catid_" + catidVal)) { //If selection matches cat ID
			$("li.catid_" + catidVal).fadeIn('fast');
		} else if ( catidVal == '-1' ) { //If selection is default
			$("ul.col1 li").show();
		}
	});
//Open Video Accordion by Query String
	var dealsQuery = location.search; //Get query string
	dealsQuery = dealsQuery.replace(/^\?/,''); // remove the leading ?	
	var vars = dealsQuery.split("&"); //Splits multiple queries
	var variable;
	
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
	if ( $("ul.col1 li").is("#" + pair[1]) ) { //If query string matches list ID then...
		$(document).ready(function(){
			$("li#" + pair[1]).find(".toggle_container").css({'display' : 'block'}); //Open video accordion
		});
	}
});