var home_flag = false;
var pP = "";

(document.layers) ? layerobj = true : layerobj = false;
(document.all) ? allobj = true : allobj = false;
(document.getElementById) ? dom = true : dom = false;

var tdColor="#ffffff";	// menu item text color
var tdBgColor="#05583f";	// menu item background color
var hlColor="#000000";	// highlight text color
var hlBgColor="#f3f9f5";	// highlight background color

var curHl = 0;
var windowWidth = 900;

var menuNumof = 3;
var menuID= [0, "mTwo", "mThree", 0];	// index zero means hide all
var menuState = [ 0, 0 , 0, 0 ];		// 0 = hidden, 1 transition, 2 visible
var menuAction = [ 0, 0 , 0, 0 ];		// 1 = blend to visible, 2 blend to hide
var menuOpacity = [ 0, 0 , 0, 0 ];
var menuTop = [0, 155 , 155, 155 ];
var menuLeft = [0, 140 , 250, 360 ];
var menuHeight = [ 0, 0 , 0, 0 ];
var menuWidth = [ 0, 0 , 0, 0 ];

var menuTimer = 0;
var menuTimeInc = 20;
var menuPerChange = 10;  //Inc * 100 divided by PerChange is the time it takes to transition

function locMenu(index) {

	var wW = 900;
	var mID = "";
	var mLeft = 0;

	if(index >= menuNumof) return;

	if(window.document.body.clientWidth) wW = window.document.body.clientWidth;
	else if(window.innerWidth) wW = window.innerWidth;
	if( wW > windowWidth) mLeft = menuLeft[index] + (wW - windowWidth - 1)/2;
	else mLeft = menuLeft[index];

	mID = menuID[index];

	if(dom) {
		var obj =  window.document.getElementById(mID).style;
		var element =  window.document.getElementById(mID);
		obj.top = menuTop[index] + "px";
		obj.left = mLeft + "px";
		menuHeight[index] = element.offsetHeight;
		menuWidth[index] = element.offsetWidth;
//		element.clip = "rect(obj.top,right,bottom,obj.left)";   Need to fix right and bottom variables
	}
	else if(layerobj) {
		document.layers[mID].top = menuTop[index];
		document.layers[mID].left = mLeft;
	}
	else if(allobj) {
		document.all[mID].style.top =  menuTop[index];
		document.all[mID].style.left =  mLeft;
	}
}

function animEngine()
{
	var i;
	var mID;
	var stoptimer = 1;
	var opacity = 0;
	for(i = 1; i < menuNumof; ++i)
	{
		mID = menuID[i];
		if(mID == 0) continue;
		var object = document.getElementById(mID).style;
		switch( menuAction[i] )
		{
			case 1:
				opacity = menuOpacity[i];
				opacity += menuPerChange;
				stoptimer = 0;
				if( opacity >= 100 ) {opacity = 100; menuAction[i] = 0; menuState[i] = 2;}
				object.opacity = (opacity / 100);
				object.MozOpacity = (opacity / 100);
				object.KhtmlOpacity = (opacity / 100);
				object.filter = "alpha(opacity=" + opacity + ")";
				object.visibility = "VISIBLE";
				menuOpacity[i] = opacity;
				break;
			case 2:
				opacity = menuOpacity[i];
				opacity -= menuPerChange;
				stoptimer = 0;
				if( opacity <= 0 ) {opacity = 0; menuAction[i] = 0; menuState[i] = 0;}
				object.opacity = (opacity / 100);
				object.MozOpacity = (opacity / 100);
				object.KhtmlOpacity = (opacity / 100);
				object.filter = "alpha(opacity=" + opacity + ")";
				menuOpacity[i] = opacity;
				if(opacity == 0) object.visibility = "HIDDEN";
				break;
			default: break;
		}
	}

	if(stoptimer && menuTimer) {clearInterval(menuTimer); menuTimer = 0;}
}


function setMenu(index, the_change) {

	if(index >= menuNumof) return;
	var mID = "";
	var i;

	for(i = 1; i < menuNumof; ++i)
	{
	    mID = menuID[i];
		if( (i == index) && (the_change == "visible")) {
			if(dom) {
				menuAction[i] = 1;
				menuState[i] = 1;
				if(menuTimer == 0) menuTimer = setInterval("animEngine()", menuTimeInc);
			}
			else if(layerobj) document.layers[mID].visibility = "SHOW";
			else if (allobj) document.all[mID].style.visibility = "VISIBLE";
		} else {
		    if(dom) {
				if(menuState[i] == 0) continue;
				menuAction[i] = 2;
				menuState[i] = 1;
				if(menuTimer == 0) menuTimer = setInterval("animEngine()", menuTimeInc);
			}
			else if(layerobj) document.layers[mID].visibility = "HIDE";
			else if (allobj) document.all[mID].style.visibility = "HIDDEN";

			setItem(0,false);
		}
	}

}

function setItem(iID, the_flag) {

	if((the_flag == true) && (iID != 0)) {
		if(dom)  {
			document.getElementById(iID).style.backgroundColor = hlBgColor;
			document.getElementById(iID).style.color = hlColor;
		} else if(layerobj)  {
			document.layers[iID].backgroundColor = hlBgColor;
			document.layers[iID].color = hlColor;
		} else if (allobj) {
			document.all[iID].style.backgroundColor = hlBgColor;
			document.all[iID].style.color = hlColor;
		}

		if( curHl == 0) {curHl = iID; return;}
		if( curHl == iID) return;
	}

	if(curHl == 0) return;

	if(dom)  {
		document.getElementById(curHl).style.backgroundColor = tdBgColor;
		document.getElementById(curHl).style.color = tdColor;
	} else if(layerobj)  {
		document.layers[curHl].backgroundColor = tdBgColor;
		document.layers[curHl].color = tdColor;
	} else if (allobj) {
		document.all[curHl].style.backgroundColor = tdBgColor;
		document.all[curHl].style.color = tdColor;
	}

	if( the_flag == true) curHl = iID;
	else curHl = 0;

}


function init_frame(level,root)
{
if (level == 0) pP = "";
if (level == 1) pP = "../";
if (level == 2) pP = "../../";
if (level == 3) pP = root;

sH = '<table cellspacing="0" name="mTwo" id="mTwo" class="menu" onMouseOver="setMenu(1, \'visible\');">';
sH+= '<tr><td class="menuitem" name="mTwo1" id="mTwo1" onMouseOver="setItem(\'mTwo1\', true);"  onClick="window.location = pP + \'mission.html\';">&bull; Mission &#38; History</td></tr>';
sH+= '<tr><td class="menuitem" name="mTwo2" id="mTwo2" onMouseOver="setItem(\'mTwo2\', true);"  onClick="window.location = pP + \'team.html\';">&bull; Our Team</td></tr>';
sH+= '<tr><td class="menuitem" name="mTwo3" id="mTwo3" onMouseOver="setItem(\'mTwo3\', true);"  onClick="window.location = pP + \'associations.html\';">&bull; Associations</td></tr>';
sH+= '<tr><td class="menuitem" name="mTwo4" id="mTwo4" onMouseOver="setItem(\'mTwo4\', true);"  onClick="window.location = pP + \'care.html\';">&bull; We Care</td></tr>';
sH+= '<tr><td class="menuitem" name="mTwo5" id="mTwo5" onMouseOver="setItem(\'mTwo5\', true);"  onClick="window.location = pP + \'employment.html\';">&bull; Employment</td></tr>';
sH+= '</table>';
document.write(sH);

sH = '<table cellspacing="0" name="mThree" id="mThree" class="menu" onMouseOver="setMenu(2, \'visible\');">';
sH+= '<tr><td class="menuitem" name="mThree1" id="mThree1" onMouseOver="setItem(\'mThree1\', true);"  onClick="window.location = pP + \'services.html\';">&bull; Technical Services</td></tr>';
sH+= '<tr><td class="menuitem" name="mThree2" id="mThree2" onMouseOver="setItem(\'mThree2\', true);"  onClick="window.location = pP + \'technologies.html\';">&bull; Technologies</td></tr>';
sH+= '<tr><td class="menuitem" name="mThree3" id="mThree3" onMouseOver="setItem(\'mThree3\', true);"  onClick="window.location = pP + \'support.html\';">&bull; Training &#38; Support</td></tr>';
sH+= '<tr><td class="menuitem" name="mThree4" id="mThree4" onMouseOver="setItem(\'mThree4\', true);"  onClick="window.location = pP + \'customers.html\';">&bull; Customers</td></tr>';
sH+= '<tr><td class="menuitem" name="mThree5" id="mThree5" onMouseOver="setItem(\'mThree5\', true);"  onClick="window.location = pP + \'casestudies.html\';">&bull; Case Studies</td></tr>';
sH+= '<tr><td class="menuitem" name="mThree6" id="mThree6" onMouseOver="setItem(\'mThree6\', true);"  onClick="window.location = pP + \'partners.html\';">&bull; Partners</td></tr>';
sH+= '</table>';
document.write(sH);
}


function init_menu()
{
document.write('<table cellspacing="0" cellpadding="0" width="550"><tr><td width="40" height="20">&nbsp;</td>');
document.write('<td width="100"><a class="nav" href="' + pP +  'index.html" onMouseOver="setMenu(0, \'hidden\');">HOME</a></td>');
document.write('<td width="100"><a class="nav" href="' + pP +  'mission.html" onMouseOver="locMenu(1); setMenu(1,\'visible\'); setItem(0,false);">ABOUT</a></td>');
document.write('<td width="115"><a class="nav" href="' + pP +  'services.html" onMouseOver="locMenu(2); setMenu(2,\'visible\'); setItem(0,false);">EXPERTISE</a></td>');
document.write('<td width="85"><a class="nav" href="' + pP +  'wordpress/index.php" onMouseOver="setMenu(0, \'hidden\');">NEWS</a></td>');
document.write('<td width="100"><a class="nav" href="' + pP +  'contact.html" onMouseOver="setMenu(0, \'hidden\');">CONTACT</a></td>');
document.write('<td width="10">&nbsp;</td></tr></table>');
}

