/*
  Some ideas for the menu were taken from
  Kevin Yank's "CROSS-BROWSER DHTML POP-UP MENUS"
  at http://www.webmasterbase.com/examples/dhtmlpopup.html.
*/

  var bInit = false;

  var onloadCustom = null;

  function onLoadPage()
  {
    if(document.getElementById || document.all || document.layers)
    {
      prepareMenus();
      bInit = true;
    }
    // else, not DHTML

    if(onloadCustom != null) // custom onload handler
      onloadCustom();

    if (document.getElementById) {
      var e = document.getElementById("commentbutton");
      var e2 = document.getElementById("commentbox");
      if (e && e2) {
        e.onclick = function() {
          e.className = 'hide';
          e2.className = 'show';
          return false;
        }
      }
    }
  }

  function prepareMenus()
  {
    //var b1 = getObject("bar1");
    //b1.onmouseover = new Function("alert('ok');");

    var n = 1;
    var menu;
    while(true)
    {
      var name = "menu" + n;
      menu = getObject(name);
      if(menu == null) break;

      menu.onmouseover = new Function("menuOver('"+n+"')");
      menu.onmouseout = new Function("menuOut('"+n+"')");

      if(document.layers)
      {
        //menu.clip.width = 200; menu.clip.height = 200;
        menu.document.bgColor="#ffffe0";
      }

      var s = getStyle(menu);
      s.top = 92;
      s.left = (n-1)*100;

      ++n;
    }
  }


  function getObject(id)
  {
    if(document.getElementById)
      return document.getElementById(id);
    else if(document.all)
      return document.all[id];
    else if(document.layers)
      return document.layers[id];
    else
      return null;  //??ok
  }

  function getStyle(o)
  {
    if(document.getElementById || document.all)
      return o.style;
    else
      return o;
  }


  function menuShow(num)
  {
    // hide others
    var n = 1;
    while(getObject("menu" + n))
    { menuHide(n); ++n; }

    var o = getObject("menu" + num);
    var s = getStyle(o);

    s.visibility = 'visible';
  }

  function menuHide(num)
  {
    var o = getObject("menu" + num);
    var s = getStyle(o);
    s.visibility = 'hidden';
  }

  function menuOver(num)
  {
    if(!bInit) return;
    if(menuTimers[num]) clearTimeout(menuTimers[num]);

    menuShow(num);
  }

  function menuOut(num)
  {
    if(!bInit) return;

    menuTimers[num] = setTimeout("menuHide('"+num+"');", 500);
  }
  var menuTimers = new Array();

  function showCart()
  {
    AAAshowCart();
  }

  //temporary fix.  this interfaces to the old shopping cart

  function AAAshowCart()
  {
    var path = location.pathname;
    document.cookie = "complete=no" + "; path=/; domain=" + window.libshopcart1.getCookieDomain();
    document.cookie = "backup=" + path +"; path=/; domain=" + window.libshopcart1.getCookieDomain();
    var cartWindow = open('/common/shopcart1/shopcart.htm', 'sisShopCart', 'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1');
    if(cartWindow.focus)
      cartWindow.focus();
  }

  function AAAaddMe(part,quan,weight,desc,sprices)
  {
    var path = window.location.pathname;
    if(sprices=='?')
    {  alert('Sorry, the price is not in our database.'); return 0; }

    if(part != null)
    {
      if(!AAAok(quan)) return false;

      //order.createPart(part, quan, weight, path, desc, sprices);
      var newcook = "#" + part + "=" + quan + "|" + weight + "|" + path + "|" + desc + sprices + "; path=/; domain=" + window.libshopcart1.getCookieDomain();
      document.cookie = newcook;
    }
    AAAshowCart();
    return false;
  }

  function AAAok(n)
  {
    r=1;for(i=0;i<n.length;i++){c=n.substring(i,i+1);if(c<"0"||c>"9") {alert(n+" is not a positive integer");return 0;}}if(n>100000){alert(n+" units is a LARGE order");r=0;}if(n==0){alert("quantity can't be zero");r=0;}return r;
  }


  function addMe(part,quan,weight,desc,sprices)
  {
    AAAaddMe(part,quan,weight,desc,sprices);
  }

function dec(s) {
  var dec = '';
  for(var n=0; n<s.length; ++n) {
    var c = s.charAt(n);
    if(c == "*" || c == "L")
      dec += "@";
    else if(c == c.toLowerCase())
      dec += c;
  }
  return dec;
}
function removeLiame(i) {
  if (document.getElementById) {
    var img = document.getElementById('liame' + i);
    if (img) img.innerHTML = '';
  }
}
function liame1(emE) {
  var em = dec(emE);
  var lnkE = '<aZZ MhrRefN="maPPilNtoR:' + em + '"R>';
  var lnk = dec(lnkE);
  
  document.write(lnk + em + '</a> ');
  document.write(lnk);
}
function liame2(i) {
  document.write('</a>');

  removeLiame(i);
}

// navigation effects.
//
// tooltip based on code by Jim Young (www.requestcode.com)
// at http://www.javascriptkit.com/script/script2/tooltip.shtml

// .ttip {border:1px solid black; font-size:12px;
//    layer-background-color:lightyellow;background-color:lightyellow}
// note:
//   document.getElementById -- NS6.0+ and IE5.0+

function showFrame(obj, evt, text) 
{
  if(document.getElementById) {
    var elm = document.getElementById("frame");
    elm.innerHTML = text;
    elm.style.visibility = "visible";
  }
}
function hideFrame()
{
  if(document.getElementById) {
    var elm = document.getElementById("frame");
    elm.style.visibility = "hidden";
  }
}

function _neobj() { }

function getabspos(obj)
{
  var left = 0;
  var top = 0;
  var ele = obj;
  while(ele) {
    if(ele.offsetLeft) left += ele.offsetLeft;
    if(ele.offsetTop) top += ele.offsetTop;
    //alert("" + ele.offsetTop  + " " + ele.tagName);
    ele = ele.offsetParent;
  }

  var ret = new _neobj();
  ret.left = left;
  ret.top = top;
  return ret;
}

function showtip(obj, evt, text)
{
  if(document.layers) // NS4.0+
  {
    document.tooltip.document.write(text);
    document.tooltip.document.close();
    document.tooltip.left = evt.pageX + 14;
    document.tooltip.top = evt.pageY + 2;
    document.tooltip.visibility = "show";
  }
  else if(document.getElementById) // NS6.0+ and IE5.0+
  {
    var pos = getabspos(obj);
    var elm = document.getElementById("tooltip");
    elm.innerHTML = text;
    
    var left = 143;
    //var left = pos.left > 200 ? 0 : pos.left;
    //var pagewidth = window.innerWidth ? window.innerWidth : (document.body && document.body.clientWidth ? document.body.clientWidth : 600);
    //elm.style.top = (document.body && document.body.scrollTop
    //? document.body.scrollTop : 0) + 100;

    elm.style.top = pos.top;
    elm.style.left = 143;

    //if(pos.left > 200) {
    //  elm.style.left = 0;
    //  elm.style.width = (pagewidth > 400) ? pos.left : null;
    //} else {
    //  elm.style.left = parseInt(left) + obj.offsetWidth;
    //  elm.style.width = null;
    //}
    elm.style.visibility = "visible";
  }
}
function hidetip()
{
  if (document.layers) { // NS4.0+
    document.tooltip.visibility = "hidden";
  }
  else if(document.getElementById) { // NS6.0+ and IE5.0+
    var elm = document.getElementById("tooltip");
    elm.style.visibility = "hidden";
  }
}

function showtip2(obj, evt, text)
{
  if(document.getElementById) // NS6.0+ and IE5.0+
  {
    var pos = getabspos(obj);
    var elm = document.getElementById("tooltip");
    elm.innerHTML = text;
    
    var left = 143;
    //var left = pos.left > 200 ? 0 : pos.left;
    //var pagewidth = window.innerWidth ? window.innerWidth : (document.body && document.body.clientWidth ? document.body.clientWidth : 600);
    //elm.style.top = (document.body && document.body.scrollTop
    //? document.body.scrollTop : 0) + 100;

    elm.style.top = pos.top;
    if(pos.left > 200 + 20) { // left
        elm.style.left = pos.left - 200 - 4;
    }
    else { // right
        elm.style.left = pos.left + obj.offsetWidth + 4;
    }

    //if(pos.left > 200) {
    //  elm.style.left = 0;
    //  elm.style.width = (pagewidth > 400) ? pos.left : null;
    //} else {
    //  elm.style.left = parseInt(left) + obj.offsetWidth;
    //  elm.style.width = null;
    //}
    elm.style.visibility = "visible";
  }
}

/*OLD
function hoverFix(id, tag) {
  var nav = document.getElementById(id);
  if (!nav) return;
  var sfEls = nav.getElementsByTagName(tag);
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function()  {
      this.className=this.className.replace(
        new RegExp("(\\w+)", "g"), "$1sfhover") + " sfhover";
    }
    sfEls[i].onmouseout=function()  {
      this.className=this.className.replace(
        new RegExp(" ?sfhover\\b","g"), "");
    }
  }
}
*/
//function sfHover() {
//  hoverFix('nav', 'li');
//}

//if (window.attachEvent) window.attachEvent("onload", sfHover);

/* jquery init */
if (typeof jQuery != 'undefined') { $(function() {

  /*install tooltips*/
  function handler() {
    var c = $(this).attr("class");
    var s = c.match('\\babout-\\w+\\b');
    if (s == "about-next")
      return $(this).next().html();
    var e = s && $('#' + s);
    if (e && e.length > 0) {
      return e.html();
    }
    else { return '<div></div>';}
  }

  $('[class*=about-]').tooltip({
    delay:0,
    left:100,
    //extraClass: "tool1",
    track: true,
    bodyHandler: handler
  });

  if (window.IE6_FOUND) {
    $('#nav li').hover(
      function() {
        $(this).addClass('sfhover');
      },
      function() {
        $(this).removeClass('sfhover');
      }
    );
  }

  // set initial input focus
  $('#sidebarsearch').select().focus();

  $('#sidebarsearch').focus(function(){
    if ($(this).attr('value') == 'search') {
      $(this).attr('value','');
    }
  });


  /* set improved search action (default /search.htm gives
     simpler links for search engines) */
  var e = document.getElementById("searchform");
  if (e) {
    e.action = document.location.href;
  }

}) }
