/* GLOBAL VARS */
var objLastShown; // used for to switch off last shown div
var objFly;  // object to show - global because you can't pass objects with setTimeout

var zip_value		="";
var address_value	="";
var city_value		="";

var make	= (get_cookie("make")	!=null)?(get_cookie("make"))	:"";
var model	= (get_cookie("model")	!=null)?(get_cookie("model"))	:"";
var year	= (get_cookie("year")	!=null)?(get_cookie("year"))	:"";
var option	= (get_cookie("option")	!=null)?(get_cookie("option"))	:"";

/* simple dom constructor */
function getRef(id) {
	return (document.getElementById ? document.getElementById(id) : document.all[id]); 
}

/* initialize variables and objects */
function tdslInit() {
	objLastShown = null;
}

/* show the flyout and hide the old one 
	- showing of the new flyout is on a timer */
function animateFlyout(id) {
	
	objFly = getRef(id);
	
	// turn off the last displayed div if exists
	if (objLastShown != null) {
		initFlyout();
	} else {
		showFlyout();
	}
	objLastShown = objFly; // div to hide on next pass		
	
}

/* close the last shown flyout - set the timer for the new flyout*/
function initFlyout() {
	objLastShown.style.display = "none";
	//setTimeout("showFlyout()", 500);
	showFlyout();
}

/* show the flyout */
function showFlyout() {
	objFly.style.display = "block";
}

/* close the last shown flyout and init the last shown object */
function closeFlyout() {
	objLastShown.style.display = "none";
	tdslInit();
}

/* load the specified iframe with the specified source */
function loadTireFrame(theIframe, thePage) {
	var theFrame = getRef(theIframe);
	theFrame.src = thePage;
}

function handleSidenav(type) {
	switch(type) {
		case "vehicle":
			// display disabled select boxes and button
			dis_select('make');
			dis_select('model');
			dis_select('year');
			dis_select('option');
			dis_button("by-vehicle-btn");
			
			animateFlyout('flyout_vhc');
			
			if (make.length>0 && model.length>0 && year.length>0 && option.length>0) {
				// prepopulate boxes with vehicle data
				show_items_preselected();
			}else{
				// populate the 'make' select box
				show_items('year','years');
			}
			break;
		case "size":
			// display disabled select boxes and button
			dis_select('tireSizeType');
			dis_select('tireSectionWidth');
			dis_select('tireAspectRatio');
			dis_select('tireRimDiameter');
			dis_button("tire-size-btn");
			
			animateFlyout('flyout_sz');
			
			// populate the 'tireName' select box
			show_items('tireSizeType','types');
			break;
		case "name":
			// display disabled select boxes and button
			dis_select('prodId');
			dis_button("tire-name-btn");
			
			animateFlyout('flyout_nm');
			
			// populate the 'tireName' select box
			show_tire_names('prodId');
			break;
		case "dealer":
			animateFlyout('flyout_dlr');
			document.sidebarDealerSearch.zipCode.value=zip_value;
			document.sidebarDealerSearch.zipCode.onfocus=document.sidebarDealerSearch.zipCode;
			document.sidebarDealerSearch.address.value=address_value;
			document.sidebarDealerSearch.city.value=city_value;
			break;
	}
}
