function BrowserInfo() {
	var agent = window.navigator.userAgent;
	if (agent.indexOf("MSIE") != -1) {
			var start = agent.indexOf("MSIE");
			this.name = "MSIE";
			this.version = parseFloat(agent.substring(start + 5, agent.indexOf(";", start)));
	} else if (agent.indexOf("Firefox") != -1) {
			var start = agent.indexOf("Firefox");
			this.name = "Firefox";
			this.version = agent.substring(start + 8, agent.length);
			var firstDec = this.version.indexOf(".") + 1;
			while (this.version.indexOf(".", firstDec) != -1)
				this.version = this.version.substring(0, firstDec) + this.version.substring(firstDec).replace(".", "");
			this.version = parseFloat(this.version);
	} else {
			this.name = "Unknown";
			this.version = 0;
	}
}

var info = new BrowserInfo();
var isIE6 = (info.name == "MSIE" && info.version < 7);


if (info.name == "MSIE" && info.version < 7)
	document.writeln('<link href="SugoiTemplates/stylesIE6.css" rel="stylesheet" type="text/css" />');
else
	document.writeln('<link href="SugoiTemplates/stylesDynamic.css" rel="stylesheet" type="text/css" />');



function renderFlash(src, width, height, features) {
	document.writeln('<embed src="' + src + '" quality="high" width="' + width + 
					 '" height="' + height + '" align="middle" allowscriptaccess="sameDomain" ' +
					 'type="application/x-shockwave-flash" ' + features + 
  					 'pluginspage="http://www.macromedia.com/go/getflashplayer" />');
}


var fades = new Array(6);
var vis=false;

function getIdxFromID(id) {
	switch (id) {
		case "navRun":
			return 0;
			break;
		case "navRide":
			return 1;
			break;
		case "newTri":
			return 2;
			break;
		case "navCustom":
			return 3;
			break;
		case "navMore":
			return 4;
			break;
		case "menu_more_dropdown":
			return 5;
			break;
	}
}

function menuFadeOut(id) {
	var element = document.getElementById("id");
	var idx = getIdxFromID(id);

	clearTimeout(fades[idx]);

	menuFadeOutStep(id, 100);
}

function menuFadeOutStep(id,val) {
	var idx = getIdxFromID(id);

	if (val > 0) {
		val = val - 10;
		setOpacity(id, val);
	}
	if (val != 0) {
		var hdl = setTimeout("menuFadeOutStep('" + id + "'," + val + ");",25);
		fades[idx] = hdl; 
	}
	else {	
		if (id=="menu_more_dropdown") {
			menuVisible = false;
			//var el = document.getElementById("id");
			//el.style.display='none';
		}
	}
}

function menuFadeIn(id) {
	var idx = getIdxFromID(id);

	clearTimeout(fades[idx]);

	menuFadeInStep(id, 0);
}

function menuFadeInStep(id,val) {
	var idx = getIdxFromID(id);

	if (val < 100) {
		val = val + 25;
		setOpacity(id, val);
	}	
	if (val != 100) {
		var hdl = setTimeout("menuFadeInStep('" + id + "'," + val + ");",25);
		fades[idx] = hdl; 
	}
	else {
		if (id=="menu_more_dropdown") {
			moreVisible = true;
		}
	}
}

//change the opacity for different browsers 
function setOpacity( id,opacity) { 
	if (id=="menu_more_dropdown" && menuVisible != true) {
		return;
	}

    var object = document.getElementById(id).style; 
    object.display = "block";
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
	
	if (opacity == 100) {
		object.filter = "";
	} else if (opacity == 0) {
		object.display = "none";
	}
} 

function navOut(id) {
	menuFadeOut(id);
	return;

}

function navOver(id) {
	menuFadeIn(id);
	return;
}

var hide;
var show;
var Showing = 0;
var menuVisible = false;

function showMoreMenu(force) {
	if (menuVisible == true || force == true) {
		if (Showing==1 && !force) { window.status = new Date().getMilliseconds().toString(); return; }

		Showing = 1;

		clearTimeout(show);

		menuVisible = true;
		show = setTimeout("menuFadeIn('menu_more_dropdown');", 250);
	}
}

function hideMoreMenu(force) {
	clearTimeout(hide);
	hide = setTimeout("start_hideMoreMenu();", 500);
}

function cancelHide() {
	Showing = 1;
	clearTimeout(hide);
}

function start_hideMoreMenu() {
//	if (Showing!=1) { return; }
	Showing = 0;

	menuFadeOut('menu_more_dropdown');
}


var userAgent = window.navigator.userAgent
var isIE = (window.navigator.userAgent.indexOf("MSIE") != -1);
var isFirefox = (window.navigator.userAgent.indexOf("Firefox") != -1);
var isIE6 = (parseFloat(userAgent.substring(userAgent.indexOf("MSIE ") + 5)) <= 6);
var isSafari = (navigator.userAgent.indexOf("Safari") > 0);

function writePngID(url, width, height, alt, id, root) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" id=\"" + id + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
	else
		document.write("<img alt=\"" + alt + "\" id=\"" + id + "\"  src=\"" + root + "/SugoiTemplates/images/spacer.png\" style=\"width: " + width + "px; height: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function writePngIDH(url, height, alt, id, root) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" id=\"" + id + "\" src=\"" + url + "\" style=\"height2: " + height + "px;\">");
	else
		document.write("<img alt=\"" + alt + "\" id=\"" + id + "\"  src=\"" + root + "/SugoiTemplates/images/spacer.png\" style=\"height2: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function writePngIDHStyle(url, height, alt, id, style,root) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" id=\"" + id + "\" src=\"" + url + "\" style=\"height2: " + height + "px;" + style + "\">");
	else
		document.write("<img alt=\"" + alt + "\" id=\"" + id + "\"  src=\"" + root + "/SugoiTemplates/images/spacer.png\" style=\"height2: " + height + 
			"px; " + style + " filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}


function writePngImage(url, width, height, alt, root) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
	else
		document.write("<img alt=\"" + alt + "\" src=\"" + root + "/SugoiTemplates/images/spacer.png\" style=\"width: " + width + "px; height: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function writePngClass(url, width, height, alt, className) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" class=\"" + className + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
	else
		document.write("<img alt=\"" + alt + "\" class=\"" + className + "\"  src=\"/SugoiTemplates/images/spacer.png\" style=\"width: " + width + "px; height: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function writePngLinkClass(lnk, url, width, height, alt, className) {
	if (!isIE6)
		document.write("<a href=\"" + lnk + "\"><img alt=\"" + alt + "\" class=\"" + className + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\"></a>");
	else
		document.write("<a href=\"" + lnk + "\"><img alt=\"" + alt + "\" class=\"" + className + "\"  src=\"/SugoiTemplates/images/spacer.png\" style=\"width: " + width + "px; height: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\"></a>");
}

function slideSearchPanel() {
	var curY = parseInt(document.getElementById("search_panel").style.top);
	if (curY < 0) {
		slidePanelStep(1, 8, 0);
	} else {
		slidePanelStep(1, 8, 1);
	}
}

function slidePanelStep(step, steps, dir) {
	var pnl = document.getElementById("search_panel");
	var ctr = document.getElementById("shift");
	var distance = 25;
	var i = (distance * (step / steps));

	if (dir == 1) {
		pnl.style.top = -i + "px";
		ctr.style.top = -i + "px";

	} else {
		pnl.style.top = i - distance + "px";
		ctr.style.top = i - distance + "px";
	}
	// 74 - 134
	if (step <= steps)
		setTimeout("slidePanelStep(" + (step + 1) + "," + steps + "," + dir + ")", 10);
	else if (dir == 1) {
		var img = document.getElementById("pnlButton");

		if (img.src = "SugoiTemplates/images/search_btn_open.png") {
			img.src = "SugoiTemplates/images/search_btn_close.png";
		}

		pnl.style.top = "-" + distance + "px";
		ctr.style.top = "-" + distance + "px";
	} else {
		var img = document.getElementById("pnlButton");

		if (img.src = "SugoiTemplates/images/search_btn_close.png") {
			img.src = "SugoiTemplates/images/search_btn_open.png";
		}

		pnl.style.top = "0px";
		ctr.style.top = "0px";
	}
}
