var ie = document.all;
var ns = document.getElementById && !document.all;
var menus = Array();
menus["company"] = false;
menus["soa"] = false;
menus["saas"] = false;
menus["products"] = false;

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function swap (imgName,swapTo) {
	document.images[imgName].src = swapTo;
	}
	
function rollover (imgName) {
	s = document.images[imgName];
	if (s.src.indexOf("_over") > 0) {
		s.src = s.src.replace(/_over/,"");
	} else {
		if (s.src.indexOf(".jpg") > 0) {
			s.src = s.src.replace(/\.jpg/,"_over.jpg");
		}
		if (s.src.indexOf(".gif") > 0) {
			s.src = s.src.replace(/\.gif/,"_over.gif");
		}
	}
}

function menu_over(menu) {
	if (!menus[menu]) { menu_open(menu); }
}

function menu_out(menu) {
	if (!document.all) {	// to avoid flickering in mozilla
		alert(e);
		really_out = false;
		if (e.clientX < menu.offsetLeft || e.clientX > menu.offsetLeft + menu.offsetWidth) {
			really_out = true;
		}
		if (e.clientY > menu.offsetHeight) {
			really_out = true;
		}
		if (really_out) { menu_close(menu); }
	} else {
		menu_close(menu);
	}
}

function menu_open(menu) {
	menu_name = menu.id.substring(menu.id.indexOf("_")+1);
	rollover(menu_name);
//	m = document.getElementById("menu_" + menu);
//	bg = document.getElementById("bg_" + menu_name);
//	bg.style.borderColor = "#ffffff";
	menu.style.height = "auto";
	menus[menu_name] = true;
}

function menu_close(menu) {
	menu_name = menu.id.substring(menu.id.indexOf("_")+1);
	rollover(menu_name);
//	m = document.getElementById("menu_" + menu);
//	bg = document.getElementById("bg_" + menu_name);
	menu.style.height = "54px";
//	bg.style.borderColor = "#006699";
	menus[menu_name] = false;
}

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function menu_pos() {
// menu positions
	temp = Array("company","soa","saas","products","partners");
	start = document.getElementById("menu_company").offsetLeft;
	for (i=1; i<temp.length; i++) {
		document.getElementById("menu_"+temp[i]).style.left = (start + 134 * i) + "px";
	} 
}

function init() {
	
	menu_pos();
	
// size columns to full height of browser, move address & footer to bottom
// top menu is 134px h, remember left col has 50px top padding
// address box 150px h, footer 20px h
	if (l = document.getElementById("left_column")) {
		r = document.getElementById("right_column");
		rH = r.offsetHeight - 20;	// save orig. r Height, less footer
		lH = l.offsetHeight - 150;		// orig l Height, less address
		l.style.minHeight = r.style.minHeight = (getWindowHeight()-134) + "px";	
		if (rH > getWindowHeight()-134) {
			l.style.height = r.offsetHeight + "px";
	// address box move to bottom
			document.getElementById("address").style.marginTop = (r.offsetHeight - lH - 150 + 50) + "px";
			document.getElementById("footer").style.marginTop = (r.offsetHeight - rH - 20 + 50) + "px";			
		} else {
	// address box move to bottom
			document.getElementById("address").style.marginTop = (getWindowHeight()- 134 - lH - 150 + 50) + "px";
			document.getElementById("footer").style.marginTop = (getWindowHeight() - 134 - rH - 20 + 50) + "px";			
		}

	} else {	// index page
		r = document.getElementById("inner");
		rH = r.offsetHeight - 20;	// save orig. r Height, less footer
		r.style.minHeight = getWindowHeight() + "px";	
		if (rH > getWindowHeight()) {
			document.getElementById("footer").style.marginTop = (r.offsetHeight - rH - 2) + "px";			
		} else {
			document.getElementById("footer").style.marginTop = (getWindowHeight() - rH - 2) + "px";			
		}
	}
}
	
function show(divname) {
	document.getElementById(divname).style.visibility = "visible";
	}
	
function hide(divname) {
	document.getElementById(divname).style.visibility = "hidden";
	}
	
function toggle(divname) {
	d = document.getElementById(divname+"_info");
	if (d.style.display == "inline") {
		d.style.display = "none";
	} else {
		d.style.display = "inline";
	}
	d = document.getElementById(divname);
	if (d.innerHTML.indexOf("click to read") > -1) {
		temp = d.innerHTML.replace(/click to read/,"click to close");
	} else {
		temp = d.innerHTML.replace(/click to close/,"click to read");
	}
	d.innerHTML = temp; 
}

function fixFlash() {
	theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}