window.name="ite_main";

var opera = (navigator.userAgent.indexOf('Opera') >= 0) ? true : false;
var dom = (document.getElementById) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nn4 = (navigator.appName == "Netscape" || !dom) ? true : false;
var obj = (nn4) ? window:document;
var prevMenus = {};

/* Pre-loading menu images */
var m1 = new Image();
m1.src = '/i/m1.gif';
var m1a = new Image();
m1a.src = '/i/m1a.gif';
var m2 = new Image();
m2.src = '/i/m2.gif';
var m2a = new Image();
m2a.src = '/i/m2a.gif';
var m3 = new Image();
m3.src = '/i/m3.gif';
var m3a = new Image();
m3a.src = '/i/m3a.gif';
var m4 = new Image();
m4.src = '/i/m4.gif';
var m4a = new Image();
m4a.src = '/i/m4a.gif';
var m5a = new Image();
m5a.src = '/i/m5a.gif';

function menuFlip(img, mode) {
	var menuId = null;
	var prevMenu = null;
	if (img) {
		var p = img.id.match(/^(\D*)/);
		menuId = p[1];
	}
	if (prevMenus[menuId] && prevMenus[menuId] != img) menuFlip(prevMenus[menuId], 'hide');
	if (img == null) return;
	var suf = "";
	var id = img.id+"s";
	if (mode == 'on') {
		suf = "a";
		showLayer(id);
		prevMenus[menuId] = img;
	} else {
		suf = "";	
		hideLayer(id);
		prevMenus[menuId] = null;
	}
	img.src = img.src.replace(/[ac]?(\.[^.]+)$/, suf+"$1");	
}

function showHideLayer(id, bShow) {
	var obj; 
	var cmd = bShow? "visible" : "hidden";
	if (dom && !opera)
		obj = document.getElementById(id) && document.getElementById(id).style;
	else
		if (ie4 && !opera)
			obj = document.all[id] && document.all[id].style;
		else
			if (nn4) {
				obj = document.layers[id];
				cmd = bShow? "show" : "hide";
			}
	if (!obj) return;
	obj.visibility = cmd;
}

function showLayer(id) { showHideLayer(id, 1); }
function hideLayer(id) { showHideLayer(id, 0); }

function showScreen(img_url, img_title, product_id) {
	if (!product_id) product_id = 'tracker';
	var product_name = (product_id == 'tracker' ? 'Stuffed Tracker' : 'Factory Nova');
	var img_url = '/i/products/'+product_id+'_screens/'+img_url;
	var img_title = product_name+' | Screenshots | '+img_title;
	window.open('/lib/pages/screen.html?img_url='+escape(img_url)+'&img_title='+escape(img_title), 'main_window', 'resizable=0, scrollbars=1, width=940, height=600');
	return false;
}

function showTrackerDemo(name, title, width, height) {
	var path = '/products/tracker/demos/'+name+'/'+name;
	title = 'Stuffed Tracker | Flash Movies | '+title;
	window.open('/lib/pages/demo.html?path='+escape(path)+'&title='+escape(title)
		+'&width='+width+'&height='+height, 
		'main_window');//, 
		//'resizable=0, scrollbars=0, width=920, height=600');
	return false;
}

function showFactoryDemo(name, title, width, height) {
	var path = '/products/factory/demos/'+name+'/'+name;
	title = 'Factory Nova | Flash Movies | '+title;
	window.open('/lib/pages/demo.html?path='+escape(path)+'&title='+escape(title)
		+'&width='+width+'&height='+height, 
		'main_window');//, 
		//'resizable=0, scrollbars=0, width=920, height=600');
	return false;
}


var Color = new Array('transparent','#ffe','#ffd','#ffc','#ffb','#ffa','#ff9');

function fadeElement(id, bg_color, firstDelay) {
  var el = document.getElementById(id);
  if (!el) return this;

  if (bg_color) Color[0] = bg_color;  

	if (firstDelay == null) firstDelay = 300;

	var idx = Color.length-1;
  setTimeout("doFade('"+id+"', "+idx+")", firstDelay);
}

function doFade(id, idx) {
	if (id == null) return false;

  var el = document.getElementById(id);
  if (!el || idx == -1) return false;

  el.style.backgroundColor = Color[idx];
  idx -= 1;
  setTimeout("doFade('"+id+"', "+idx+")", 150);
}

function GetObj(id) { 
  return document.getElementById(id);
}
