var timesover=0;
var timerID = null;
//var boolFirstMenuFlag = true;
var boolTimerOn = false;
var intTimecount = 450;
var intRunCount = 0;
var intTabActive = 999;
var intNumTabs = 5;
var asTabs = new Array();
	asTabs[0] = "solutions";
	asTabs[1] = "customerreferences";
	asTabs[2] = "casestudies";
	asTabs[3] = "aboutus";
	asTabs[4] = "contactus";
////////////////////////////////////////////////	
var ThisBoolTimerOn = false;
var ThisTimerID = null;
var IsMenu = false;

var ThisIsMenuTimer = false;
var ThisIsMenuBoolTimerOn = false;

function StopTime(){
	if (ThisBoolTimerOn){
		clearTimeout(ThisTimerID);
        ThisTimerID = null;
        ThisBoolTimerOn = false;
	}
	if(ThisIsMenuBoolTimerOn == false){
		ThisIsMenuTimer = setTimeout("MenuItemTime()",450);
		ThisIsMenuBoolTimerOn = true;
	}
}

function StartTime(id){
	/* initialize the menu to figure out which tab is set to active */
	if (ThisIsMenuBoolTimerOn){
		clearTimeout(ThisIsMenuTimer);
	    ThisIsMenuTimer = null;
	   	ThisIsMenuBoolTimerOn = false;
	}
	
	if (ThisBoolTimerOn == false && IsMenu == false) {
		ThisTimerID=setTimeout("ThisMenuOn('" + id + "')",intTimecount);
		ThisBoolTimerOn = true;
		IsMenu = true;
	}else{
		ThisMenuOn(id);
	}
}

function MenuItemTime(){
	IsMenu = false;
	ThisIsMenuBoolTimerOn = false;
}
/////////////////////////////////////////////////////////	
function doMenuOn(id) {
	StartTime(id);
}

function doInitializeMenu() {
	for (i=0; i<intNumTabs; i++)
	{
		if(document.getElementById("menuitem-" + asTabs[i]).className=="mainmenuitem active")
			intTabActive = i;
	}
}

function settimeover(){
timesover=1;
}

function ThisMenuOn(id){
	/* initialize the menu to figure out which tab is set to active */
	
	if (intRunCount < 1)
	{
		doInitializeMenu();
		intRunCount++;
	}

	
	//if (boolFirstMenuFlag == true)
	//{

		/* hide any menus that might be open */
		if (document.getElementById("menuitem-" + id).className == "mainmenuitem active" && timesover==0)
		{
		//alert("active");
		timesover=1;
		}
		else
		{
		timesover=1;
		doHideAll();
		/* if statement to check if the submenu acutally exists, because the home menu doesn't have one */
		if(document.getElementById("submenu-" + id))
		{
			var subMenu = document.getElementById("submenu-" + id);
			var shim = $('menuShim');
			subMenu.style.display = "block"; /*turn on the submenu*/
			shim.show();
			window.setTimeout("lame('" + subMenu.id + "')", 250);
			var sm = $(subMenu);
			shim.clonePosition(sm);
		}
		
		/* change the style of the tab to the hover style */	
		for(var i=0; i < asTabs.length; i++){
			if(asTabs[i] == id && i!=0){
				//alert("asTabs=" + asTabs[i]);
				//alert("i=" + i);
				//alert("id=" + id);
				document.getElementById("menuitem-" + asTabs[i-1]).className = "mainmenuitem removeLine"; 
			}
		}
		/* stop the timer */
		doStopTime(); 
		}
	//}
}

function lame(subMenu)
{
	var shim = $('menuShim');
	shim.clonePosition($(subMenu));
}

function doMenuOff() {
for (i=0; i<intNumTabs; i++)
	{
		if(document.getElementById("menuitem-" + asTabs[i]).className=="mainmenuitem active")
			timesover=1;
	}
	/*start the timer */
	doStartTime(); 
	StopTime();
}
function doSubMenuOn(){
	/* stop the timer */
	doStopTime(); 
}
function doSubMenuOff(){
	 /* start the timer */
	 doStartTime();
}
function doHideAll(){
	for (i=0; i<intNumTabs; i++)
	{
		/* if statement to check if the submenu exists before we try to hide it */
		if(document.getElementById("submenu-" + asTabs[i]))
			document.getElementById("submenu-" + asTabs[i]).style.display = "none"; /* hide the submenu */
		$('menuShim').hide();
		/*set all tabs to the inactive style */
		/* ry comment out for image buttons */
		/* document.getElementById("menuitem-" + asTabs[i]).className="mainmenuitem inactive";
 */
	}
	/*set the active tab to the active style*/
	if (intTabActive < 999)
	{
		document.getElementById("menuitem-" + asTabs[intTabActive]).className="mainmenuitem removeLine";
	}
}
function doStopTime(){
	if (boolTimerOn){
		clearTimeout(timerID);
        timerID = null;
        boolTimerOn = false;
	}

}
function doStartTime(){
	if (boolTimerOn == false) {
		timerID=setTimeout( "doHideAll()" , intTimecount);
		boolTimerOn = true;
	}
}

//used to open videos in success stories.
function MM_openBrWindow(theURL,winName,features) { //v2.0
var winl = (screen.width - 705) / 2;
var wint = (screen.height - 100) / 2;
window.open(theURL,winName,features + ",top="+wint+", left="+winl);
}

function locWin(locTitle,locURL,locOptions) {

var picWinHTML = '<html>';
picWinHTML += '<head><title>' + locTitle + '</title></head>';
picWinHTML += '<script language="JavaScript" type="text/javascript">self.focus();</script>';
picWinHTML += '<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">';
picWinHTML += '<div align="center"><img src="' + locURL + '" alt="' + locTitle + '" border="0"></div>';
picWinHTML += '</body>';
picWinHTML += '</html>';

var picWin = window.open('','NULL',locOptions);
picWin.document.open();
picWin.document.write(picWinHTML);
picWin.document.close();

}
// ****** opens link in popup window
 function CreateWindow(url) { 
  		topL=20;
  		leftL=20;
  		width=550;
  		height=400;    
  		toolbar=1;      
  		scrollbar=1;      
    wName='popUp';
  		width = (arguments.length>1)?arguments[1]:width; // option to pass in width
  		height = (arguments.length>2)?arguments[2]:height; // option to pass in height    
  	 toolbar = (arguments.length>3)?arguments[3]:toolbar; // option to turn toolbar off
  	 scrollbar = (arguments.length>4)?arguments[4]:scrollbar; // option to turn scrollbar off
  	 wName = (arguments.length>5)?arguments[5]:wName; // option to pass in window name     
    
  		var str="toolbar="+ toolbar +",location=0,directories=0,status=0,menubar=0,scrollbars="+ scrollbar +",width="+ width +",height="+ height +",screenX="+ leftL +",screenY="+ topL +",left="+ leftL +",top="+ topL +",resizable=1";
    var Pwin = window.open(url,wName,str,true)
    Pwin.focus();

}