function hex(d) {return d.toString(16);}
//function h2d(h) {return parseInt(h,16);} 
var isIE6 = false;
var msuppress = false;
var n_menu = 8; // Number of menus (plus choice 0: home not used at the moment)
var n_opt_arr = [0,13,0,6,5,5,0,9,5]; // Number of options on each menu
//NOTE: don't do drop-down for myaccount because options depend on type of user and whether logged in 
var skip_arr = [0,0,1,0,0,0,0,0,0]; // Skip menu (allows provisional removal of menus without shifting all others up)
var n_opt_arr2_exists = [0,0,0,0,0,0,0,1,1];
var n_opt_arr2 = new Array;
// still zero-based even if 0 not used
n_opt_arr2[7] = [0,0,4,0,0,3,0,3,3,3]; 
n_opt_arr2[8] = [0,4,0,4,5,0,0]; 
var includetop = true; //whether to show top level in drop down

toptarg_arr = new Array("/index.asp", "http://twitter.com/autoebid", "/buy-new-cars.asp", "/messages/buy.asp?vehPref=Both", "/messages/sell-my-car.htm", "/messages/Contract-Hire-Lease-Purchase-PCP.htm", "/messages/Contract-Hire-Lease-Purchase-PCP.htm", "/about-autoebid.asp", "/about-autoebid.asp", "/research.asp");
var starg_arr  = new Array; 
var starg_arr2 = new Array;
starg_arr[1] = new Array("/autoenews/newsAEB.asp", "/blog", "/new-car-reviews.asp", "/carasp/bidding-examples.asp", "/help-me-choose.asp", "/green-hybrid-cars.asp", "/messages/currentDeals.asp", "/stock-cars.asp", "/new-models.asp", "/carCompareLanding.asp","/used-cars.asp","/Newsletter.asp","/messages/Fleet-Company-Cars.php");
//starg_arr[2] = new Array("/vanSearch.asp", "/carasp/van-examples.asp");
starg_arr[3] = new Array("/carasp/acarpost2.asp", "/carasp/acarpost4.asp", "/carasp/acarpost5.asp", "/carasp/acarpost6.asp", "/carasp/acarpost6.asp","/used-cars.asp");
starg_arr[4] = new Array("/carasp/free-used-car-valuation.asp", "/sell-my-car-ads.htm", "/sell-my-car-now.htm", "/sell-my-car-used-car-auction.asp", "/messages/seller-guide2.asp");
starg_arr[5] = new Array("/pcp-quote.asp", "/hire-purchase-uk.htm","/Contract-Hire-Lease-Purchase.asp","/contract-hire-lease-purchase-deals.asp","/car-manufacturers-special-finance-offers.htm","/car-manufacturers-special-finance-offers.htm");
starg_arr[7] = new Array("/messages/contact-us.php","/buyers-guide.asp","/carasp/inqSelectMain.asp","/messages/customer-feedback.php","/messages/secure-payment-escrow-account-uk.htm","/reverse-auctions.asp","/news.htm", "/policy.asp", "/join.asp");
starg_arr2[7] = new Array;
starg_arr2[7][2] = new Array("/flash-demo.asp","/doc-downloads.asp","/buying-detail.asp","/messages/fees.php");
starg_arr2[7][5] = new Array("/new-car-supermarket-broker-dealer.asp","/messages/seller-guide.asp","/messages/AutoeBid-UK-Suppliers-Terms-and-Conditions.htm");
starg_arr2[7][7] = new Array("/news1.htm","/news2.htm","/news3.htm");
starg_arr2[7][8] = new Array("/messages/AutoeBid-UK-Buyer-Terms-and-Conditions.htm","/privacy.asp","/tech.asp");
starg_arr2[7][9] = new Array("/AutoeBid-UK-Affiliate-program.asp","/messages/AutoeBid-UK-Affiliate-contract.htm","/job-vacancy.asp");
starg_arr[8] = new Array("/personal-loans-uk.htm","/how-to-buy-a-car.asp","/autoenews/car-dealer-directory.php","/services.asp","/used-cars.asp")
starg_arr2[8] = new Array;
starg_arr2[8][1] = new Array("/mortgages.asp","/credit-cards.asp","/banking-current-accounts.asp","/Individual-Voluntary-Arrangement-iva.asp");
starg_arr2[8][3] = new Array("/Ireland-new-car-sales.asp","/voitureneuveFrance.asp","/international-dealer-directory.asp","/European-Car-Imports-UK.asp");
starg_arr2[8][4] = new Array("/cheap-car-insurance-directory.htm","/used-cars-directory.htm","/cheap-car-hire-directory.htm","/car-loans-directory.htm","/breakdown-cover-directory.htm");

toptext_arr = new Array("","Twitter","","Specs & Pricing","Sell my Car","Finance Types","Overview","About Us","","Summary","Highlights");
var stext_arr  = new Array; 
var stext_arr2  = new Array;
stext_arr[1] = new Array("Motoring News", "Motoring Blog", "New Car Reviews", "Examples", "Help Me Choose", "Green Cars", "Hot Deals", "Stock Cars", "New Models","Compare Cars","Used Cars","Newsletter","Fleet Sales");
//stext_arr[2] = new Array("Specs & Pricing", "Examples");
stext_arr[3] = new Array("Choose Vehicle", "Select Options", "Set Conditions", "Review/Register", "Order","Used Cars");
stext_arr[4] = new Array("Car Valuation","Car Adverts","Selling to Trade","Used Car Auctions","Car Dealers");
stext_arr[5] = new Array("PCP Finance", "Hire Purchase", "Contract Hire", "Finance Deals","Retail Offers");
stext_arr[7] = new Array("Contact Us","How We Work","Help & FAQs","Our Customers","Our Suppliers","Reverse Auctions","In the News","Company Policy","Join Us");
stext_arr2[7] = new Array;
stext_arr2[7][2] = new Array("Flash Demo","Downloads","Buying a car","Our charges");
stext_arr2[7][5] = new Array("Dealers","Selling Cars");
stext_arr2[7][7] = new Array("Awards","Articles","Press Releases");
stext_arr2[7][8] = new Array("T&Cs","Privacy","Technical");
stext_arr2[7][9] = new Array("Affiliates","Affiliate T&Cs","Employment");
stext_arr[8] = new Array("Personal Finance","How to Buy a Car","Dealer Directory","Insurance","Used Cars")
stext_arr2[8] = new Array;
stext_arr2[8][1] = new Array("Mortgages","Credit Cards","Banking","IVAs");
stext_arr2[8][3] = new Array("Ireland","France","International","Imports");
stext_arr2[8][4] = new Array("Car Insurance","Used Car Vendors","Car Hire","Car Loans","Breakdown Cover");

var id_show, id_show2; //currently showing pop-up
var if_show; // iframe shim for IE6
var i_curr_option2, i_curr_option, i_curr_menu, curr_id, curr_id2;
i_curr_option = 0;
id_show = "";

function domenu(i_menu, i_option) {
//used to build all the DOM elements for the menu but some is now done in HTML for SEO reasons if nothing else
for (var i = 0; i <=n_menu; i++) {
  if (!skip_arr[i]) {
    am = document.getElementById("amenu"+hex(i)+"0");
    am.onmouseover = aover1;
    am.onmouseout = aout1;
  
    if (n_opt_arr[i] > 0) {
      ds = document.createElement('div');
      ds.id = "submenu"+hex(i);
      ds1 = document.createElement('div');
      
      if (includetop) {
        as = document.createElement('a');
        as.id = "amenu"+hex(i)+"0";
        as.href = toptarg_arr[i];
        as.onmouseover = aover1;
        as.onmouseout = aout1;
        as.appendChild(document.createTextNode(toptext_arr[i]));
        ds1.appendChild(as);
  	     ds1.appendChild(document.createElement('br'));
      }
      for (var j = 1; j <=n_opt_arr[i]; j++) {
        as = document.createElement('a');
        as.id = "amenu"+hex(i)+hex(j);
        as.href = starg_arr[i][j-1];
        as.onmouseover = aover1;
        as.onmouseout = aout1;
        as.appendChild(document.createTextNode(stext_arr[i][j-1]));
        ds1.appendChild(as);
  	     ds1.appendChild(document.createElement('br'));
      }  
    	 ds1.className = "inline1";
    	 ds.appendChild(ds1);
      ds.className = "submenu";
      dm1 = document.getElementById("menu"+hex(i));
      dm1.appendChild(ds);
  // create shim to hide select for IE6
      if (isIE6) {
        ifshim = document.createElement('iframe');
        ifshim.src = "javascript:'';" 
        ifshim.id = "ifshim"+hex(i);
        ifshim.frameBorder = 0;
        ifshim.style.position = "absolute";
        ifshim.style.visibility = "hidden";
        ifshim.style.zIndex = "0";
        ifshim.style.top = "24px";
        ifshim.style.left = "-9px";
        ifshim.style.width = "134px";
        ifshim.style.height = (n_opt_arr[i]*22+22)+"px";
        dm1.appendChild(ifshim);
      }
    }
  }
}
}
function domenu2(i_menu, i_option) {
for (var i = 1; i <=n_opt_arr[i_menu]; i++) {
  am = document.getElementById("asmenu"+hex(i_menu)+hex(i));
   am.onmouseover = aover2;
   am.onmouseout = aout2;
  
   if (n_opt_arr2[i_menu][i] > 0) {
     if (i != i_option) {
       //change position
       tid = "tmenu"+hex(i_menu)+hex(i);
       tstyle = document.getElementById(tid).style;
       tstyle.position= "absolute"; 
       tstyle.top = "10px"; 
       tstyle.left = "118px"; 
       tstyle.display = "block"; 
       tstyle.visibility = "hidden"; 
     }
   }
  }
 }

function init_menu2(i_menu, i_option, i_option2) {

// check for IE6 (for shim...)
iMSIE = navigator.appVersion.indexOf('MSIE');
if (iMSIE > 0) {
  iVer = navigator.appVersion.substring(iMSIE + 5);
  if (parseFloat(iVer) < 7) {
    isIE6 = true;
  }
}
stmenu = document.getElementById("tmenu"+hex(i_menu)+hex(i_option)).style;
stmenu.display = "block";
if (i_option2 == 0) {
  init_menu(i_menu, i_option);
  // should click on self do anything
  //document.getElementById("asmenu"+hex(i_menu)+hex(i_option)).href = "#"
  curr_id2 = 'smenu' + hex(i_menu)+hex(i_option)
} else { 
  domenu(i_menu, i_option);
  hlight2 (i_menu, i_option, i_option2);
}
}

function hlight2 (i_menu, i_option, i_option2) {

curr_id = 'amenu' + hex(i_menu) + '0';
curr_id2 = 'smenu' + hex(i_menu) + hex(i_option);
document.getElementById("menu"+hex(i_menu)).className = "menuitem menu0s";
tcurr_id = 'atmenu' + hex(i_menu) + hex(i_option) + hex(i_option2);
document.getElementById(tcurr_id).href = "#";
stcurr_id = 'stmenu' + hex(i_menu) + hex(i_option) + hex(i_option2);
document.getElementById(stcurr_id).className = "current";

i_curr_option2 = i_option2;
i_curr_option = i_option;
i_curr_menu = i_menu;

}
  
function init_menu(i_menu, i_option) {

// check for IE6 (for shim...)
iMSIE = navigator.appVersion.indexOf('MSIE');
if (iMSIE > 0) {
  iVer = navigator.appVersion.substring(iMSIE + 5);
  if (parseFloat(iVer) < 7) {
    isIE6 = true;
  }
}
//set up the menus appropriate to this page
domenu(i_menu, i_option);
if (n_opt_arr2_exists[i_menu] == 1) {
  domenu2(i_menu, i_option);
}
hlight (i_menu, i_option); 
}

function hlight(i_menu, i_option) {
// highlight current page selected
  curr_id = 'amenu' + hex(i_menu) + '0';
  curr_id2 = "";
  document.getElementById("menu"+hex(i_menu)).className = "menuitem menu0s";
  i_curr_option = i_option;
  i_curr_menu = i_menu;

  if (i_option>0 || (includetop && i_menu > 0)) {
    scurr_id = 'asmenu' + hex(i_menu) + hex(i_option);
    document.getElementById("smenu"+hex(i_menu) + hex(i_option)).className = "sidemenu2";
    //document.getElementById(scurr_id).href = "#";
  } else {
  //document.getElementById(curr_id).href = "#"
  }
}

function aover2() {
aid = this.id;
i_menu = parseInt(aid.charAt(6),16);
i_option = parseInt(aid.charAt(7),16);
if (this.id != id_show) {ahide()}
if (aid != "a"+curr_id2) {
  ashow2(i_menu,i_option);
}
}

function ashow2(i_menu,i_option) {
if (n_opt_arr2[i_menu][i_option]>0) {
  menu = "tmenu" + hex(i_menu) + hex(i_option);
  if (msuppress == false ) document.getElementById(menu).style.visibility = "visible";
  id_show = menu;
  if_show = "";
  }
}

function aout2(){
}

function aover1() {

aid = this.id;
i_menu = parseInt(aid.charAt(5),16);

if (this.id != id_show) {ahide()}
if (this.id != curr_id) {
  ashow(i_menu);
  }
}

function ashow(i_menu) {
if (n_opt_arr[i_menu]>0) {
  menu = ('submenu' + hex(i_menu));
  id_show = menu;
  if (msuppress == false ) document.getElementById(menu).style.visibility = "visible";
  if (isIE6) {
    ifshim = 'ifshim' + hex(i_menu);
    if_show = ifshim;
    if (msuppress == false ) document.getElementById(ifshim).style.visibility = "visible";
  }
}
}

function ahide() {
// put away popup menu
if (id_show != "") {
  document.getElementById(id_show).style.visibility = "hidden";
  id_show = "";
  if (isIE6 && if_show != "") {
    document.getElementById(if_show).style.visibility = "hidden";
    if_show = "";
  }
}
}
function aout1(){
}
function stopmenu() {
msuppress = true;
 }
function startmenu() {
msuppress = false;
 }
 
/*  when a results table is hovered over change the background color 
nothing to do with the menu, put it here as this js file is included in most pages */

function changeRowColor(row){
  row.className='gray_background';
  flipImage(row, '/images/nxg-orange1.gif');
}

function changeRowColorBack(row){
  row.className='white_background';
  flipImage(row, '/images/nxg1.gif');
}

function flipImage(row, newImage)
{
  //td6 = row.childNodes[6];  //td 6
  td6 = row.lastChild
 	link6 = td6.childNodes[0]; // link within td
 	img6 = link6.childNodes[0]; // img within link
 	img6.src = newImage;
}


