onError=null;

var EmptyImgArray = new Array();
EmptyImgArray[0] = new Image();
EmptyImgArray[0].src = "images/empty.gif";

var addX = 0;
var addY = 0;
var NS4 = (document.layers) ? true : false;
var IE4 = (document.all) ? true : false;
var is_gecko = (navigator.userAgent.toLowerCase().indexOf('gecko') != -1);
var is_whatever = (document.getElementById) ? true : false;

var scriptrun = false;

function init()
{
	aboutMnu = new SectionItem('divAboutBtn','divAboutMnu',false);
	PressMnu = new SectionItem('divPressBtn','divPressMnu',false);
	ContactMnu = new SectionItem('divContactBtn','divContactMnu',false);
	AlliancesMnu = new SectionItem('divAlliancesBtn','divAlliancesMnu',false);
	SolutionsMainMnu = new SectionItem('divSolutionsBtn','divMainSolutions',false);
	CorporateUsrMnu = new SectionItem('mainCat2','divCorporateMnu',true,'divMainSolutions');
	SolutionsMnu = new SectionItem('mainCat1','divSolutionsMnu',true,'divMainSolutions');
	HomeUsrMnu = new SectionItem('SolutionsLink1','divHomeUsrMnu',true,'divSolutionsMnu');
	//BusinessUsrMnu = new SectionItem('SolutionsLink2','divBusinessUsrMnu',true,'divSolutionsMnu');
	ProvidersUsrMnu = new SectionItem('SolutionsLink2','divProvidersUsrMnu',true,'divSolutionsMnu');
	WWofficeMnu = new SectionItem('Corporate3','divWWOFFICE',true,'divCorporateMnu');
	ChannelMnu = new SectionItem('Alliances3','divChannelMnu',true,'divAlliancesMnu');

	if (is_gecko)
	{
		window.onmousemove = mouseMove;
		window.captureEvents(Event.MOUSEMOVE);
	}
	else
	{
		document.onmousemove = mouseMove;
	}
//	if (is_gecko) document.captureEvents(Event.MOUSEMOVE);
	scriptrun=true;
}

function checkhit(x,y)
{
	//alert('imgy1' + this.imgy1 + ',' + this.imgy2 + ',' + this.imgx1 + ',' + this.imgx2 + ','  + ':::x:' + x + ':::y:'+ y + this.id);
	if ((y>=this.imgy1) && (y<=this.imgy2) && (x>=this.imgx1) && (x<=this.imgx2))
		return true;
	if ((y>=this.menu_y1) && (y<=this.menu_y2) && (x>=this.menu_x1) && (x<=this.menu_x2))
		return true;

	return false;
} 

function SectionItem(btnId,menuId,subMenu,parentMenu)
{	
	this.theMenu = document.getElementById(menuId);
	this.theBtn = document.getElementById(btnId);
	if (parentMenu != '') this.theParent = document.getElementById(parentMenu);
	
	this.id = btnId;
	this.checkhit = checkhit;
	this.menuOn=false;
	
	if (subMenu) 
	{
		addX =  parseInt(this.theParent.offsetLeft);
		addY = parseInt(this.theParent.offsetTop);
	}

	this.imgx1 = parseInt(this.theBtn.offsetLeft) + addX;
	this.imgx2 = this.imgx1+this.theBtn.offsetWidth;

	this.imgy1 = parseInt(this.theBtn.offsetTop) + addY;	
	this.imgy2 = this.imgy1 + this.theBtn.offsetHeight;

	this.menu_x1 = parseInt(this.theMenu.offsetLeft); 
	this.menu_x2 = parseInt(this.theMenu.offsetLeft)+this.theMenu.offsetWidth; 
	this.menu_y1 = parseInt(this.theMenu.offsetTop); 
	this.menu_y2 = parseInt(this.theMenu.offsetTop) + this.theMenu.offsetHeight; 

	this.turnOn = turnOn;
	this.turnOff = turnOff;
	this.imgId = btnId;
	this.menuId = menuId;
}

function turnOff()
{
	this.menuOn = false;
	this.theMenu.style.visibility = 'hidden';
}

function turnOn()
{
	this.menuOn = true;
	this.theMenu.style.visibility = 'visible';
}

function mouseMove(e)
{
	var x = (is_gecko) ? e.pageX : event.x+document.body.scrollLeft;
	var y = (is_gecko) ? e.pageY : event.y+document.body.scrollTop;

//	alert(x + ',' +y);
	if (aboutMnu.menuOn)
	{
		if (!aboutMnu.checkhit(x,y))
		{
			aboutMnu.turnOff();
		}
	}
	
	if (AlliancesMnu.menuOn)
	{
		if (!AlliancesMnu.checkhit(x,y))
		{
			AlliancesMnu.turnOff();
		}
	}

	if (PressMnu.menuOn)
	{
		if (!PressMnu.checkhit(x,y))
		{
			PressMnu.turnOff();
		}
	}

	if (ContactMnu.menuOn)
	{
		if (!ContactMnu.checkhit(x,y))
		{
			ContactMnu.turnOff();
		}
	}

	if(SolutionsMnu.menuOn)
	{
		SolutionsMainMnu.menuOn = false;
		if (!SolutionsMnu.checkhit(x,y))
		{
			SolutionsMainMnu.menuOn = true;
			SolutionsMnu.turnOff();
		}
	}

	if(CorporateUsrMnu.menuOn)
	{
		SolutionsMainMnu.menuOn = false;
		if (!CorporateUsrMnu.checkhit(x,y))
		{
			SolutionsMainMnu.menuOn = true;
			CorporateUsrMnu.turnOff();
		}
	}

	if(HomeUsrMnu.menuOn)
	{
		SolutionsMnu.menuOn = false;
		if (!HomeUsrMnu.checkhit(x,y))
		{
					SolutionsMnu.menuOn = true;
					HomeUsrMnu.turnOff();
		}
	}

/*	if(BusinessUsrMnu.menuOn)
	{
		SolutionsMnu.menuOn = false;
		if (!BusinessUsrMnu.checkhit(x,y))
		{
				SolutionsMnu.menuOn = true;
				BusinessUsrMnu.turnOff();
				
		}
	}*/

	if(ProvidersUsrMnu.menuOn)
	{
		SolutionsMnu.menuOn = false;
		if (!ProvidersUsrMnu.checkhit(x,y))
		{
					SolutionsMnu.menuOn = true;
					ProvidersUsrMnu.turnOff();
		}
	}

	if(ChannelMnu.menuOn)
	{
		AlliancesMnu.menuOn = false;
		if (!ChannelMnu.checkhit(x,y))
		{
			AlliancesMnu.menuOn = true;
			ChannelMnu.turnOff();
		}
	}
	
	if(SolutionsMainMnu.menuOn)
	{
		AlliancesMnu.menuOn = false;
		if (!SolutionsMainMnu.checkhit(x,y))
		{
			AlliancesMnu.menuOn = true;
			SolutionsMainMnu.turnOff();
		}
	}

	if(WWofficeMnu.menuOn)
	{
		CorporateUsrMnu.menuOn = false;
		if (!WWofficeMnu.checkhit(x,y))
		{
			CorporateUsrMnu.menuOn = true;
			WWofficeMnu.turnOff();
		}
	}
	return true;
}

function toURL(url)
{
	document.location.href = url;
}

/*Images functions*/

function MM_swapImgRestore()
{ //v3.0
	var i,x,a=document.MM_sr;
	for(i=0; a&&i<a.length && (x=a[i]) && x.oSrc;i++)
		x.src=x.oSrc;
}

function MM_preloadImages()
{ //v3.0
	var d=document;
	if(d.images)
	{
		if(!d.MM_p)
			d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;

		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{
			d.MM_p[j]=new Image;
			d.MM_p[j++].src=a[i];
		}
	}
}

function MM_findObj(n, d)
{ //v4.0
	var p,i,x;
	if(!d)
		d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for(i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById)
		x=document.getElementById(n);
	return x;
}

function MM_swapImage()
{ //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc)
				x.oSrc=x.src;
			x.src=a[i+2];
		}
}

var widthNum = 500;
var heightNum = 400;
var topNum = 5;
var leftNum = 5;
var HolidayWin = null;

function topLeft()
{
	var IE = (document.all);
	var NS6 = ((document.getElementById) && (!document.all));

	if (IE)
	{
		topNum = parseInt((screen.height - heightNum)/2-15);
		leftNum = parseInt((screen.width - widthNum)/2);
	}
	else if(NS6)
	{
		topNum = parseInt((window.outerHeight + 20 - heightNum)/2-100);
		leftNum = parseInt((window.outerWidth - 8 - widthNum)/2);
	}

	topNum = (topNum <= 5)? 5:topNum;
	leftNum = (leftNum <= 5)? 5:leftNum;
}

function openWin(winName,winWidth,winHeight)
{
	var windowName = winName;
	widthNum = winWidth;
	heightNum = winHeight;
	topLeft();
	var url = (winName == "Holiday")? "events/Holidays.html":"http://www.cti2.com";
	var args = "height=" + heightNum + ",width=" + widthNum + ",top=" + topNum + ",left=" + leftNum + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no";
	HolidayWin = window.open(url,windowName,args);
	HolidayWin.focus();
}
