/*
	Globals
*/

var slideshow = new Array(
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Everyday.jpg',
	
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Full_VIR.jpg', // step 1
	
	
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Full_Shaun02.jpg', // step 2
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Left_Shaun01.jpg', // step 2 slide
	
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Full_Sport.jpg', // step 3
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Left_Sport.jpg', // step 3 slide
	
	/*
	'images/slides/final/BFG_Homepage_Full_RT.jpg', // step 4
	'images/slides/final/BFG_Homepage_Right_RT.jpg', // step 4 slide (rugged terrain)
	 
	'images/slides/final/BFG_Homepage_Full_spoto.jpg', // step 5
	'images/slides/final/empty.gif', // step 5 slide
	*/
	
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Full_spoto.jpg',	// step 5
	
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Full_KM2.jpg', // step 6 
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Left_KM2.jpg', // step 6 slide
	
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Full_HotRod.jpg', // step 7 hot rod
	'/assets/bfg/system/images/slides/final/BFG_Homepage_Left_HotRod.jpg' // step 7 slide
);
var slidestack = slideshow.slice(0);
var btn_find_tires_clicked = false;

/* Homepage scroller */
var minBrowserWidth = 1048;
var minBrowserHeight = 540;


/* Animation Timeline */
var animation_script = [
	{
		duration: 1.6, // 4 seconds
		enter: function () {
			reveal();
			promoBoxIn("site-intro");
			//console.log("step 1: This is BFGoodrich");
		},
		exit: function() {
			promoBoxOut("site-intro");
		}
	},
	{
		duration: 8, // 4 seconds
		enter: function () {
			reveal();
			//console.log("step 2: Shaun White's Upgrade");
		}
	},
	{
		duration: 3, // 4 seconds
		enter: function () {
			slidefromleft();
			promoBoxIn("promo-slide-2", "left");
			//console.log("step 2: left animation");
		},
		exit: function () {
			promoBoxOut("promo-slide-2");
		}
	},
	{
		duration: 8, // 4 seconds
		enter: function () {
			reveal();
			//console.log("step 3: Shaun White's Upgrade");
		}
	},
	{
		duration: 3, // 4 seconds
		enter: function () {
			slidefromleft();
			promoBoxIn("promo-slide-3", "left");
			//console.log("step 3: left animation");
		},
		exit: function () {
			promoBoxOut("promo-slide-3");
		}
	},
	{
		duration: 8, // 4 seconds
		enter: function () {
			reveal();
			//console.log("step 5");
		}
	},
	{
		duration: 2,
		enter: function() {
			promoBoxIn("promo-slide-5", "left");
		},
		exit: function() {
			promoBoxOut("promo-slide-5");
		}
	},
	{
		duration: 8,
		enter: function () {
			reveal();
			//console.log("step 6: Mud-Terrain T/A KM2");
		}
	},
	{
		duration: 3,
		enter: function () {
			slidefromleft();
			promoBoxIn("promo-slide-6", "left");
			//console.log("step 6: left animation");
		},
		exit: function () {
			promoBoxOut("promo-slide-6");
		}
	},
	{
		duration: 8,
		enter: function () {
			reveal();
			//console.log("step 7: Hot Rod");
		}
	},
	{
		duration: 3	,
		enter: function () {
			slidefromleft();
			promoBoxIn("promo-slide-7", "left");
			//console.log("step 7: left animation");
		},
		exit: function () {
			promoBoxOut("promo-slide-7");
		}
	},
	{
		duration: 8, // 4 seconds
		enter: function () {
			reveal();
			//console.log("---------- Start over ----------");
		}
	}
];



/*	Full screen image resize */

function resizeSlides() {
	var currBrowserHeight = $(window).height() < minBrowserHeight ? minBrowserHeight : $(window).height();
	var currBrowserWidth = $(window).width() < minBrowserWidth ? minBrowserWidth : $(window).width();
	
	var t = $('.slide img');
	var x = $('#stage');
		
	//Define image ratio
	var ratio = t.height()/t.width();
	
	//Gather browser and current image size
	var imagewidth = t.width();
	var imageheight = t.height();
	var browserwidth = currBrowserWidth;
	var browserheight = currBrowserHeight;
	var offset;

	//Resize image to proper ratio
	if ((browserheight/browserwidth) > ratio){
		t.height(browserheight);
		t.width(browserheight / ratio);
		t.children().height(browserheight);
		t.children().width(browserheight / ratio);
	} else {
		t.width(browserwidth);
		t.height(browserwidth * ratio);
		t.children().width(browserwidth);
		t.children().height(browserwidth * ratio);
	}
	t.children().css('left', (browserwidth - t.width())/2);
	t.children().css('top', (browserheight - t.height())/2);
}



/* Animation Functions */

/* The basic animation that splits and image in two sending half up and half down */
function reveal() {
	var nextimg = getnextimage();
	$('#slide1a').css({"left": "25%", "top": "33.3%"}).animate({top: "0%"}, 1500, "easeInQuad", function() {
			//when complete, reposition under the top slide in the viewport (html)
			$('#slide1a').attr("id","slide3a");
			$('#slide2a').attr("id","slide1a").css({"z-index": "8"});
			$('#slide3a').attr("id","slide2a").css({"top": "33.3%", "z-index": "7"});
			$('#slide2a img').attr("src", nextimg);
	});
	$('#slide1b').css({"left": "50%", "top": "33.3%"}).animate({top: "66.7%"}, 1500, "easeInQuad", function() {
			$('#slide1b').attr("id","slide3b");
			$('#slide2b').attr("id","slide1b").css({"z-index": "8"});
			$('#slide3b').attr("id","slide2b").css({"top": "33.3%", "z-index": "7"});
			$('#slide2b img').attr("src", nextimg);
	});

	//$('.promo-slide').fadeOut();
}

function revealAndThen(nextaction) {
	var nextimg = getnextimage();
	$('#slide1a').css({"left": "25%", "top": "33.3%"}).animate({top: "0%"}, 1500, "easeInQuad", function() {
			//when complete, reposition under the top slide in the viewport (html)
			$('#slide1a').attr("id","slide3a");
			$('#slide2a').attr("id","slide1a").css({"z-index": "8"});
			$('#slide3a').attr("id","slide2a").css({"top": "33.3%", "z-index": "7"});
			$('#slide2a img').attr("src", nextimg);
	});
	$('#slide1b').css({"left": "50%", "top": "33.3%"}).animate({top: "66.7%"}, 1500, "easeInQuad", function() {
			$('#slide1b').attr("id","slide3b");
			$('#slide2b').attr("id","slide1b").css({"z-index": "8"});
			$('#slide3b').attr("id","slide2b").css({"top": "33.3%", "z-index": "7"});
			$('#slide2b img').attr("src", nextimg);
			eval(nextaction);
	});

	//$('.promo-slide').fadeOut();
}



/* Place random image on top of slide */
function placeImage(filename, imgtop, imgleft) {
	$('#slideshow').append('<img src="'+filename+'" style="position: absolute; z-index: 10; top: '+imgtop+'; left: '+imgleft+';" class="generated" />');
}

function placeLinkImage(link, filename, imgtop, imgleft) {
	$('#slideshow').append('<a href="'+link+'"><img src="'+filename+'" style="position: absolute; z-index: 10; top: '+imgtop+'; left: '+imgleft+';" class="generated" /></a>');
}

/* Slides the animation from the left hand side of the screen */
function slidefromleft(cta) {
	$('#slide2a').css({"left": "0", "top": "33.3%", "z-index": "9"}).animate({left: "25%"}, 750, "easeInQuad", function() {
		$('#slide1a').attr("id","slide3a");
		$('#slide2a').attr("id","slide1a").css({"z-index": "8"});
		$('#slide3a').attr("id","slide2a").css({"top": "33.3%", "z-index": "7"});
		var nextimg = getnextimage();
		$('#slide2a img').attr("src", nextimg);
		$('#slide2b img').attr("src", nextimg);

		//promoBoxIn(cta, 'left');

	});
}


function slidefromright(cta) {
	$('#slide2b').css({"left": "75%", "top": "33.3%", "z-index": "9"}).animate({left: "50%"}, 750, "easeInQuad", function() {
		$('#slide1b').attr("id","slide3b");
		$('#slide2b').attr("id","slide1b").css({"z-index": "8"});
		$('#slide3b').attr("id","slide2b").css({"top": "33.3%", "z-index": "7"});
		var nextimg = getnextimage();
		$('#slide2a img').attr("src", nextimg);
		$('#slide2b img').attr("src", nextimg);
		
		//promoBoxIn(cta, 'right');
	});
}



/* Reveals the banner at the bottom of the page */
function bannerUp(element) {
	$('#'+element).css({"left": "0", "bottom": "-200px", "z-index": 10});
	$('#'+element).animate({
			left: "0",
			bottom: "0"
		}, 500 , "easeInQuad", function() {
	});				
}

/* Hides the banner at the bottom of the page */
function bannerDown(element) {
	$('#'+element).css({"left": "0", "bottom": "0", "z-index": 10});
	$('#'+element).animate({
			left: "0",
			bottom: "-200px"
		}, 500 , "easeInQuad", function() {
	});				
}

/* Brings down the intro box */
function introDown() {
	$('#intro_bar').show().css({"top": "-300px"}).animate({"top": "50px"}, 500, "easeInQuad", function (){});
}

/* Hide the Introbox */
function introUp() {
	$('#intro_bar').animate({"top": "-300px"}, 500, "easeOutQuad", function() {}).fadeOut();
}

/* Fade In and Out Functions for cleanliness */
function fadeIn(element) {
	$('#'+element).fadeIn();
}

function fadeOut(element) {
	$('#'+element).fadeOut();
}

/* Animate promobox */
function promoBoxIn(element, direction) {
	$('#'+element).removeClass("animate-right").removeClass("animate-left");

	if(direction == 'right') {
		$('#'+element).addClass("animate-right");
		$('#'+element).css({"position": "absolute", "right": "-0px", "left": "auto", top: "45%", "z-index": 10}).show();
		$('#'+element).stop().delay(1000).animate({"right": "220px"}, 400 , "easeInQuad");
	} else {
		$('#'+element).addClass("animate-left");
		$('#'+element).css({"position": "absolute", "right": "auto", "left": "-220px", top: "45%", "z-index": 10}).show();
		$('#'+element).stop().delay(1000).animate({"left": "0px"}, 400);
	}
}

function promoBoxOut(element) {
	if($('#'+element).hasClass("animate-right")) {
		$('#'+element).animate({right: "-0px"}, {duration:400});
	} else {
		$('#'+element).animate({left: "-300px"}, {duration:400});
	}
	
	$('#'+element).removeClass("animate-right").removeClass("animate-left");
}


/* Find Tires / Explore Animation Events */
function findTires() {
	tsdlReset();
	$('#btn_find_tires').animate({
		top: "103px"
	}, 300 , "easeInQuad", function() {
		$('#tire_form').show();
		$('#btn_find_tires').css({"background": "none", height: "auto"}).addClass("maxi");
	}).addClass("maxi");	
	$('#btn_explore').css({'color': '#535353'}).animate({
		top: "254px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");	
}


function explore() {
	tsdlReset();
	$('#btn_find_tires').css({'color': '#535353'}).animate({
			top : "310px",
			fontSize : "16px"
		}, 300 , "easeInQuad", function() {
		$('#explore_form').show();
		$('#btn_find_tires').css({"background": "none", height: "auto"}).addClass("mini");
	});	
	$('#btn_explore').animate({
			top: "47px"
		}, 300 , "easeInQuad", function() {
	}).addClass("maxi");	
}

function tsdlReset() {
	$('#tire_form').hide();
	$('#explore_form').hide();
	$('#btn_find_tires').css({'color': '#fff'}).animate({
			top: "132px",
			fontSize: "43px"
		}, 200 , "easeInQuad", function() {
		$('#btn_find_tires').css({"height": "74px", "background": "url('images/decoration/circle_line.png') no-repeat bottom center"});
	}).removeClass("mini").removeClass("maxi");	
	$('#btn_explore').css({'color': '#fff'}).animate({
			top: "150px",
			fontSize: "43px"
		}, 200 , "easeInQuad", function() {
	}).removeClass("mini").removeClass("maxi");
}


/************************  Animation Loop Manager  ************************/
var paused = false;		// When set to true, prevents slideshow animation
var next_event;
var next;
var prev;
var cursor = 0;			// current position within the animation timeline
var second = 1000;		// JavaScript time methods use milliseconds, but we use seconds for animation timing (its easier)

function animate_next() {

	if (paused == false) {
		if (animation_script.length > 0) {
			// run the exit animation of the previous step
			if(next != undefined) {
				var last = cursor - 1;
				if(last < 0) {
					last = animation_script.length - 1;
				}
				prev = animation_script[last];
			}
			
			next = animation_script[cursor];
			next_event = setTimeout(function() {
				next.enter();
				if(prev != undefined && typeof prev.exit == 'function') {
					prev.exit();
				}
				animate_next();
			}, next.duration * second);
			
			// Move to the next animation step
			cursor++;
			
			// If we've reach the end of the animation, loop back to the beginning
			if(cursor >= animation_script.length) {
				cursor = 0;
			}
		}
	}
}


/* Image Array Manager (Returns the next image and rotates the array) */

function getnextimage() {
	var nextimage = slidestack.shift();			
	slidestack.push(nextimage);
	return nextimage;
}


/* Initialize */

function initSlides() {
	$('.promo-slide').hide();
	
	var nextImg = getnextimage();
	var nextImg2 = getnextimage();

	$('#stage').append('<div id="slide1a" class="slide leftslide"><img src="' + nextImg + '" /></div><div id="slide1b" class="slide rightslide"><img src="' + nextImg + '" /></div>');
	$('#stage').append('<div id="slide2a" class="slide leftslide"><img src="' + nextImg2 + '" /></div><div id="slide2b" class="slide rightslide"><img src="' + nextImg2 + '" /></div>');
	resizeSlides();
	animate_next();
}

function initSlides_old() {
	$('.promo-slide').hide();
	
	var nextImg = getnextimage();
	var nextImg2 = getnextimage();
	
	
	$('<img />').attr('src', nextImg).load(function(){
		$('#stage').append('<div id="slide1a" class="slide leftslide"><img src="' + nextImg + '" /></div><div id="slide1b" class="slide rightslide"><img src="' + nextImg + '" /></div>');
		resizeSlides();

		$('<img />').attr('src', nextImg2).load(function(){
			$('#stage').append('<div id="slide2a" class="slide leftslide"><img src="' + nextImg2 + '" /></div><div id="slide2b" class="slide rightslide"><img src="' + nextImg2 + '" /></div>');
			resizeSlides();
			animate_next();
		});

	});
}


/* TS Helper functions */

function addFifthDropdown() {
	$('#btn_explore').hide();
	$('#dropdown5').show();
	$('#tire_form').css({'top': '132px', 'height': '150px'});
	$('#btn_find_tires').css({'top': '83px'});
}

function removeFifthDropdown() {
	$('#btn_explore').show();
	$('#dropdown5').hide();
	$('#tire_form').css({'top': '153px', 'height': '160px'});
	$('#btn_find_tires').css({'top': '103px'});
}


/* Resize Function for when the browser is more narrow than the page */
var isIE7 = false;
var isIE = false;
function checkWidth_home() {
	if(isIE7 || isIE) {
		window.scrollTo(0,0);
	}

	var browserWidth = $(window).width();
	var browserHeight = $(window).height();
	
	var currBrowserWidth = $(window).width() < minBrowserWidth ? minBrowserWidth : $(window).width();	
	var currBrowserHeight = $(window).height() < minBrowserHeight ? minBrowserHeight : $(window).height();

	var docWidth = $("body").width();
	var docHeight = $("body").height();
	
	var viewWidth = $(window).scrollLeft() + $(window).width();
	var viewHeight = $(window).scrollTop() + $(window).height();
	
	var clipWidth = currBrowserWidth;
	var clipHeight = currBrowserHeight;
	
	if(browserWidth < minBrowserWidth) {
		$("body").css("width", minBrowserWidth +"px");
		
		$("#find_dealer_widget").css({
			'left': '773px',
			'right': 'auto'	
		});
		$("#search_site_widget").css({
			'left': '773px',
			'right': 'auto'	
		});
		$("html").css({'overflow-x': 'auto'});
		$("#background-image").css("min-width", browserWidth+"px");
		$("#background-image").css("width", minBrowserWidth);
		
	} else {
		$("body").css("width", browserWidth +"px");
		$("#find_dealer_widget").css({
			'right': '20px',
			'left': 'auto'	
		});
		$("#search_site_widget").css({
			'right': '20px',
			'left': 'auto'	
		});
		$("html").css({'overflow-x': 'hidden'});
		$("#background-image img").css("min-width", browserWidth+"px");
		$("#background-image").css("width", currBrowserWidth);
	}
	// set background image height so it matches visible area or content space
	//alert($(document.body).height() +" / "+ $(window).height())
	if($(document.body).height() < $(window).height()) {
		$("#background-image").css({"height":$(window).height()+"px"});
	} else {
		$("#background-image").css({"height":$(document.body).height()+"px"});
	}
	// set footer width
	$("#page_footer").css("width", clipWidth +"px");
	
	// tire selector layout
			
	if(typeof(nav_TabName) != 'undefined'){
		$("body").addClass(nav_TabName);
		
		if (nav_TabName == 'tires-page' || nav_TabName == 'tire-layout tires-page'){
			$("#nav-tires a").addClass("selected");
		}
		
		if (nav_TabName == 'explore-page' || nav_TabName == 'tire-layout explore-page'){
			$("#nav-explore a").addClass("selected");
		}
		
		if (nav_TabName == 'news-page' || nav_TabName == 'tire-layout news-page'){
			$("#nav-news a").addClass("selected");
		}
		
		if (nav_TabName == 'heritage-page'){
			$("#nav-heritage a").addClass("selected");
		}
		
		if (nav_TabName == 'contact-us-page'){
			$("#nav-contact a").addClass("selected");
		}
	}
	$("body.tire-layout #scrollable").css("width", currBrowserWidth +"px");
	$("body.tire-layout #scrollable").css("height", currBrowserHeight +"px");
	$("body.tire-layout #page_wrapper").css({
		'width': '100%',
		'height': currBrowserHeight
	});
	
	if(currBrowserWidth <= 1024){
		$("#page_footer ul.horizontal li").css("margin-right","5px")
	}
}


function checkWidth() {
	var browserHeight = $(window).height() ;
	var browserWidth = $(window).width();
	var currBrowserHeight = $(window).height() < minBrowserHeight ? minBrowserHeight : $(window).height();
	var currBrowserWidth = $(window).width() < minBrowserWidth ? minBrowserWidth : $(window).width();
	
	if(browserHeight < minBrowserHeight) {
		$("body").css("height", minBrowserHeight +"px");
	} else {
		$("body").css("height", browserHeight +"px");
	}
	
	if(browserWidth < minBrowserWidth) {
		$("body").css("width", minBrowserWidth +"px");
		$("#searches").css({
			'right' : '15px',
			'top' : '2px'
		});
	} else {
		$("body").css("width", browserWidth +"px");
		$("#searches").css({
			'right' : '40px',
			'top' : '2px'
		});
	}
	
	$("#scrollable").css("width", currBrowserWidth +"px");
	$("#scrollable").css("height", currBrowserHeight +"px");
	$("#scrollable").css("clip", "rect(0px "+currBrowserWidth+"px "+currBrowserHeight+"px 0px)");
}


function tabClick(e) {
	$("#tire_sub_menu li").removeClass("selected");
	$(this).addClass("selected");

	displaySubmitButton(this.id);
	$(".tire_module").hide();
	$("#" + this.id.replace("tab_","tire_")).fadeIn();
}

function displaySubmitButton(tab_name)
{
		if(tab_name=="tab_vehicle")
		{
			document.getElementById('find_vehicle_button_id').style.display='block';
			document.getElementById('find_category_button_id').style.display='none';
			document.getElementById('find_name_button_id').style.display='none';
			document.getElementById('find_size_button_id').style.display='none';
		}
		else if(tab_name=="tab_name")
		{
			document.getElementById('find_vehicle_button_id').style.display='none';
			document.getElementById('find_category_button_id').style.display='none';
			document.getElementById('find_name_button_id').style.display='block';
			document.getElementById('find_size_button_id').style.display='none';
		}
		else if(tab_name=="tab_size")
		{
			document.getElementById('find_vehicle_button_id').style.display='none';
			document.getElementById('find_category_button_id').style.display='none';
			document.getElementById('find_name_button_id').style.display='none';
			document.getElementById('find_size_button_id').style.display='block';
		}
		else if(tab_name=="tab_category")
		{
			document.getElementById('find_vehicle_button_id').style.display='none';
			document.getElementById('find_category_button_id').style.display='block';
			document.getElementById('find_name_button_id').style.display='none';
			document.getElementById('find_size_button_id').style.display='none';
		}
}

/*****************************  Hash Listener  ****************************/
var hashListener;
var lastHash = "";
var firstVisit = true;

function hashChange() {
	// Check for hash tag
	var hash = window.location.hash;
	
	if(hash != lastHash) {
		if(hash.match("tires")) {
			findTires();
			if(firstVisit) {
				setTimeout(pauseAnimation, 2000);
			} else {
				pauseAnimation();
			}
		} else if(hash.match("explore")) {
			explore();
			if(firstVisit) {
				setTimeout(pauseAnimation, 2000);
			} else {
				pauseAnimation();
			}
		}
		lastHash = hash;
	}
	
	firstVisit = false;
}

function pauseAnimation() {
	clearTimeout(next_event);
	paused = true;
}

function main() {
	initSlides();
	resizeSlides();
	checkWidth_home();
    $(".reskin").select_skin();
	$('#find_name_submit').css({'color': '#53535'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_size_submit').css({'color': '#53535'}).animate({
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_category_submit').css({'color': '#53535'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_vehicle_submit').css({'color': '#53535'}).animate({
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	
	
	$('#find_name_submit_disable').css({'color': '#535353'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_size_submit_disable').css({'color': '#535353'}).animate({
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_category_submit_disable').css({'color': '#535353'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_vehicle_submit_disable').css({'color': '#535353'}).animate({
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");


	//Tire Selecter Widget Tooltip
	$(".icon_help, .helplinks").addClass('clickable').click(function(e) {
			$("div.tooltip_widget").show().css({
				position:'absolute',
				top: (e.pageY-30)+'px',
				left:(e.pageX+20)+'px'
			}).children('span').eq(0).html($(this).attr('title').split('\n').join('<br />'));
			return false;
	});
	
	//Tire Selecter Widget Tooltip - Close Botton 
	$("div.tooltip_widget img").addClass('clickable').click(function(event) {
		$("div.tooltip_widget").hide();
		event.stopPropagation();
	});


	/******************************  Events  ******************************/
	$(window).bind("resize", function(){resizeSlides(); checkWidth_home();});
	$('#logo').click(function() {$('#intro_bar').is(":visible") ? introUp() : introDown();});
	// $('#btn_find_tires').click(function() {findTires();});
	$('#btn_find_tires').click(function() {
		btn_find_tires_clicked = true;
		findTires();
	});
	$('#btn_explore').click(function() {explore();});
	$('#find_dealer_widget .close_button').click(function(event) {$('#find_dealer_widget').hide(); $('#searches img').removeClass('selected');});
	
	$('#btn_find_dealer').mouseover(function() {$('.navbar_widget').hide(); $('#searches img').removeClass('selected'); $('#find_dealer_widget').show(); $('#btn_find_dealer').addClass('selected');});
	$('#btn_search_site').mouseover(function() {$('.navbar_widget').hide(); $('#searches img').removeClass('selected'); $('#search_site_widget').show(); $('#btn_search_site').addClass('selected');});
	$('#tire_sub_menu li').click(tabClick);

	$('body').click(function(){
		//tsdlReset();
		$('.navbar_widget').hide();
		$('#searches img').removeClass('selected');

		if (paused) {
			next_event = setTimeout(function () {
				next.enter();
				if(prev != undefined && typeof prev.exit == 'function') {
					prev.exit();
				}
				animate_next();
			}, 100);
			paused = false;
		}
	});
	/*$('#tire_nav').click(function(event){
		event.stopPropagation();
		clearTimeout(next_event);
		pauseAnimation();
	});*/
	$('.navbar_widget').click(function(event){
		event.stopPropagation();
	});
	$('#sliderreset').click();
	
	// Check for hash tag
	hashChange();
	hashListener = setInterval(hashChange, 200);
	document.getElementById('find_vehicle_button_id').style.display='block';
}

$(document).ready(main);
