// written by Tan Ling Wee
// last updated 9 October 2003
// email : fuushikaden@yahoo.com

//modified by Martin Venter 9 October
//    - Added MenuFontColor property
//    - Previously I added support to overlay ie objects like <select> and <objects> with the OverlayIEObjects and 
//      HideIEObjects properties. This only works in IE5.5 and up so I have changed the code to detect the browser
//      properly and then determine whether to overlay ie objects or to hide them. Credit to Bard who picked up this
//      problem in the calendar.
//    - Added target property. Reserved words can also be used. (_blank, _top, _parent, _self)
//      If the target is not passed then "_self" is assumed.
//modified by Martin Venter 14 September
//    - Added Opera detection code.
//    - Added HideIEObjects property to enable or disable the code execution of 
//      hiding/showing IE objects. It will also hide\show <OBJECTS> like flash objects.
//    - Added OverlayIEObjects property. If set true and its an IE browser some extra logic is added so that 
//      the calendar will show above IE objects. I cant take all the credit for this, I got the idea from 
//      this url - http://dotnetjunkies.com/weblog/jking/posts/488.aspx and implemented it.
//    - Added addIFrame(), showIFrame() and hideIFrame() functions. Used to implement the OverlayIEObjects
//      property.
//    - Added missing semi-colons so that one can run the script through a code chruncher.
//    - Fixed image tag in the DrawMenu() function.
//    - The menuFont property was not implemented anywhere in the code. This has been fixed.
//    - Added menuFontSize property.
//    - menuSize property is not implemented anywhere. I'm not going to implement it at this stage. 
//email: martin@unirnd.co.za

var orientation=0; // 0-horizontal 1-vertical
var imgPath = "js/";

var mainItemForeground = "#536579";
var mainItemBorder = "#f0f0f0";
var mainItemBackground = "#536579";

var mainItemHoverForeground = "#000000";
var mainItemHoverBorder = "#a0a0a0";
var mainItemHoverBackground = "#d0d0d0";

var subItemForeground = "#536579";
var subItemBorder = "#ffffff";
var subItemBackground = "#536579";

var subItemHoverForeground = "#000000";
var subItemHoverBorder = "#a0a0a0";
var subItemHoverBackground = "#d0d0d0";

var menuFont = "Verdana";
var menuFontSize = "10px";
var menuFontColor = "#ffffff";
var menuSize = "10px";

/////////////////////////////////////////////////////////////////////////////

var ie=(navigator.appName=='Microsoft Internet Explorer');
var ns=(navigator.appName=='Netscape');
var dom=document.getElementById;
var opera = (navigator.userAgent.indexOf("Opera")!=-1)?true:false;

var appVer = navigator.appVersion.toLowerCase();
var is_minor;
var is_major;
var iePos  = appVer.indexOf('msie');
 if (iePos !=-1) {
   is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
   is_major = parseInt(is_minor);
 }
var is_ie   = ((iePos!=-1) && (!opera));
var is_ie5_5up =(is_ie && is_minor >= 5.5);

var lw_menuId, lw_trigger, to1;
var s1;

/////////////////////////////////////////////////////////////////////////////

function Tmenu (id, parentId, url, description, img, target) {
this.id = id;
this.parentId = parentId;
this.url = url;
this.description = description;
this.numChild = 0;
this.levelId = 0;
this.img = img;
this.target = target;
}

/////////////////////////////////////////////////////////////////////////////

var menu = new Array();
var menuCounter = 0;
var numLevel = 0;
var prevMenuId = -1;
var nNowAt = 0;

function displayMenuItem(menuId) {
var sHTML;

 if (menu[menuId].parentId>0){
  ItemForeground = subItemForeground;
  Border = subItemBorder;
  Background = subItemBackground;
 
  HoverForeground = subItemHoverForeground;
  HoverBorder = subItemHoverBorder;
  HoverBackground = subItemHoverBackground;
 }else{
  ItemForeground = mainItemForeground;
  Border = mainItemBorder;
  Background = mainItemBackground;
 
  HoverForeground = mainItemHoverForeground;
  HoverBorder = mainItemHoverBorder;
  HoverBackground = mainItemHoverBackground;
 }
 
 if ((orientation==1)||(menu[menuId].levelId>0)){
   sHTML += "<tr>";
 } 
 
 if (menu[menuId].description!='-'){
   sHTML = "<td id='menu_"+menuId+"' style='cursor:pointer;cursor:hand;border-style:solid;border-width:1px;background-color:"+ Background +";color:\""+ ItemForeground +"\";border-color:"+ Border +"' onmouseover='clearInterval(s1);this.style.backgroundColor=\"" + HoverBackground + "\";this.style.color=\"" + HoverForeground + "\";this.style.borderColor=\"" + HoverBorder + "\";";
 
   if (menu[menuId].numChild!=0) {
     sHTML += "showSubmenu("+menu[menuId].id+",this);hideSubmenu(menu["+menuId+"].levelId+1);";
   }else{
     sHTML += "prevMenuId = "+menuId+";hideSubmenu(menu["+menuId+"].levelId);";
   }

   sHTML += ";nNowAt="+menuId+";clearAll("+menu[menuId].levelId+","+menu[menuId].parentId+")' ";
   //sHTML += "onclick='document.location.href=\""+menu[menuId].url+"\";' ";
   if ((menu[menuId].target == undefined) || (menu[menuId].target == "")){
     menu[menuId].target = "_self";
   }
   // Open link in current document
   if (menu[menuId].target=="_self"){
     sHTML += "onclick='document.location=\""+menu[menuId].url+"\";' ";
   }
   else if (menu[menuId].target=="_top"){
     sHTML += "onclick='top.location=\""+menu[menuId].url+"\";' ";
   }
   //Open link in new window
   else if (menu[menuId].target=="_blank"){
     sHTML += "onclick='window.open(\""+menu[menuId].url+"\");' ";
   }
   // Open link in parent frame
   else if (menu[menuId].target=="_parent"){
     sHTML += "onclick='parent.location=\""+menu[menuId].url+"\";' ";
   }
   // Open link in the specified frame
   else{
     sHTML += "onclick='parent.frames[\""+menu[menuId].target+"\"].location=\""+menu[menuId].url+"\";' ";
   } 
   sHTML += "onmouseout='s1=setInterval(\"resetMenu();hideSubmenu(0)\",1000);'><table cellpadding=0 cellspacing=0 border=0 width='100%'><tr>";

   if (menu[menuId].levelId>0)
   {
     sHTML += "<td style='padding-left:3px' width=20><img src='";
     if (menu[menuId].img==""){
       sHTML += imgPath + "trans.gif";
     }else{
       sHTML += imgPath + menu[menuId].img;
     }
     sHTML += "' width=16 height=16 border=0></td>";
   }

   if ((orientation==0) && (menu[menuId].levelId==0)){
     nArrowWidth = 0;
   }else{
     nArrowWidth = 25;
   }

   //sHTML += "<td nowrap style='padding-left:5px;padding-right:5px;font-family:" + menuFont + ";font-size:" + menuFontSize + ";' align=left>" + menu[menuId].description.replace(" ","&nbsp;") + "</td><td style='padding-right:2px' align=right width="+nArrowWidth+">";
   sHTML += "<td nowrap style='padding-left:5px;padding-right:5px;font-family:" + menuFont + ";font-size:" + menuFontSize + ";color:" + menuFontColor + ";' align=left>" + menu[menuId].description.replace(" ","&nbsp;") + "</td><td style='padding-right:2px' align=right width="+nArrowWidth+">";
   if (menu[menuId].numChild>0){
     if ((orientation==0)&&(menu[menuId].levelId==0)){
       sHTML += "<img src='" + imgPath + "arrow_down.gif'>";
     }else{
       sHTML += "<img src='" + imgPath + "arrow_right.gif'>";
     }
   }else{
     sHTML += "&nbsp;";
   }
   sHTML += "</td></tr></table></td>";
 }else{
   sHTML = "<td><img src='" + imgPath + "trans.gif' height=2></td></tr><tr><td onmouseover='' bgcolor='#d0d0d0'><img src='" + imgPath + "trans.gif' height=1></td></tr><tr><td><img src='" + imgPath + "trans.gif' height=2></td>";
 }

 if ((orientation==1)||(menu[menuId].levelId>0)){
   sHTML += "</tr>";
 } 
 return sHTML;
}

function clearAll(levelId, parentId) {
 if (levelId>0){
   Border = subItemBorder;
   Background = subItemBackground;
 }else{
   Border = mainItemBorder;
   Background = mainItemBackground;
 }

 for (i=0;i<menuCounter;i++){
   if (menu[i].levelId==levelId){
     if ((i!=nNowAt) && (menu[i].parentId==parentId) && (menu[i].description!="-")) {
       lw_getObj("menu_"+i).backgroundColor=Background;
       lw_getObj("menu_"+i).borderColor=Border;
     }
   }
 }
}

function mapID (id) {
 for (var i=0;i<menuCounter;i++){
   if (menu[i].id==id){
     return i;
   }
 }
 return -1;
}

function showSubmenu(menuId,trigger) {
lw_menuId = menuId;
lw_trigger = trigger;

 if (ns){
   to1 = setTimeout("showActualSubmenu(lw_menuId,lw_trigger)",50);
 }else{
   showActualSubmenu(lw_menuId,lw_trigger);
 }
}

function showActualSubmenu(menuId,trigger) {
var nLevel = 0;
var leftpos = 0;
var nIndex=0;

 if (menuId>0){
   lw_calcpos(trigger);

   for (var i=0;i<menuCounter;i++){
     if (menu[i].id==menuId){ 
       nLevel = menu[i].levelId;
       nIndex = i;
     }
   }

   if ((orientation==1)||(menu[nIndex].parentId>0)){
     lw_getObj("menu_level_"+nLevel).top=lw_toppos;
     leftpos = lw_leftpos + lw_width + 5;

     if (nLevel==0) {
       leftpos -= 3;
     }
   }else{
     lw_getObj("menu_level_"+nLevel).top = lw_toppos + lw_height + 2;
     leftpos = lw_leftpos;
   }

   lw_getObj("menu_level_"+nLevel).left=leftpos;

   sHTML = "<table cellpadding=0 cellspacing=0 border=0>";
   for (var i=0;i<menuCounter;i++){
     if (menu[i].parentId==menuId){
       sHTML += displayMenuItem (i);
     }
   }
   sHTML += "</table>";

   document.getElementById("menu_level_"+nLevel+"_content").innerHTML=sHTML;
   lw_showLayer('menu_level_'+nLevel);
 } 
}

function hideSubmenu(levelId) {
 for (var cnt=levelId; cnt<numLevel; cnt++){
   lw_hideLayerName("menu_level_"+cnt);
 }
}

function DrawMenu ()  {
var sHTML = "";
 for (var i=0; i<numLevel; i++){
 lw_createLayer("menu_level_"+i,0,0,0,0,"#ffffff","#d0d0d0",100);
 }

 sHTML='<div id=\"fwwMenuBar\" style=\"background-color:' + mainItemBackground + ';\" onselectstart="return false;">';
 sHTML+="<table cellpadding=0 cellspacing=0>";
 for (var i=0; i<menuCounter; i++){
   if (menu[i].parentId==0){  
     sHTML += displayMenuItem (i);
   }
   else if (menu[i].parentId==-1){  
     sHTML += "<tr><td><img src='" + imgPath + "trans.gif' height=2></td></tr><tr bgcolor='"+mainItemBackground+"'><td style='padding:5px'><b>" + menu[i].description + "</b></td></tr>";
   }
 }
 sHTML += "</table>";
 sHTML += "</div>";
 document.writeln(sHTML);
}

function getLevel (menuId) {
var pId=menuId;
var nLevel=0;

 while (pId!=0){
   nLevel++;
   for (var i=0;i<menuCounter;i++){
     if (menu[i].id==pId){ 
       pId = menu[i].parentId;
     }
   }
 }
 return nLevel;
}

function AddMenuItem (id, parentId, url, description, img, target){

menu[menuCounter++] = new Tmenu (id, parentId, url, description, img, target);

 if (parentId>0){
   for (i=0;i<menuCounter;i++){
     if (menu[i].id==parentId){
       menu[i].numChild++;
     }
   }
   menu[menuCounter-1].levelId = getLevel(parentId);

   if ( numLevel < menu[menuCounter-1].levelId){ 
     numLevel = menu[menuCounter-1].levelId;
   }
 }
 else if (parentId==0){
   menu[menuCounter-1].levelId = 0;
 }else{
   menu[menuCounter-1].levelId = -1;
 }
}

function handleonclick() {
 if (ns){
   lw_closeAllLayers();
 }else{
   lw_closeAllLayers(event);
 }
 resetMenu();
}

function handlekeypress(e) {
 if (ns){
   var keyCode = e.keyCode?e.keyCode:e.which?e.which:e.charCode;
   if ((keyCode==27)||(keyCode==1)){
     handleonclick();
   }
 }
 else
   if ((event.keyCode==0)||(event.keyCode==27)){
     handleonclick();
   }
 resetMenu();
}

function resetMenu () {
 for (i=0;i<menuCounter;i++){
   if (menu[i].levelId==0){
     lw_getObj("menu_"+i).backgroundColor=mainItemBackground;
     lw_getObj("menu_"+i).borderColor=mainItemBorder;
   }
 }
}

document.onkeypress = handlekeypress;
document.onclick = handleonclick;

AddMenuItem (1, 0, "", "Browse Our GWR Catalog", "") 
//  Remove Jowissa watches from the menu, shift other menus over
//  AddMenuItem (2, 0, "jwwatches.php", "Browse Our Jowissa Watches","")
AddMenuItem (2, 0, "", "Jewellery Collection (Coming Soon!)", "") 
AddMenuItem (11, 1, "", "Browse By Category", "")
AddMenuItem (12, 1, "", "Browse By Brand", "")
AddMenuItem (13, 1, "", "Browse By Price", "")
AddMenuItem (21, 11, "automatic.php", "Automatic", "")
AddMenuItem (22, 11, "manual.php", "Manual Wind", "")
AddMenuItem (23, 11, "quartz.php", "Quartz", "")
AddMenuItem (24, 11, "chronograph.php", "Chronograph", "")
AddMenuItem (25, 11, "pocket.php", "Pocket Watches", "")
AddMenuItem (26, 11, "ssband.php", "Stainless Steel Band", "")
AddMenuItem (27, 11, "goldband.php", "Gold Band", "")
AddMenuItem (28, 11, "twotoneband.php", "Two-Tone Band", "")
AddMenuItem (29, 11, "titanium.php", "Titanium", "")
AddMenuItem (30, 11, "leather.php", "Leather Strap", "")
AddMenuItem (31, 11, "h2oresist.php", "Water-Resistant", "")
AddMenuItem (32, 11, "diasgems.php", "Diamonds or Gems", "")
AddMenuItem (41, 12, "jjwatches.php", "Jules Jurgensen Watches", "")
AddMenuItem (42, 12, "preowned.php", "Pre-Owned Watches", "")
AddMenuItem (43, 12, "custom.php", "Custom-Made Watches", "")
AddMenuItem (51, 13, "wunder150.php", "Gifts Under $150", "")
AddMenuItem (52, 13, "w150to250.php", "Gifts $150 to $250", "")
AddMenuItem (53, 13, "w250to500.php", "Gifts $250 to $500", "")
AddMenuItem (54, 13, "w500up.php", "Gifts $500 & up", "")
AddMenuItem (61, 41, "jjmens.php", "Men's", "")
AddMenuItem (62, 41, "jjwomens.php", "Women's", "")
AddMenuItem (63, 41, "jjssbands.php", "Stainless Steel Bands", "")
AddMenuItem (64, 41, "jjgoldbands.php", "Gold Bands", "")
AddMenuItem (65, 41, "jjleatherbands.php", "Leather Straps", "")
/*AddMenuItem (71, 2, "stuller.php", "Stuller Jewelry Collection", "")
AddMenuItem (81, 71, "stulwomens.php", "Women's Fashion", "")
AddMenuItem (82, 71, "stulmens.php", "Men's Fashion", "")
AddMenuItem (83, 71, "", "Browse By Price", "")
AddMenuItem (91, 83, "j100under.php", "Gifts Under $100", "")
AddMenuItem (92, 83, "j100to250.php", "Gifts $100 to $250", "")
AddMenuItem (93, 83, "j250to500.php", "Gifts $250 to $500", "")
AddMenuItem (94, 83, "j500up.php", "Gifts $500 & up", "")
AddMenuItem (101, 27, "goldfilled.php", "Gold-Filled", "")
AddMenuItem (102, 27, "14Kgold.php", "14K Gold", "")
AddMenuItem (103, 27, "18Kgold.php", "18K Gold", "")
AddMenuItem (111, 81, "wrings.php", "Wedding/Anniversary Rings", "")
AddMenuItem (112, 81, "wearrings.php", "Earrings", "")
AddMenuItem (113, 81, "wpendants.php", "Necklaces & Pendants", "")
AddMenuItem (114, 81, "wbracelets.php", "Bracelets", "")*/
//  AddMenuItem (21, 2, "jwmens.php", "Men's", "") 
//  AddMenuItem (22, 2, "jwwomens.php", "Women's", "") 
//  AddMenuItem (22, 2, "jwssbands.php", "Stainless Steel Bands", "") 
//  AddMenuItem (23, 2, "jwleatherbands.php", "Leather Straps", "") 

