// preLoad images
var buttonImgs = new Array;
var buttonAlwaysOn = "";
var sideMenuAlwaysOn = 0;

var buttonOnId = null;
var buttonOffId = null;
var buttonOffTimerId = null;

function buttonImgObj(onImg, offImg) {
  this.onImg = onImg;
  this.offImg = offImg;
}

// Photo Gallery + and - images
/*
ImagePlus      = new Image();
ImagePlus.src  = "/images/faq_plus.gif";
ImageMinus     = new Image();
ImageMinus.src = "/images/faq_minus.gif";
*/


buttonImgs['PnS'] = new buttonImgObj(new Image(149,21), new Image(149,21));
buttonImgs['DC'] = new buttonImgObj(new Image(111,21), new Image(111,21));
buttonImgs['Net'] = new buttonImgObj(new Image(85,21), new Image(85,21));
buttonImgs['Cust'] = new buttonImgObj(new Image(94,21), new Image(94,21));
buttonImgs['AU'] = new buttonImgObj(new Image(84,21), new Image(84,21));
buttonImgs['NnE'] = new buttonImgObj(new Image(116,21), new Image(116,21));
buttonImgs['CU'] = new buttonImgObj(new Image(98,21), new Image(98,21));

buttonImgs['PnS'].onImg.src = "/images/nav_products_b.gif";
buttonImgs['DC'].onImg.src = "/images/nav_datacenters_b.gif";
buttonImgs['Net'].onImg.src = "/images/nav_network_b.gif";
buttonImgs['Cust'].onImg.src = "/images/nav_customers_b.gif";
buttonImgs['AU'].onImg.src = "/images/nav_about_b.gif";
buttonImgs['NnE'].onImg.src = "/images/nav_news_b.gif";
buttonImgs['CU'].onImg.src = "/images/nav_contact_b.gif";

buttonImgs['PnS'].offImg.src = "/images/nav_products_a.gif";
buttonImgs['DC'].offImg.src = "/images/nav_datacenters_a.gif";
buttonImgs['Net'].offImg.src = "/images/nav_network_a.gif";
buttonImgs['Cust'].offImg.src = "/images/nav_customers_a.gif";
buttonImgs['AU'].offImg.src = "/images/nav_about_a.gif";
buttonImgs['NnE'].offImg.src = "/images/nav_news_a.gif";
buttonImgs['CU'].offImg.src = "/images/nav_contact_a.gif";

function initButtons() {
  if ( buttonAlwaysOn == "" ) {
    buttonOff('PnS');
    buttonOff('DC');
    buttonOff('Net');
    buttonOff('Cust');
    buttonOff('AU');
    buttonOff('NnE');
    buttonOff('CU');
  } else {
    buttonOn( buttonAlwaysOn );
  }
}

function buttonOn( buttonId ) {
  if (buttonOffTimerId != null && buttonOffId != null) {
    if (buttonOffId == buttonId) {
      clearTimeout( buttonOffTimerId );
    } else {
      buttonTurnOff( buttonOffId );
      buttonOffId = null;
    }
  }

  if (buttonOnId == buttonId) return;

  var targetId = "button" + buttonId + "";
  var target = document.getElementById( targetId );
  target.src = buttonImgs[buttonId].onImg.src;
  buttonOnId = buttonId;
}

function buttonOff( buttonId ) {
  if (buttonOffTimerId != null && buttonOffId != null) {
    if (buttonOffId == buttonId) {
      clearTimeout( buttonOffTimerId );
    } else {
      buttonTurnOff( buttonOffId );
      buttonOffId = null;
    }
  }

  if (buttonId == buttonAlwaysOn) return;
  buttonOffId = buttonId;
  buttonOffTimerId = setTimeout("buttonTurnOff( buttonOffId )", 30);
}

function buttonTurnOff( buttonId ) {
  if (buttonId == null) return;
  if (buttonOffTimerId != null) clearTimeout(buttonOffTimerId);
  if (buttonId == buttonAlwaysOn) return;

  var targetId = "button" + buttonId;
  var target = document.getElementById( targetId );
  target.src = buttonImgs[buttonId].offImg.src;

  if (buttonOnId == buttonId) buttonOnId = null;
}

function mainPopOn( mainId ) {
  var targetId = "menu" + mainId + "";
  var target = document.getElementById( targetId );
  target.style.visibility = "visible";  
}

function mainPopOff( mainId ) {
  var targetId = "menu" + mainId + "";
  var target = document.getElementById( targetId );
  target.style.visibility = "hidden";  
}

function mainOff( item ) {
  item.style.background = "none";
}

function mainOn( item ) {
  item.style.background = "#9e2d1f";
}


function menuLayerOn( mainId, menuNum ){
  var targetId = "menu" + menuNum + "";
  target = document.getElementById( targetId );
  target.style.visibility = "visible";  
  mainPopOn( mainId );
  mainOn( menuNum );
}

function menuLayerOff( mainId, menuNum ){
  var targetId = "menu" + menuNum + "";
  var target = document.getElementById( targetId );
  target.style.visibility = "hidden";   
  mainOff( menuNum );
  mainPopOff( mainId );
}

function allMenuLayersOff ( menuNum ) {
  var targetId = "menu" + menuNum + "";
  var target = document.getElementById( targetId );
  var targetParent = target.parentNode;
  var list = targetParent.childNodes;
  for (var i = 0; i < list.length; i++) {
    list[i].style.visibility = "hidden";
  }
}

function menuOn( menuNum, itemNum ) {
  var targetId = "menu" + menuNum + "Item" + itemNum + "";
  target = document.getElementById( targetId );
  target.style.background = "#9e2d1f";
}

function menuOff( menuNum, itemNum ) {
  var targetId = "menu" + menuNum + "Item" + itemNum + "";
  target = document.getElementById( targetId );
  if (target.className == "menuItem") {
    target.style.background = "#707070";
  }
  else if (target.className == "menuCat") {
    target.style.background = "#4f4f4f";
  }
  // otherwise do nothing
}

function sideMenuOn ( menuNum ) {
  if (menuNum == 0) {
    return;
  }
  var targetId = "sideCell" + menuNum + "";
  target = document.getElementById( targetId );
  target.style.background = "#9e2d1f";
}

function sideMenuOff ( menuNum ) {
  if (menuNum == 0) {
    return;
  }
  if (menuNum == sideMenuAlwaysOn) {
    return;
  }
  var targetId = "sideCell" + menuNum + "";
  target = document.getElementById( targetId );
  if (target.className == "menuItem") {
    target.style.background = "#707070";
  }
  else if (target.className == "menuCat") {
    target.style.background = "#4f4f4f";
  } else {
    target.style.background = "#2a2a2a";
  }
}


// Photo gallery function

function showThumbs (id) {
  var catThumb = document.getElementById("catThumbs"+id);
  if (catThumb.style.display == "block") {
    catThumb.style.display = "none";
    document.getElementById("plusminus"+id).src = ImagePlus.src;
  }
  else {
    catThumb.style.display = "block";
    document.getElementById("plusminus"+id).src = ImageMinus.src;
  }
}

function thumbOn (id) {
  var bigImage = document.getElementById("imageArea"+id);

  var bigParent = document.getElementById("photoArea");
  var list = bigParent.childNodes;

  for (var i = 0; i < list.length; i++) {
    // close all images first
    if (!(typeof list[i].id == 'undefined')) {
      list[i].style.display = "none";
    }
  }

  bigImage.style.display = "block";
}

