var WT_clear = function(_tag) {
	for (var i in _tag.WT) {
		if(i.indexOf("z_") == 0) {
			delete(_tag.WT[i]);
		}
		if(i.indexOf("si_") == 0) {
			delete(_tag.WT[i]);
		}
	}
};

(function($) {
	$(function() {
/* */
		// Generic Tab functionality
		var tabs = $('li[id^=tab], li[id^=tab] span.sub').not('.empty');
		var tab_contents = $('div.tabcontent, table.tabcontent, div.default_tabcontent, table.default_tabcontent');
		var current_techspec_group = 0;

		$(tabs).hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		}).addClass('clickable').click(function() {
			var current_tab_id = $(this).attr('id');
			var tab_wrapper = $(this).closest('.tabwrapper, body');
			var result_count = $(this).find('.result_count').html();
			$("#result_count").html(result_count+" tire"+((result_count != 1) ? 's' : ''));
	
	//		$(tabs).removeClass('current');
	//		$(tab_contents).hide();
			$('li[id^=tab], li[id^=tab] span.sub', tab_wrapper).removeClass('current');
			$('div.tabcontent, table.tabcontent, div.default_tabcontent, table.default_tabcontent', tab_wrapper).hide().css('height:0;overflow:hidden;');
			// $('div.tabcontent, table.tabcontent, div.default_tabcontent, table.default_tabcontent', tab_wrapper).addClass('hidden');
	
			$(this).addClass('current');
	
			if($(this).filter('li').size() != 0 && $(this).children('span.subtabs').size() != 0) {
				$(this).find('span.sub:first').addClass('current');
				current_tab_id = $(this).find('span.sub:first').attr('id');
			} else if($(this).filter('span').size() != 0) {
				$(this).closest('li').addClass('current');
				current_tab_id = $(this).attr('id');
			}
			
			$('#'+current_tab_id+'_content').show();
			// $('#'+current_tab_id+'_content').removeClass('hidden');
	
			return false;
		});

		// Comparison Page by Vehicle Switch Comp Tables
		$("img.totech").addClass('clickable').click(function() {
			$("div#tab_performanceratings_content").hide();
			$("div#tab_techspecs_content").show().find("ul#tabs_performanceratings_comparison li").eq(0).addClass('clickable').click();
			$("b#search_title").html('Technical Specs');
			$("img.switch").toggle();
		});
		$("img.toperf").addClass('clickable').click(function() {
			$("div#tab_techspecs_content").hide();
			$("div#tab_performanceratings_content").show();
			$("b#search_title").html('Performance Ratings');
			$("img.switch").toggle();
		});

/* */
		// Performance Ratings Slider
		var newPos = "0";

/* *
		$('.col2box').each(function() {
			var box	= $(this);
			var pr	= $('.performance_ratings', this);
			var myHeight = 200;
			
			if(box.height() == 0){
				var hiddenContent = $(this).closest('div.tabcontent, tr.prehide');
				
				hiddenContent.css('visibility','hidden').css('display', 'block');
				myHeight = Math.max(box.height(), (pr.height()));
				hiddenContent.css('display', 'none').css('visibility','inherit');
			}
			else{
				myHeight = Math.max(box.height(), (pr.height()));
			}

			box.height(myHeight);
			pr.height("100%");
		});
/* */

		$('.performance_ratings:first').each(function() {
			var pr	= $(this);
			var myHeight = 200;
			
			if(pr.height() == 0){
				var hiddenContent = $(this).parents('div.tabcontent:hidden, tr.prehide');
				
				hiddenContent.css('visibility','hidden').css('display', 'block');
				myHeight = pr.height();
				hiddenContent.css('display', 'none').css('visibility','inherit');
			}
			else{
				myHeight = pr.height();
			}

			$(".shim").height(myHeight);
			pr.height("100%");
		});

		$(".toggle").addClass('clickable').click(function() {
			$('.performance_ratings').filter(function() {
				return(parseInt($(this).css('left')) != 332);
			}).animate({
				left: '332px'
			}).children('.toggle').removeClass('right');
	
			$(this).parents(".performance_ratings").animate({
				left: (332 - parseInt($(this).parents(".performance_ratings").css('left'))+'px')
			}, false, false, function() {
				if($(this).css('left') == "0px") {
					$(this).children('.toggle').addClass('right');
				} else {
					$(this).children('.toggle').removeClass('right');
				}
			});
		});

		// Technical Specs Tabs
		$current_techspec_group = 0;

		group0 = null;
		group1 = null;
		var mysheet=document.styleSheets[0];
		if(mysheet != null) {
			var myrules=mysheet.cssRules? mysheet.cssRules: mysheet.rules;
			for (i=0; i<myrules.length; i++){
				if(myrules[i].selectorText != null) {
					if(myrules[i].selectorText.toLowerCase()==".group0"){
						group0=myrules[i];
						if(group1 != null)
							break;
					}
					if(myrules[i].selectorText.toLowerCase()==".group1"){
						group1=myrules[i];
						if(group0 != null)
							break;
					}
				}
			}
		}

		$('td.more').addClass('clickable').click(function() {
			if($current_techspec_group == 1) {
				group1.style.display = 'none';
				if($.browser.msie)
					group0.style.display = 'block';
				else
					group0.style.display = 'table-cell';
			} else {
				group0.style.display = 'none';
				if($.browser.msie)
					group1.style.display = 'block';
				else
					group1.style.display = 'table-cell';
			}
			$(this).children('div').toggleClass('right');
			$current_techspec_group = 1 - $current_techspec_group;
		});
		
/*
		$group1 = $('#techspecs .group1, #techspecs_all .group1'); 
		$group1.hide();
		$group0 = $('#techspecs .group0, #techspecs_all .group0'); 
		$('td.more').addClass('clickable').click(function() {
			if(current_techspec_group == 1) {
				$group1.hide();
				$group0.show();
				$(this).children('div').toggleClass('right');
			} else {
				$group1.hide();
				$group0.show();
				$(this).children('div').toggleClass('right');
			}
		});
/*
		$group1 = $('#techspecs .group1, #techspecs_all .group1'); 
		//$group1.hide();
		// $group0 = $('#techspecs td:not(.group1, .alwayson),#techspecs_all td:not(.group1, .alwayson)');
		$group0 = $('#techspecs .group0, #techspecs_all .group0'); 
		$('td.more').addClass('clickable').click(function() {
			if($current_techspec_group == 1) {
				$group1.hide();
				$group0.show();
				$(this).children('div').toggleClass('right');
			} else {
				$group0.hide();
				$group1.show();
				$(this).children('div').toggleClass('right');
			}
			$current_techspec_group = 1 - $current_techspec_group;
		});
/* */

		// More table switcher
		var rowHeaders	= $("div#tab_techspecs_content tr.column_titles");
		var moreCells	= $("div#tab_techspecs_content .more");
	
		if(rowHeaders.length != 0 && moreCells.length != 0) {
			var rowCells	= $(rowHeaders).filter(":first").children("td, th");
			var rowContent	= $("tr.techspecs").filter(":not(.column_titles)");
			var rowContentCells = new Array();
			var temp;
			
			var morePositions = new Array();
			for(i=0;i<rowCells.length;i++) {
				if($(rowCells[i]).hasClass(".more, .col5")) {
					morePositions.push(i - morePositions.length + 2);
				}
			}
			morePositions.push(rowCells.length-1);
	
			for(j=0;j<morePositions.length-1;j++) {
				rowContentCells[j] = new Array();
			}
	
			for(k=1;k<morePositions.length;k++) {
				rowContentCells[k-1] = $(rowCells).slice(morePositions[k-1]+k-2,morePositions[k]+k-2).get().concat(
					$(rowHeaders).not(":first").children("td, th").slice(morePositions[k-1]+k-2,morePositions[k]+k-2).get()
				);
	
				for(j=0;j<rowContent.length;j++) {
					multirow_adjust = 0;
					if($(rowContent).eq(j).hasClass('.multicell_middle, .multicell_bottom')) {
						multirow_adjust = morePositions[0];
					}
					
					temp = rowContentCells[k-1].concat(
						$(rowContent).eq(j).children("td, th").slice(morePositions[k-1]-multirow_adjust,morePositions[k]-multirow_adjust).get()
					);
	
					rowContentCells[k-1] = temp;
				}
			}
	
			more1 = $(".more").eq(0);
			more1 = $(".more").eq(2).add(more1);
	
			more2 = $(".more").eq(1);
			more2 = $(".more").eq(3).add(more2);
			
			showTablePage(rowContentCells, 1, more1, more2);
			$(more1).children('div').addClass('clickable').click();
	
			$("#ed1").addClass('clickable').click(function() {
				showTablePage(rowContentCells, 1, more1, more2)
			});
			$("#ed2").addClass('clickable').click(function() {
				showTablePage(rowContentCells, 2, more1, more2)
			});
			$("#ed3").addClass('clickable').click(function() {
				showTablePage(rowContentCells, 3, more1, more2)
			});
			
			$(more1).children("div").addClass('clickable').click(function() {
				if($(this).hasClass('left')) {
					showTablePage(rowContentCells, 1, more1, more2);
				} else {
					showTablePage(rowContentCells, 2, more1, more2);
				}
			});
			$(more2).children("div").addClass('clickable').click(function() {
				if($(this).hasClass('left')) {
					showTablePage(rowContentCells, 2, more1, more2);
				} else {
					showTablePage(rowContentCells, 3, more1, more2);
				}
			});
	
		}

		function showTablePage(rowContentCells, page, more1, more2) {
			switch(page) {
				case 1:
					$(more2).hide();
					$(more1).show().children("div").removeClass("left").addClass("right");
					$(rowContentCells[1]).hide();
					$(rowContentCells[2]).hide();
					$(rowContentCells[0]).show();
					break;
				case 2:
					$(more2).show().children("div").removeClass("left").addClass("right");
					$(more1).show().children("div").removeClass("right").addClass("left");
					$(rowContentCells[0]).hide();
					$(rowContentCells[2]).hide();
					$(rowContentCells[1]).show();
					break;
				case 3:
					$(more1).hide();
					$(more2).show().children("div").removeClass("right").addClass("left");
					$(rowContentCells[0]).hide();
					$(rowContentCells[1]).hide();
					$(rowContentCells[2]).show();
					break;
			}
		}

		$("p.showall").addClass('clickable').click(function() {
			$("table#techspecs, table#techspecs_all").toggle();
			if($(this).html() == 'Show All Sizes') $(this).html('Hide Additional Sizes');
			else $(this).html('Show All Sizes');
		});
		
		$("img#locate_dealer_submit").addClass('clickable').click(function() {
			$(this).closest('form').submit();
		});
		
		$("a.help").addClass('clickable').click(function() {
			var newwin=window.open(this.href,'contact','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=830,height=620');
			return false;
		});

		$("div#locate_dealer input[name=zipCode]").focus(function() {
			if($(this).val() == $(this).attr('alt')) $(this).val('');
		}).blur(function() {
			if($(this).val() == '') $(this).val($(this).attr('alt'));
		});

		if($.fixIESelectWidth) $("select").fixIESelectWidth();
/* */
		
	});
})(jQuery);