// javacript code for Alphalogic menu system

oaMenus = new Array();

// if menuTimer is greater than 0 you must enter coordinates for each primary menu.
menuTimer = 0; //timeout time in seconds
menuWidth = 139; // width of each menu

// menu positioning for each primary menu
menuPosition = 0;  //0=relative to menu pad, 1=absolute

// this stuff is for fading menus
fadeCycles = 0; // number of fade cycles. make 0 for no fade
fadePause = 0; // time in ms between each fade cycle
startRGB = new Array (255,255,255);  //fade start color
endRGB = new Array (200,200,0); //fade end color

// menus require one transparent gif and an arrow gif
clearImage = "http://www.fremontohio.org/media/clear.gif"
arrowImage = "http://www.fremontohio.org/media/subMenuArrow.gif"

// oaMenus[<inc>] = new menu(<menuid|-1>,x-coord,y-coord);
// the coordinates are optional and should only be entered for parent menus
// if the menuPosition is not absolute then the coordinates are relative
// to the pad location
oaMenus[0] = new menu(-1);
oaMenus[1] = new menu(-1);
oaMenus[2] = new menu(2,1,22);
oaMenus[3] = new menu(3,1,22);
oaMenus[4] = new menu(-1);
oaMenus[5] = new menu(-1);
oaMenus[6] = new menu(-1);
oaMenus[7] = new menu(-1);
oaMenus[8] = new menu(-1);
oaMenus[9] = new menu(-1);
oaMenus[10] = new menu(-1);


//oaMenus[<menu inc>].menuItem[<inc>] = new menuItem(<item name>,<url>,<window name>,<linked menu id|-1>);
//<window name> is any arbitrary name you choose for a popup window, blank for no popup window
oaMenus[0].menuItem[0] = new menuItem('Alphalogic','http://www.alsnet.com','',-1);
oaMenus[0].menuItem[1] = new menuItem('<img border=0 src="http://www.alsnet.com/achannel/images/admissions.gif">','http://www.cnn.com','',-1);
oaMenus[0].menuItem[2] = new menuItem('more sites','','',10);

oaMenus[1].menuItem[0] = new menuItem('oracle','http://www.oracle.com','',8);
oaMenus[1].menuItem[1] = new menuItem('yahoo - no link','','',-1);
oaMenus[1].menuItem[2] = new menuItem('google - more sites','http://www.google.com','',4);

oaMenus[2].menuItem[0] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/auditor.gif">','pages/auditor.html','',-1);
oaMenus[2].menuItem[1] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/economic.gif">','pages/economic.html','',-1);
oaMenus[2].menuItem[2] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/engineering.gif">','pages/engineering.html','',-1);
oaMenus[2].menuItem[3] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/fire.gif">','pages/fire.html','',-1);
oaMenus[2].menuItem[4] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/incometax.gif">','pages/income.html','',-1);
oaMenus[2].menuItem[5] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/police.gif">','http://www.fremontpd.com','popup',-1);
oaMenus[2].menuItem[6] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/recreation.gif">','#','',9);
oaMenus[2].menuItem[7] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/services.gif">','#','',8);
oaMenus[2].menuItem[8] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/utilities.gif">','#','',7);
oaMenus[2].menuItem[9] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/zoning.gif">','pages/zoning.html','',-1);

oaMenus[10].menuItem[0] = new menuItem('sample1','http://www.google.com','',-1);
oaMenus[10].menuItem[1] = new menuItem('sample2','http://www.sample.com','',-1);

oaMenus[4].menuItem[1] = new menuItem('menu 4 item','http://www.nbc.com','',5);
oaMenus[4].menuItem[0] = new menuItem('sample1','http://www.google.com','',-1);
oaMenus[4].menuItem[2] = new menuItem('sample2','http://www.sample.com','',-1);

oaMenus[5].menuItem[0] = new menuItem('third nest item','http://www.three.com','',-1);
oaMenus[5].menuItem[1] = new menuItem('yahoo - no link','','',-1);
oaMenus[5].menuItem[2] = new menuItem('google - more sites','http://www.google.com','',6);

oaMenus[6].menuItem[0] = new menuItem('sample41','http://www.google.com','',-1);
oaMenus[6].menuItem[1] = new menuItem('sample52','http://www.sample.com','',7);

oaMenus[7].menuItem[0] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/billing.gif">','pages/billing.html','',-1);
oaMenus[7].menuItem[1] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/sewer01.gif">','pages/water.html','',-1);
oaMenus[7].menuItem[2] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/water.gif">','pages/watertreatment.html','',-1);

oaMenus[8].menuItem[0] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/parks.gif">','pages/parks.html','',-1);
oaMenus[8].menuItem[1] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/streets.gif">','pages/streets.html','',-1);
oaMenus[8].menuItem[2] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/sewer.gif">','pages/sewer.html','',-1);

oaMenus[9].menuItem[0] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/reccomplex.gif">','pages/reccomplex.html','',-1);
oaMenus[9].menuItem[1] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/parks.gif">','pages/parks.html','',-1);
oaMenus[9].menuItem[2] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/recprograms.gif">','pages/recprograms.html','',-1);

oaMenus[3].menuItem[0] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/cominfo.gif">','pages/community.html','',-1);
oaMenus[3].menuItem[1] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/driving.gif">','pages/directions.html','',-1);
oaMenus[3].menuItem[2] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/history.gif">','pages/history.html','',-1);
oaMenus[3].menuItem[3] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/visitors.gif">','pages/visitors.html','',-1);
oaMenus[3].menuItem[4] = new menuItem('<img border=0 src="http://www.fremontohio.org/media/weather.gif">','http://www.weather.com/weather/local/43420?GO=GO','popup',-1);








/*
*
* dont change anything from here down
*
*/


// webword checker
usingWebword = true;
try {
  parent.randomID(usingWebword);
} catch (e) {
   usingWebword = false;
}


if (! document.all && ! document.layers) {
   isNetscape = true;
} else {
   isNetscape = false;
}

isMac=(navigator.userAgent.toLowerCase().indexOf("mac")!=-1);



function addMenuItem (i,j) {
   //add menu item 
  if (oaMenus[i].menuItem[j].child < 0) {
      //add line item
      sMenuString+="<div id='_alphaItem" + i + "-" + j + "' CLASS='menuItemOff' onMouseOver='showMenuItem(" + i + ",this)' onMouseOut='hideMenuItem(this)' onMouseDown='callUrl(" + i + "," + j + ")' >" + oaMenus[i].menuItem[j].title + "</div>";
   } else {
      k=oaMenus[i].menuItem[j].child;
      //add new div for line item
      sMenuString+="<DIV id='_alphaItem" + i + "-" + j + "' CLASS='menuItemOff' OnMouseOver='showChildMenu(" + k +"," + i + ",this)' onMouseOut='hideMenuItem(this)' style='position:relative;top:0;left:0;width:"+menuWidth+"px;' >" + oaMenus[i].menuItem[j].title + "</DIV>";
   }
}


function callUrl(i,j) {
   if (oaMenus[i].menuItem[j].windowName.length==0) {
      window.location = oaMenus[i].menuItem[j].url;
   } else {
	   oWindow = window.open(oaMenus[i].menuItem[j].url,oaMenus[i].menuItem[j].windowName);
   }
}


function createMenus() {
   //for initial creation of context menus
   sMenuString = ' ';
   for (var i=0;i<oaMenus.length;i++) {
      if (menuPosition==0) {
         x=0;
         y=0;
         if (oaMenus[i].menuPadId > -1) {
            for(var p=document.getElementById("_alphaPad"+oaMenus[i].menuPadId); p&&p.tagName!='BODY'; p=p.offsetParent){
               x+=p.offsetLeft;
               y+=p.offsetTop;
            }
            x += oaMenus[i].xPos;
            y += oaMenus[i].yPos;
         }
      } else {
         x = oaMenus[i].xPos;
         y = oaMenus[i].yPos;
      }
      sMenuString+="<DIV id='_alphaMenu" + i + "' style='position:absolute;top:" + y + "px;left:" + x + "px;width:"+menuWidth+"px;' CLASS='menuOff'>";
      for (j=0;j<oaMenus[i].menuItem.length;j++) {
         if (oaMenus[i].menuItem[j]!=null) {
            addMenuItem(i,j);
         }
      }
      sMenuString+="</DIV>";
   }
   //add div sets for menu to html area and clear unused vars
   document.write(sMenuString);
   sMenuString = null;
   for (var i=0;i<oaMenus.length;i++) {
      // loop through again and add images to right
      for (j=0;j<oaMenus[i].menuItem.length;j++) {
         oItemStyle = document.getElementById("_alphaItem"+i+"-"+j).style;
         oItemStyle.backgroundRepeat = "no-repeat";
         oItemStyle.backgroundPosition = "right top";
         if (oaMenus[i].menuItem[j].child > -1) {
            oItemStyle.backgroundImage = 'url("'+arrowImage+'")';
         } else {
            oItemStyle.backgroundImage = 'url("'+clearImage+'")';
         }
      }
   }
   oItemStyle = null;
}


function fadeMenu() {
   if (oCurrentMenu==null) {
      return;
   }
   
   sR = Math.floor(startRGB[0] * ((fadeCycles-currentFadeCycle)/fadeCycles) + endRGB[0] * (currentFadeCycle/fadeCycles)).toString(16);
   sG = Math.floor(startRGB[1] * ((fadeCycles-currentFadeCycle)/fadeCycles) + endRGB[1] * (currentFadeCycle/fadeCycles)).toString(16);
   sB = Math.floor(startRGB[2] * ((fadeCycles-currentFadeCycle)/fadeCycles) + endRGB[2] * (currentFadeCycle/fadeCycles)).toString(16);
   if (sR.length == 1) {
      sR = '0'+sR;
   }
   if (sG.length == 1) {
      sG = '0'+sG;
   }
   if (sB.length == 1) {
      sB = '0'+sB;
   }
   oCurrentMenu.style.backgroundColor = "#"+sR+sG+sB;
   if (currentFadeCycle==0) {
      oCurrentMenu .className = "menuOn";
   }
   currentFadeCycle++;
   if (currentFadeCycle<fadeCycles) {
      setTimeout(fadeMenu,fadePause);
   } else {
      oCurrentMenu = null;
   }
}


function hideAllChildMenus (iMenuIdToCheck, iMenuIdToSkip) {
   //hides only the menus that are children of the passed in menu id
   for (var i=0;i<oaMenus[iMenuIdToCheck].menuItem.length;i++) {
      if (oaMenus[iMenuIdToCheck].menuItem[i].child > -1 && oaMenus[iMenuIdToCheck].menuItem[i].child != iMenuIdToSkip) {
         iMenuToHide = oaMenus[iMenuIdToCheck].menuItem[i].child;
         hideMenuNow();
         hideAllChildMenus(iMenuToHide);
      }
   }
}


function hideAllMenus() {
   // hides ALL the menus 
   if (usingWebword) return;

   for (var i=0;i<oaMenus.length;i++) {
      iMenuToHide = i;
      hideMenuNow();
   }
}


function hideMenu (oEvent, iMenuId) {
   // only used if the timer function is used
   if (usingWebword) return;

   if (menuTimer > 0) {
      iMenuToHide = iMenuId;
      setTimeout(hideMenuNow,menuTimer*1000);
   }
}


function hideMenuItem (oMenuItem) {
   oMenuItem.className = "menuItemOff";
}


function hideMenuNow () {
   document.getElementById('_alphaMenu'+iMenuToHide).className = "menuOff";
   if (oaMenus[iMenuToHide].menuPadId > -1) {
      document.getElementById('_alphaPad'+iMenuToHide).className = "menuPadOff";
   }
}


function menu (iMenuPadId, xPos, yPos) {
   // menu class
   this.menuPadId = iMenuPadId;
   this.xPos = xPos;
   this.yPos = yPos;
   this.menuItem = new Array();
}


function menuItem (bTitle, bURL, sWindow, iChildMenu) {
   // menu item class
   this.title = bTitle;
   this.url = bURL;
   this.child = iChildMenu;
   this.windowName = sWindow;
}


function resetMenus() {
   // only used with menuPosition==0
   // after window is resized, this calculates
   // the new x,y offsets for the primary menus
if (usingWebword) return;

   if (menuPosition==1) {
      return;
   }
   for (var i=0;i<oaMenus.length;i++) {
      if (oaMenus[i].menuPadId > -1) {
         x=0;
         y=0;
         for(var p=document.getElementById("_alphaPad"+oaMenus[i].menuPadId); p&&p.tagName!='BODY'; p=p.offsetParent){
            x+=p.offsetLeft;
            y+=p.offsetTop;
         }
         x += oaMenus[i].xPos;
         y += oaMenus[i].yPos;
         document.getElementById("_alphaMenu"+i).style.left = x;
         document.getElementById("_alphaMenu"+i).style.top = y;
      }
   }
}


function showChildMenu (iNextMenuId, iCurrentMenuId, oMenuItem) {
   hideAllChildMenus(iCurrentMenuId,iNextMenuId);
   oMenuItem.className = "menuItemOn";
   x=0;
   y=0;
   for(var p=oMenuItem; p&&p.tagName!='BODY'; p=p.offsetParent){
      x+=p.offsetLeft;
      y+=p.offsetTop;
   }
   x+=parseInt(oMenuItem.style.width) - 3;
   if (x+ menuWidth >document.body.clientWidth){
      x=x-(menuWidth*2);
   }
   showMenu(iNextMenuId,x,y);
   x = null;
   y = null;

}


function showMenu (iMenuId, xpos, ypos) {
   if (usingWebword) return;

   if (oaMenus[iMenuId].menuPadId > -1) {
      for (i=0;i<oaMenus.length;i++) {
         document.getElementById('_alphaMenu'+i).className = "menuOff";
         if (oaMenus[i].menuPadId > -1) {
            document.getElementById('_alphaPad'+i).className = "menuPadOff";
         }
      }
   }
   oCurrentMenu = document.getElementById('_alphaMenu'+iMenuId)
   if (xpos!=null) {
      oCurrentMenu.style.left = xpos;
   }
   if (ypos!=null) {
      oCurrentMenu.style.top = ypos;
   }
   if (oaMenus[iMenuId].menuPadId > -1) {
      document.getElementById('_alphaPad'+oaMenus[iMenuId].menuPadId).className = "menuPadOn"
   }
   if (fadeCycles > 0) {
      currentFadeCycle = 0;
      fadeMenu();
   } else {
      oCurrentMenu .className = "menuOn";
   }
}


function showMenuItem (iCurrentMenuId,oMenuItem) {
   hideAllChildMenus(iCurrentMenuId,-2);
   oMenuItem.className = "menuItemOn";
}


// create the menu system
if (! usingWebword) {
   createMenus();
}

