
var inelem = [];

var timerOver = [];
var timerOut = [];


startList = function() {
  if (document.getElementById) {
    navRoot = document.getElementById("nav");

    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];

      if ((node.nodeName=="LI") && (node.className.indexOf("cur") == -1) && (node.className.indexOf("line")==-1)) {

        inelem[i] = false;
        
        var h3 = node.getElementsByTagName("h3");
        h3 = h3[0];
        

        h3.onmousedown = function(ii) {
          return function() {
            inelem[ii] = true;

                    for(k = 0; k < inelem.length; k++) {
                      inelem[k] = k == ii;
                      }

                for (k = 0; k < navRoot.childNodes.length; k++) {
                  siblingNode = this.parentNode.parentNode.childNodes[k];
                  if ((siblingNode.nodeName=="LI") && (siblingNode.className.indexOf("cur") == -1) && (siblingNode.className.indexOf("line")==-1)) {
                    if(inelem[k])
                      showLI(siblingNode, k);
                    else
                      hideLI(siblingNode, k);
                  }
                }
  
                    showLI(this.parentNode, ii);
                }

        }(i);


      }
    }
  }
}


function showitem(id, height, maxheight) {
  var navRoot = document.getElementById("nav");
  var li = navRoot.childNodes[id];

  var lists = li.getElementsByTagName("ul");
  if (lists.length > 0) {
    var list = lists[0];

        
        height += Math.round((maxheight - height) / 1.2);
      
        if (height >= maxheight){
          list.style.height="auto";
//          list.style.height=maxheight;
        } else {
          if (li.className.indexOf("active") == -1) {
            li.className+=" active";
          }
          list.style.height = height+'px';
          timerOver[id] = setTimeout('showitem('+id+', '+height+', '+maxheight+')', 1);
      }
  }
}


showLI = function(li, id) {
      var lists = li.getElementsByTagName("ul");
    if (lists.length > 0) {
        var list = lists[0];
        if (li.className.indexOf("active") != -1) {
          inelem[id] = false;
      list.style.height = "auto";
          hideLI(li, id);
          return;
        }

        list.style.top = '-10000px';
        list.style.left = '-10000px';
        list.style.position = "absolute";
        list.style.width = '184px';
        list.style.height = "auto";
        list.style.display = "block";
        var maxHeight =  Math.round(list.offsetHeight);
    //alert(maxHeight);
        list.style.display = "";
        list.style.position = "";
        list.style.left = '';
        list.style.width = '';

        list.style.height="0px";

        listheight = parseInt(list.style.height);
      
        timerOver[id] = setTimeout('showitem('+id+', '+listheight+', '+maxHeight+')', 1);
    }
}

function hideitem(id, height) {
  var navRoot = document.getElementById("nav");
  var li = navRoot.childNodes[id];

  var lists = li.getElementsByTagName("ul");
  var list = lists[0];

        height -= Math.round(height / 2);
        if (height <= 0) {
          list.style.height = '0px';
          li.className=li.className.replace("active", "");
        } else {
          list.style.height = height+'px';
          timerOut[id] = setTimeout('hideitem('+id+', '+height+')', 1);
        }
}


hideLI = function(li, id) {
  if(inelem[id]) return;

        var lists = li.getElementsByTagName("ul");
      if (lists.length > 0) {
        var list = lists[0];
      

      if (list.style.height == 'auto' && list.offsetHeight > 0) {
        list.style.height = (list.offsetHeight) + "px";
      } else {
    //    alert(list.style.height);
        list.style.height = "0px";
      }
    
      listheight = parseInt(list.style.height);
            timerOut[id] = setTimeout('hideitem('+id+', '+listheight+');', 1);
      }
}


window.onload=startList;



function ShowImageWindow(picname, width, height, title)
{
  if(self && self.screen && self.screen.width)
  {
    pos="";
    if(width>self.screen.width)
    {
      winwidth=self.screen.width-20;
      pos+=",left=0";
    }
    else
    {
      winwidth=width;
      pos+=",left="+((self.screen.width-width+17)/2);
    }
    if(height>self.screen.height)
    {
      winheight=self.screen.height-60;
      pos+=",top=0";
    }
    else
    {
      winheight=height;
      pos+=",top="+((self.screen.height-height)/2);
    }
      
  }
  var params='toolbar=no,height='+winheight+',width='+winwidth+',location=no,scrollbars=no,status=no,menubar=no,resizable=yes'+pos;
  picwin=window.open("","_blank",params);
  picwin.document.write("<html><title>"+title+"</title>");
  picwin.document.write("<body marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>");
  picwin.document.write("<img src='"+picname+"' width="+width+" height="+height+" border=0>");
  picwin.document.write("</body></html>");
}

function createControl(divid, url, flashid, width, height) {
  var d = document.getElementById(divid);
  d.innerHTML = '<object type="application/x-shockwave-flash" data='+url+' id='+flashid+' name='+flashid+' height='+height+' width='+width+'><param name="movie" value='+url+' /></object>';
}
