/*
	*************************
	**** BEGIN Menu/Submenu
	*************************
*/

/*
	*************************
	**** CONFIGURABLES
	*************************
*/
var _iSubnavHangTime = 400;// ms to keep subnav open before closing unless mouse interaction keeps it open
var _iSubnavTxIn = 200;// ms to transition in open subnav
var _iSubnavInitLeft = 120;// starting left pos of submenu (px); should correspond with CSS
var _iSubnavAnimDist = 30;// pixels to move submenu during transition in
var _iFPS = 50;// frames per second to run FX


/*
	*************************
	**** no need to change anything below
	*************************
*/
var _iSubnavEndLeft = _iSubnavInitLeft + _iSubnavAnimDist;
var _elCurMenuOvr = null;
var _iTimeoutId = null;
var _fxCur = null;
var _aMenuData = [];
var elDbg;

// initialize menu items, submenu items and related data/info
function initMenu(){
//elDbg = document.getElementById("dbg");// remove for deployment
try {
	// determine subnav top positions by inspecting main menu items
  var iTop, sSubnavId, elSubnavItem, oData, oFX;
  var elParent = document.getElementById("mainMenu");
  var aAnchors = elParent.getElementsByTagName("a");

  for(var i=0, iLen=aAnchors.length; i<iLen; i++) {
  	if(aAnchors[i].className.indexOf("mainMenuItem") != -1) {
        sSubnavId = aAnchors[i].getAttribute("rel") || null;

        if(sSubnavId) {
        	elSubnavItem = document.getElementById(sSubnavId) || null;
           if(elSubnavItem) {
             	iTop = getRealPos(aAnchors[i], "Top");
              oFX = null;

           	elSubnavItem.style.top = iTop + "px";
              oFX = new Fx.Morph(elSubnavItem, {fps:_iFPS, duration:_iSubnavTxIn});

             	// update global data
              oData = {id:aAnchors[i].id, elA:aAnchors[i], subId:sSubnavId, elSub:elSubnavItem, top:iTop, fx:oFX};
              _aMenuData.push(oData);
              _aMenuData[aAnchors[i].id] = oData;// make associative as well
              _aMenuData[sSubnavId] = oData;// make associative as well
           }
        }
     }
  }
}catch(e) { alert("ERROR initializing menu:\n" + e.message); }
}

function menuItemOvr(elMenuItem){
	// kill any possible timeouts
	if(_iTimeoutId) window.clearTimeout(_iTimeoutId);

	//	if the same as the curr item, do nothing;   
  if(elMenuItem == _elCurMenuOvr) return;       

  // must be a new subnav to show, hide 'em all before showing it
  resetAllSubnav();

  // update globals
  _elCurMenuOvr = elMenuItem;

  elMenuItem.className = "mainMenuItemOvr";

	// open up subnav of new menu item
  _aMenuData[_elCurMenuOvr.id].fx.start({
  					"display": "block",
					"opacity": [0, 1]
                 ,"left": [_iSubnavInitLeft, _iSubnavEndLeft]
             });	
}

function menuItemOut(elMenuItem){
	_iTimeoutId = window.setTimeout("killSubnav('" + _aMenuData[elMenuItem.id].subId + "');_elCurMenuOvr=null;window.clearTimeout(_iTimeoutId);", _iSubnavHangTime);
}

function subnavOvr(elSub){
	// kill any possible timeouts
	if(_iTimeoutId) window.clearTimeout(_iTimeoutId);       
}

function subnavOut(elSubnav){
	_iTimeoutId = window.setTimeout("killSubnav('" + elSubnav.id + "');_elCurMenuOvr=null;window.clearTimeout(_iTimeoutId);", _iSubnavHangTime);
}

// reset all subnavs to their 'out' state
function resetAllSubnav() {
	for(var i=0, iLen=_aMenuData.length; i<iLen; i++) {
  	killSubnav(_aMenuData[i].subId);
  }
}

function killSubnav(sIdSubnav){
	_aMenuData[sIdSubnav].elA.className = "mainMenuItem";
  _aMenuData[sIdSubnav].fx.cancel();
  _aMenuData[sIdSubnav].fx.set({
    			"opacity": 0
           ,"left": _iSubnavInitLeft
             });
}

/*
	*************************
	**** END Menu/Submenu
	*************************
*/



