//pcichon
// restoration: tma

var rollOvers = new Array();
var timer;

function Is() {
	var agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent
			.indexOf('compatible') == -1)));
	this.ns4 = (this.ns && (this.major == 4));
	this.ns6 = (this.ns && (this.major >= 5));
	this.ie = (agent.indexOf("msie") != -1);
	this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.") == -1));
	this.ie5 = (this.ie && (this.major >= 4) && (agent.indexOf("msie 5.") != -1));
}

function getAbsX(elt) {
	return (elt.x) ? elt.x : getAbsPos(elt, "Left");
}

function getAbsY(elt) {
	return (elt.y) ? elt.y : getAbsPos(elt, "Top");
}

function getAbsPos(elt, which) {
	iPos = 0;
	while (elt != null) {
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
}

function showMenu(name) {

	hideAll();
	clearTimeout(timer);

	var item = document.getElementById("menu" + name);
	var img = document.getElementById("img" + name);
	var pos = getAbsX(img) - 1;

	if (new Is().ie) {
		item.filters[0].Apply();
		item.filters[0].Play();
	}

	item.style.visibility = "visible";
	item.style.left = pos;
}

function checkPos(img) {
	return img.offsetLeft;
}

function hideMenu(name) {
	timer = setTimeout("hide(\'menu" + name + "\')", 1000);
}

function hide(name) {
	document.getElementById(name).style.visibility = 'hidden';
}

function hideAll() {
	for (i = 1; i <= 6; i++)
		hide("menu" + i);
}

function hideAllTimer(stimer) {
	timer = setTimeout("hideAll()", eval(stimer));
}

function getSrcOver(src) {
	var i = src.indexOf(".", src.length - 5);
	var srcOver;

	if (src.indexOf("_over") != -1)
		srcOver = src;
	else
		srcOver = src.substr(0, i) + "_over" + src.substr(i);
	return srcOver;
}

function imgRollOverCommon(s, src, id, width, height, srcOver) {
	if (width) {
		s += ' width="' + width + '"';
	}
	if (height) {
		s += ' height="' + height + '"';
	}
	if (id) {
		s += ' id="' + id + '"';
	}
	s += '>';

	rollOvers[rollOvers.length] = new Image();
	rollOvers[rollOvers.length - 1].src = srcOver;
	rollOvers[rollOvers.length - 1].src2 = src;
	rollOvers[rollOvers.length - 1].id = id;

	document.write(s);
}

function imgRollOverMenu(src, idm, width, height, id) {
	var srcOver = getSrcOver(src);
	var s = '<img id="img' + idm + '" name="img' + idm + '" src="' + src + '"'
			+ ' align="absmiddle"' + ' border="0"'
			+ ' onMouseOver="this.src=\'' + srcOver + '\';showMenu(\'' + idm
			+ '\');return true;"' + ' onMouseOut="this.src=\'' + src
			+ '\';hideAllTimer(2000);return true;"';

	imgRollOverCommon(s, src, id, width, height, srcOver);
}

function imgRollOver(src, id, width, height) {
	var srcOver = getSrcOver(src);

	var s = '<img src="' + src + '"' + ' align="absmiddle"' + ' border="0"'
			+ ' onMouseOver="this.src=\'' + srcOver + '\';"'
			+ ' onMouseOut="this.src=\'' + src + '\'"';

	imgRollOverCommon(s, src, id, width, height, srcOver);
}

function imgOverById(id, src) {
	if (!src) {
		var i;
		for (i = 0; i < rollOvers.length; i++)
			if (rollOvers[i].id == id)
				src = rollOvers[i].src;
	}

	var img = document.getElementById(id);
	if (img)
		img.src = src;
}

function imgOutById(id, src) {
	if (!src) {
		for ( var i = 0; i < rollOvers.length; i++)
			if (rollOvers[i].id == id)
				src = rollOvers[i].src2;
	}

	var img = document.getElementById(id);
	if (img)
		img.src = src;
}

function showBiger(path, width, height, title, top, left) {
	if (width == '')
		width = 16;
	if (height == '')
		height = 16;

	width = width * 1; // What is that? Casting to number???
	height = height * 1;

	var margin = 50;

	if (!title)
		title = path;
	width += margin;
	height += margin * 2;

	// scroll if neaded
	var margin = 100;
	var scroll = "no";
	if (((window.screen.width - margin < width) || (window.screen.height
			- margin < height))) {
		scroll = "yes";
		if (window.screen.width - margin < width)
			width = window.screen.width - margin;
		if (window.screen.height - margin < height)
			height = window.screen.height - margin;
	}

	if (!top)
		top = (window.screen.height - margin - height) / 2
	if (!left)
		left = (window.screen.width - margin - width) / 2

	if (path.charAt(0) != '/')
		path = '/' + path;

	var wnd = window.open("/products/modalphoto.xml?rand=" + Math.random()
			+ "&image=" + path + "&title=" + title, "larger", "top=" + top
			+ ", left=" + left + ", width=" + width + ", height=" + height
			+ ",status=0,help=0,scroll=" + scroll);

	wnd.focus();
}

function PopupWindow(url, width, height, windowName) {
	_PopupWindow(url, width, height, 150, windowName);
}

function popup(url, width, height, windowName) {
	_PopupWindow(url, 510, height, 150, windowName);
}

function _PopupWindow(url, width, height, top, windowName) {
	var center_x = (screen.width - width) / 2;
	var center_y = (screen.height - height) / 2;
	var win = window.open(url, windowName,
			"toolbar=no,location=no,directories=no,"
					+ "status=no,menubar=no,scrollbars=yes,resizable=no,"
					+ "copyhistory=no,left=" + center_x + ",top=" + center_y
					+ ",width=" + width + ",height=" + height);
}

function rollover(id, destid, src) {
	document.getElementById(destid).src = src;
}

rnd.today = new Date();
rnd.seed = rnd.today.getTime();

function rnd() {
	rnd.seed = (rnd.seed * 9301 + 49297) % 233280;
	return rnd.seed / (233280.0);
};

function rand(number) {
	return Math.ceil(rnd() * number);
};

function getPageElement(id) {
	if (document.layers) {// "NN4";
		return document.layers[id];
	}

	if (document.all) { // "ie"
		return document.all[id];
	}

	if (!document.all && document.getElementById) {// "NN6";
		return document.getElementById(id);
	}

	return false;
}

function drawImage(id, sub) {
	var td = getPageElement('td_' + sub);
	if (td) {
		if (id == 1 || id == 2) {
			td.setAttribute('valign', 'top', 'false');
		} else {
			td.setAttribute('valign', 'bottom', 'false');
		}
	}
	document.write('<img width="102" src="/images/back/' + id + '_' + sub
			+ '.gif">');
}

function toggleSimpleMode(on) {
	var div = getPageElement('smDiv');
	if (div) {
		div.style.visibility = on ? "visible":"hidden";
	}
}

var i = rand(6);

function switchImg(z, next) {
	if (next && ++z > 6)
		z = 1;
	else if (--z < 1)
		z = 6;

	i = z;

	tsShow(getPageElement('tsdiv'), i);
	return false;
}

function tsNav() {
	var s = '<a title="Previous" href="#" style="color: 909090;" onClick="javascript:switchImg(i,false);" style="text-decoration: none;"><img src="/images/arr_left.gif" onMouseOver="this.src=\'/images/arr_left_over.gif\';" onMouseOut="this.src=\'/images/arr_left.gif\';" border="0"/></a>&nbsp;<a title="Next" href="#" style="color: 909090;" onClick="javascript:switchImg(i,true);"  style="text-decoration: none;"><img src="/images/arr_right.gif" onMouseOver="this.src=\'/images/arr_right_over.gif\';" onMouseOut="this.src=\'/images/arr_right.gif\';" border="0"/></a>';
	return s;
}

function tsShow(p, z) {
	if (p) {
		var url = '/films/popup.xml?imgid=' + z;
		var src = '<a href="javascript: PopupWindow(\'' + url
				+ '\',650,500,\'Torqueshots\');">';
		src += '<img id="ts_thumb" src="/servlet/com.janmedia.images.ImageConverter?widthMax=124&quality=0.95&img=';
		src += '/upload/wysiwyg/films/torque/shots/t_' + z + '.jpg';
		src += '" border="0" alt="Click to enlarge">';
		src += '</a>';
		p.innerHTML = src;
	}
}

function showPic(a, random, num) {
	var s;
	var len = a.length;
	if (random)
		s = a[rand(len - 1)];
	else {
		if (num <= len)
			s = a[num - 1];
		else {
			var index = (num % len);
			if (index < 0)
				index = 0;
			s = a[index];
		}
	}
	if (s.src)
		document.write('<img src="' + s.src + '" align="bottom">');
}

function showDetails(href) {
	PopupWindow(href,560,560,'popup');
// We have got rid of html layers because they were not compatibile with qt player plugin.
//	var dialog = $('<div id=\'modal_holder\'/>');
//	$('body').append(dialog);
//	$.ajax({ url: "/rf/type", data: "href="+href, success: function(msg){
//		dialog.load(href, {}, function(responseText, textStatus, XMLHttpRequest) {
//			dialog.dialog({
//				width : 560,
//				height : 560,
//				resizable : false,
//				title : msg,
//				close: function(event, ui) { $('#modal_holder').remove() }
//			});
//		});
//    }});
}

function myAddListener(obj, evt, handler, captures) {
	if (document.addEventListener)
		obj.addEventListener(evt, handler, captures);
	else
		// IE
		obj.attachEvent('on' + evt, handler);
}

/* define functions that register each listener */
function RegisterListener(eventName, objID, embedID, listenerFcn) {
	var obj = document.getElementById(objID);
	if (!obj)
		obj = document.getElementById(embedID);
	if (obj)
		myAddListener(obj, eventName, listenerFcn, false);
}

function onMovieEnd() {
	hidePlayer();
}

function showPlayerMain(movie, background) {
	var x = 800;
	var y = 450;

	showPlayerCommon(movie, background,x * ratio, y * ratio, {
		'top' : (docheight - (y+73) * ratio) / 2 + 'px',
		'right' : (docwidth - x * ratio) / 2 + 'px'
	});
}

function showPlayer(movie, background) {
	showPlayerCommon(movie, background, (800 * ratio), (450 * ratio), {
		'top' : playerHeight + 'px',
		'right' : playerWidth + 'px'
	});
}

function setMute(mute)
{
	if (document.qtmovie)
	{
		document.qtmovie.SetMute(mute);
	}
	else if (false)
	{
	}
}


function showPlayerCommon(movie, background, width, height, attributes) {
	var playerDiv = getPageElement('playerDiv');

	if (playerDiv) {
		hideElement('playerDiv');
		showElement('playerDiv', attributes);

		if (movie.substring(movie.length - 3, movie.length) == 'mov') {
			showQTPlayer(movie, background, width,height, attributes,playerDiv);
		} else {
			showFlashPlayer(movie, background, width, height, attributes,playerDiv)
		}

		showElement('playerDiv', attributes);
	}
}

function showFlashPlayer(movie, background, width, height, attributes,playedDiv) {
	playerDiv.innerHTML = "<div id=\"playerCont\"/>";

	var params = {
		movie_src : movie
	};
	var attributes = {
		allowFullScreen : "true",
		wmode : 'transparent'
	};
	swfobject.embedSWF("videoplayer.swf", "playerCont", (800 * ratio),
			(450 * ratio), "8.0.0", false, params, attributes);
}

function whichBrs() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}

function showQTPlayer(movie, background, width, height, attributes,playerDiv) {
	playerDiv.innerHTML = "<div id=\"playerCont\"/>";
	if (qtinst) {
		var qt = new QTObject(movie, 'qtmovie', width, height);
		qt.addParam("autostart", "true");
		qt.addParam("target", "myself");
		qt.addParam("controller", "true");
		qt.addParam("bgcolor", "black");

		// T#10656, PCH, 2009-10-14, new QT Player version issue
		// should be restored, when the bugfix from Apple appears
		qt.addParam("scale", "tofit");
		qt.addParam("loop", "false");

		qt.addParam("postdomevents", "false");
		qt.write("playerCont");
		RegisterListener('qt_ended', 'qtmovie', 'qtmovie', onMovieEnd);
	} else {
		playerDiv.innerHTML = "<center><br><br><a href='http://www.apple.com/quicktime' target='_blank'>Quick Time 7 Plugin <font color='#FF0000'>not detected</font>.<br>This content requires the newest QuickTime Plugin.<br>Download QuickTime Player.</a><br></center>";
	}
}

function showElement(id_attribute_value, attributes) {
	if (document.getElementById && document.getElementById(id_attribute_value)
			&& document.getElementById(id_attribute_value).style) {
		var el = document.getElementById(id_attribute_value);
		el.style.visibility = 'visible';
		el.style.display = 'block';
		if (attributes != null) {
			for (a in attributes) {
				el.style[a] = attributes[a];
			}
		}
	}
}

function hideElement(id_attribute_value) {
	if (document.getElementById) {
		var d = document.getElementById(id_attribute_value);
		if (d && d.style) {
			d.style.visibility = 'hidden';
			d.style.display = 'none';
			d.innerHTML = "";
		}
	}
}

function hidePlayer() {
	var obj = document.getElementById('gilFlash');
	if (obj) {
		obj.movieCompleteHandler();
	}
	hideElement('playerDiv');
}

function getQuicktimeVersion() {
	var quicktimeVersion;
	var agent = navigator.userAgent.toLowerCase();

	// NS3+, Opera3+, IE5+ Mac (support plugin array): check for Quicktime
	// plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		for (i = 0; i < navigator.plugins.length; i++) {
			var plugin = navigator.plugins[i];
			if (plugin.name.indexOf("QuickTime") > -1) {
				quicktimeVersion = parseFloat(plugin.name.substring(18));
			}
			if( quicktimeVersion!=undefined ) return quicktimeVersion;
		}
	}

	// IE4+ Win32: attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4
			&& agent.indexOf("win") != -1 && agent.indexOf("16bit") == -1) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obQuicktime \n');
		document
				.write('set obQuicktime = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1") \n');
		document.write('if IsObject(obQuicktime) then \n');
		document.write('   if obQuicktime.IsQuickTimeAvailable(0) then \n');
		document
				.write('      quicktimeVersion = CInt(Hex(obQuicktime.QuickTimeVersion) / 1000000) \n');
		document.write('   end if \n');
		document.write('end if \n');
		document.write('</scr' + 'ipt\> \n');
	}

	// Can't detect in all other cases
	else {
		quicktimeVersion = quicktimeVersion_DONTKNOW;
	}
	return quicktimeVersion;
}

