﻿function initTabs() {
	showDefault();
	$("ul.tabs").find("a").each(function(i) {
		$(this).click(function(e) {
			e.preventDefault();
			location.hash = $(this).attr("href");
			setTab($(this));
			hideTabs();
			$($(this).attr("href") + "_").removeClass("hidden");
		});
	});

	//Dealer locator tab
	try {
		var cookie = $.cookie("DealerSponsored");
		if (cookie != null && cookie != "") {
			$("a[href='#wheretobuy']").click();
		}
	} catch (err) { }
}
	
function setTab(tab) {
	$("ul.tabs").find("a").each(function(i) {
		$(this).removeClass("selected");
	});
	tab.addClass("selected");
	
	try {
		var page = location.search + location.hash.replace("#", "$");
		trackVirtualPageView(page);
	} catch (err) { }
	
}

function showDefault() {
	$("div.tabs-content > div").each(function() {
		var showId = $(this).attr("id");
		$(this).attr("id", showId + "_");
	});

	hideTabs();
	if (location.hash.length > 0 && $(location.hash + "_").length > 0) {
		$(location.hash + "_").removeClass("hidden");
		setTab($("a[href='" + location.hash + "']"));
	}
	else {
		$($("div.tabs-content > div")[0]).removeClass("hidden")
		setTab($($("ul.tabs").find("a")[0]));
	}
}

function hideTabs() {
	$("div.tabs-content > div").each(function() {
		var showId = $(this).attr("id");
		//$(this).hide();
		$(this).addClass("hidden");
	});
}

