/*******************************************************
 * VMax DYNOMENU Lib  v3.0                             *
 * (C)1996-2000   Virtual_Max  ( http://come.to/vmax ) *
 * This library and it's derivatives  is  free for use * 
 * until this notice remains unchanged and  present in * 
 * all copies and derivatives.                         *
 * revision: 03/03/2001                                *
 *******************************************************/

function getById(id,o){
    if(document.getElementById) return document.getElementById(id);
    if(document.all)            return document.all[id]
    if(o==null) o=window.document;

    if(o.layers[id]){
      return o.layers[id]
    }

    if(o.images[id]){
      return o.images[id]
    }

    for(var i=0; i<o.layers.length; i++){
       var oo=getById(id,o.layers[i].document); 
       if(oo!=null) return oo;
    }
    return null;
}

function Dimension(x,y,w,h) {
  this.w=w; this.h=h; this.x=x; this.y=y;
}

function getDivSizes(o){
 if(o==null) return null;
 var x,y,w,h;
 if(document.layers) {
     x=o.left;
     y=o.top;
     if(o.height==null) o.height=o.clip.height;
     if(o.width==null)  o.width=o.clip.width;
     h=o.height;
     w=o.width;
  }
  else if(document.all){
     x=o.offsetLeft;
     y=o.offsetTop;
     w=o.scrollWidth;
     h=o.scrollHeight;
 }
 else{
     x=o.offsetLeft;
     y=o.offsetTop;
     w=o.offsetWidth;
     h=o.offsetHeight;
 }
 return new Dimension(x,y,w,h);
}


function getViewPort(){
  var x=0,y=0,w=640,h=480;
  if(document.all) {
     var o=window.document.body;
     x=o.scrollLeft;
     w=o.offsetWidth;
     y=o.scrollTop;
     h=o.offsetHeight;
  } 
  else {
     x=window.pageXOffset;
     w=window.innerWidth;
     y=window.pageYOffset;
     h=window.innerHeight;
  }

  return new Dimension(x,y,w,h);
}

function getPageSize(){
  var w=640,h=480;
  if(document.all) {
     var o=window.document.body;
     w=o.scrollWidth;
     h=o.scrollHeight;
  } 
  else {
     w=document.width;
     h=document.height;
  }
  return new Dimension(0,0,w,h);
}


function showDiv(o,vis) {
  if( o==null ) return;
  if(!document.layers) o=o.style;
    o.visibility = vis ? "visible" : "hidden";
}



function moveDiv(o,x,y){
  if( o==null ) return;
  if(document.layers){
     o.moveTo(x,y);     
  }
  else {
    o=o.style;
    if(document.all) {
       o.pixelLeft=x;
       o.pixelTop=y;
    }
    else {
       o.left=x;
       o.top=y;     
    }
  }
}


/*----- zIndex functions -------*/

function setZindex(o, index){
  if( o==null ) return;
  if(!document.layers)    o=o.style;
  o.zIndex=index;
}

function getZindex(o){
  if( o==null ) return 0;
  if(!document.layers) o=o.style;
  return parseInt(o.zIndex);
}

	
//==============================================

function changeContent(o,content){
 if(o==null) return;
 if(document.layers){
    o.document.writeln(content);
    o.document.close();
 }
 else o.innerHTML = content
}


if(!document.all){
 var oldWidth=window.innerWidth ;
 var oldHeight=window.innerHeight;

 function fixResize(){
  if(document.layers){
    if(oldWidth!=window.innerWidth || oldHeight!=window.innerHeight){ 
      history.go(0);
   }
  }
 }
 window.onresize=fixResize;
}

//=====================================================================
var m_cnt=0;
var allMenus = new Array();

function DynoMenu(txt,url,iconset,formatter) {
   if(formatter==null)  this.txt = txt;
   else                 this.txt = formatter(txt);
   if(url==null) this.url="Javascript:void(0)";
   else          this.url = url; 

   this.iconset = iconset;
   this.pappy   = null;
   this.opened  = false;
   this.sub = new Array(); 
   var args = DynoMenu.arguments;
   for(var i=0; i<args.length-4; i++) {
     this.sub[i] = args[i+4];
     this.sub[i].pappy = this;
   }
   this.depth    = -1;
   this.divname  = null;
   this.iconname = null;
   this.x=0;
   this.y=0; 
   this.lastx=0;
   this.lasty=0; 
   this.h=null; 
   this.vis=false;
} 

function LineIcon(w,h,src){
  this.w=w;
  this.h=h;
  this.src=src;
}

function Iconset(){
   this.imnames = new Array();
   this.ims     = new Array();
   this.w = Iconset.arguments[0];
   this.h = Iconset.arguments[1];
   for(var i=2;i<Iconset.arguments.length;i++){
     this.imnames[i-2] = Iconset.arguments[i];
     this.ims[i-2]     = new Image();
     this.ims[i-2].src = this.imnames[i-2];
   }
}






function createMenu(menuname){
   var menu = eval(menuname);
   if(menu.pappy == null) {
       menu.opened = true;
       menu.depth=-1;
   }
   else {
       menu.opened = false;     
       menu.depth  = menu.pappy.depth+1;
       createOne(menu);
   }            
   for(var i=0; i<menu.sub.length; i++) {
      createMenu(menuname+'.sub['+i+']');
   }
}



function createOne(menu){
   menu.divname  = 'DL'+m_cnt;
   menu.iconname = 'DI'+m_cnt;

   var s='<DIV ID="'+menu.divname+'" CLASS="DYNO">';
   s+="<table cellspacing=0 cellpadding=0 border=0><tr>";
   for(var i=0; i < menu.depth; i++){
     s+='<td width=10 align=right><img src="'+lineicon.src+'" width='+lineicon.w+' height='+lineicon.h+' border=0></td>';
   }

   s+='<td><a href="javascript:void(0);" ';
   s+=  makeIconHandlers(m_cnt);
   s+='>';
   s+='<img name="'+menu.iconname+'" src="'+menu.iconset.imnames[(menu.opened)?1:0]+'" width='+menu.iconset.w+'  height='+menu.iconset.h+' border=0></a></td>';

   s+='<td NOWRAP><a href="'+menu.url+'" CLASS="DYNOITEM" ';
   s+=' target="'+target+'" '
   s+= makeMenuHandlers(m_cnt);
   s+='>';
   s+= menu.txt;
   s+='</a></td>'
   s+='</tr></table></DIV>';

   document.writeln(s);
   allMenus[m_cnt] = menu;
   m_cnt++;
}

function makeIconHandlers(n){
   var s = " onMouseOver='highlight("+n+",true)'";
   s+= " onMouseOut='highlight("+n+",false)'";
   s+= " onClick='return toggle("+n+")'";
   return s;
}

function makeMenuHandlers(n){
   var s = " onMouseOver='highlight("+n+",true)'";
   s+= " onMouseOut='highlight("+n+",false)'";
   s+= " onClick='return toggleAndGo("+n+")'";
   return s;
}


function toggle(n){
   var m = allMenus[n];
   if(m.sub.length>0 && !m.opened) m.opened=true;
   else  m.opened=false;
   var p = m
   while(p.pappy!=null) p = p.pappy;
   placeMenu(p,p.x,p.y,true);
   return false;
}

function toggleAndGo(n){
   var m = allMenus[n];
   if(m.sub.length>0 && !m.opened) m.opened=true;
   var p = m
   while(p.pappy!=null) p = p.pappy;
   placeMenu(p,p.x,p.y,true);
   return (m.href!="Javascript:void(0)");
}

function highlight(n,over) {
   var m = allMenus[n];
   var inx = m.opened ? 1:0;
   if(over) inx +=2;
   if(document.images[m.iconname])
     document.images[m.iconname].src=m.iconset.ims[inx].src;
   else  
     m.obj.document.images[m.iconname].src=m.iconset.ims[inx].src;   
}

function placeMenu(m,x,y,vis){
   if(m.divname!=null && vis) {
     if(m.lasty!=y) {
        if( document.all && m.lastx == x ) m.obj.style.pixelTop = y;
        else moveDiv(m.obj,x,y); 
        m.lastx = x ;
        m.lasty = y ;        
     }
     y+=m.h;
   }
   if(vis!=m.vis) {
      showDiv(m.obj,vis);
      m.vis = vis;
   }
   m.x = x; m.y = y;
   vis = vis && m.opened;
   for(var i=0; i<m.sub.length; i++)  y=placeMenu(m.sub[i],x,y,vis);  
   return y;
}

function initMenuObjects(m){
   m.obj = getById(m.divname);
   if( m.obj!=null ) m.h = getDivSizes(m.obj).h;   
   for(var i=0; i<m.sub.length; i++) initMenuObjects(m.sub[i]);
}


function initMenu(m,x,y){
  initMenuObjects(m);
  placeMenu(m,x,y,true);
}