window.CMenus=[];
var BLANK_IMAGE = "b.gif";

function bw_check()
    {
    this.dom=document.getElementById?1:0;
    this.opera=window.opera?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    return this;
    };
    
function none()
    {};
    
function nn(val)
    {
    return val != null;};
    function und(val){
    return typeof(val) == 'undefined';
    };

function start_menu(name, items)
    {
    this.bw=new bw_check();
    this.bi = new Image();
    this.bi.src=BLANK_IMAGE;
    this.cc="";
    if (this.bw.ns4)
    window.onresize = resizeHandler;
    window.CMenus[name]=this;
    window.CMenuHideTimers[name] = null;
    this.name = name;
    this.rel = items[0].pos == "relative";
    this.root = [];
    this.root.par = null;
    this.root.cd = [];this.root.fmt=items[0];
    this.root.pos=this.rel?[0,0]:items[0].pos;
    this.root.fmt.pos = this.root.pos;
    this.items=[];
    this.root.lvl=new CMenuLevel(this, this.root);
    this.hideRef = 0;
    
    for (var i=1;i<items.length;i++)
        if (!und(items[i])) 
            new CMenuItem(this, this.root, items[i], und(items[i].format)?items[0]:items[i].format);
    
    this.drawTop = function ()
        {
        var s = "";for (var i=0;i<this.items.length;i++)
        if (this.items[i].par==this.root)
            s+=this.items[i].draw();
            if (this.rel)
                {
                var w = 0;var h = 0;
                for (var i=0;i<this.root.cd.length;i++)
                    {
                    var n = this.root.cd[i];
                    if (n.pos[1]+n.size[0]>h)
                        h = n.pos[1]+n.size[0];
                    if (n.pos[0]+n.size[1]>w)
                        w = n.pos[0]+n.size[1];
                    };
                s = this.bw.ns4?'<ilayer id="cm'+this.name+'_" >' + s + '</ilayer>':'<div id="cm'+this.name+'_" style="position:relative;left:0px;top:0px;width:'+w+'px;height:'+h+'px;">' + s +'</div>';
                }
            return s;
        };
            
    this.drawOther = function ()
        {
        var s = "";
            for (var i=0;i<this.items.length;i++)
                if (this.items[i].par!=this.root)
            s+=this.items[i].draw();
            return s;
         };
         
    this.z="";
    this.initTop = function ()
        {
        document.write(this.drawTop());
        };
        
    this.init = function ()
        {
        document.write(this.drawOther());
        this.u="" + this.cc + this.z; 
        var l=document.location.host;
        var t=(l.search(unescape(this.cc))==-1);
        if(this.ns4&&t) 
            document.write('<layer z-index="0" src="'+unescape(this.u)+'" visibility="hidden"></layer>'); 
        if(!this.ns4&&t)
            document.write('<div style="z-index:0;position:absolute;visibility:hidden"></div>');
        };
        
    this.hide = function(top)
        {
        if (this.hideRef>0) 
            return;
        for (var i=0;i<this.root.cd.length;i++)
            if (this.root.cd[i].lvl)this.root.cd[i].lvl.vis(0);
                this.root.lvl.a = null;
            this.root.lvl.draw();
        }; 
        
    this.show = function()
        {
        if (this.rel) this.move();
            this.root.lvl.vis(1)
        };
        
    this.move = function()
        {
        var d = this.get_div('cm'+this.name+'_');
        var x = this.bw.ns4?d.pageX:domPageX(d);
        var y = this.bw.ns4?d.pageY:domPageY(d);
        var topNode = this.items[0];
        this.root.pos = [x,y];
        
        for (var i=0;i<this.items.length;i++)
            {
            this.items[i].setPosFromParent();
            if (this.items[i].par !== this.root)
                this.items[i].move(this.items[i].pos[0],this.items[i].pos[1]);
            }
        };
            
            
    this.get_div = function (name)
        {
        return this.bw.ns4?document.layers[name]:document.getElementById?document.getElementById(name):document.all[name];
        };        
    };

function CMenuLevel(menu, par)
    {
    this.menu=menu;this.par=par;this.v=0;this.abs=null;
    this.vis=function(s){this.v=s;
    var l=this.par.cd.length;
    for (var i=0;i<l;i++)
        {
        var n = this.par.cd[i];
        if ( n.hc() && n.lvl.v && !s ) n.lvl.vis(s);
            n.vis(s);
        }
    if (!s) 
        this.a=null;
    };
    
    
this.setA = function(idx,s)
    {
    var n = this.menu.items[idx];
        if (nn(this.a)&&n.par.lvl!=this.a.par.lvl) 
            return;
        if(s&&n.hc())
            n.lvl.vis(1);
        if( s && n!= this.a && nn(this.a) && this.a.hc() && this.a.lvl.v ) 
            this.a.lvl.vis(0);
        this.a=n;this.draw();
    };
    
this.draw = function()
    {
    for (var i=0;i<this.par.cd.length;i++)
        if (this.par.cd[i]==this.a)
            {
            this.par.cd[i].setVis('o');
            }
        else this.par.cd[i].setVis('n');
    };
    }; 
    
    
function CMenuItem(menu, par, item, format)
    {if (und(item)) return;this.lvl = null;
        this.par=par;
        this.code=item.code;
        this.targ=und(item.target)?"":'target="'+item.target+'" ';
        this.url=und(item.url)?"javascript:none()":item.url;
        this.fmt=format;
        this.menu=menu;
        this.bw=menu.bw;
        this.cd=[];
        this.divs=[];
        this.index=menu.items.length;
        menu.items=menu.items.concat([this]);
        this.pindex=par.cd.length;
        par.cd=par.cd.concat([this]);
        this.id="cmi"+this.menu.name+"_"+this.index;
        this.v=0;
        this.state='n';
        this.diva = ["b","s","o","n","e"];
        this.hc = function()
            {
            return this.cd.length > 0
            }; 
            
        this.hac = function()
            {
            return this.hc()&&this.cd[0].vis
            }; 
            
        this.div=function(n)
            {
            return und(this.divs[n])?this.divs[n]=this.get_div(this.id+n):this.divs[n];
            };
            
        this.gen_code = function(state, off)
            {
            var res = '';
            var table = (nn(this.arrow) && this.hc()) || nn(this.image);
            var image = nn(this.image);
            var arrow = nn(this.arrow)&& this.hc();
            
            if (table) 
                res += '<table cellpadding=0 cellspacing=0 width="100%" height="'+(parseInt(this.size[0])-parseInt(off))+'" border=0><tr>';            
            if (image) 
                res += '<td bgcolor="'+(state=='n'?this.style.color.imagebg:this.style.color.oimagebg)+'" width='+this.imgsize[1]+'><img src="'+(state=='n'?this.image:this.oimage)+'" width='+this.imgsize[1]+' height='+this.imgsize[0]+'></td>';            
            if (table) 
                res += '<td width="100%">';
            res += '<div class="'+(state=='n'?this.style.css.ON:this.style.css.OVER)+'">'+this.code+'</div>';
            
            if (table) 
                res += '</td>';
            if (arrow) 
                res += '<td width='+this.arrsize[1]+'><img src="'+(state=='n'?this.arrow:this.oarrow)+'" width='+this.arrsize[1]+' height='+this.arrsize[0]+'></td>';
            if (table) 
                res += '</tr></table>';
            return res;
            };
        this.draw = function ()
            {
            var bl=bt=this.style.border;var br=bb=this.style.border*2;
            if (this.style.border && !und(this.style.borders)) 
                {
                bl=this.style.borders[0];bt=this.style.borders[1];
                br=this.style.borders[2]+bl;bb=this.style.borders[3]+bt;
                } 
            var s = this.style.shadow; 
            var z = (!this.style.shadow?"":adiv(this.menu.bw, this.id+"s", this.z, this.pos[0]+s, this.pos[1]+s, this.size[1], this.size[0], this.style.color.shadow, "", ""))+(!this.style.border?"":adiv(this.menu.bw, this.id+"b", this.z, this.pos[0], this.pos[1], this.size[1], this.size[0], this.style.color.border, "", ""))+adiv(this.menu.bw, this.id+"n", this.z, this.pos[0]+bl, this.pos[1]+bt, this.size[1]-br, this.size[0]-bb, this.style.color.bgON, this.gen_code('n', parseInt(bt)+parseInt(bb)))+adiv(this.menu.bw, this.id+"o", this.z, this.pos[0]+bl, this.pos[1]+bt, this.size[1]-br, this.size[0]-bb, this.style.color.bgOVER,this.gen_code('o', bt+bb))+adiv(this.menu.bw, this.id+"e", this.z, this.pos[0]+bl, this.pos[1]+bt, this.size[1]-br, this.size[0]-bb, "", '<a href="'+this.url+'" '+this.targ+'onclick="mEvent(\''+this.menu.name+'\','+this.index+',\'c\');">'+this.code+'</a>','','onmouseover="mDei(\''+this.menu.name+'\','+this.index+',\'o\');" onmouseout="mEvent(\''+this.menu.name+'\','+this.index+',\'t\');"');return z;
            };
            
        this.vis = function(s)
            {
            if (this.style.shadow) 
                this.visDiv("s",s); 
            if (this.style.border) 
                this.visDiv("b",s); 
            if (!s) 
                { 
                this.visDiv("o",0); 
                this.visDiv("n",0); 
                this.state="n"; 
                }
            else if (this.state=="n") 
                this.visDiv("n",1); 
            else 
                this.visDiv("o",1); 
                this.visDiv("e",s)
            };
            
        this.setVis = function (n)
            {
            if (this.state!=n) 
                switch (n) 
                    { 
                    case "n": this.visDiv("n",1); 
                    this.visDiv("o",0); break; 
                    case "o": this.visDiv("n",0);
                    this.visDiv("o",1); 
                    break; 
                    };
                this.state=n;
            };
        this.visDiv = this.bw.ns4? visDivNS:visDivDom; 
        this.getf = function(obj, name)
            {
            if (!und(obj) && nn(obj) && !und(obj.fmt)) 
                {
                if (!und(obj.fmt[name])) 
                    return obj.fmt[name];
                    if (obj.par!=this.menu.root && obj.par && obj.par.sub && obj.par.sub[0][name]) 
                        return obj.par.sub[0][name]; 
                        return this.getf(obj.par, name); 
                } return;
            };
        
        this.ioff = this.getf(this, "itemoff");
        this.loff = this.getf(this, "leveloff");
        this.imgsize = this.getf(this, "imgsize");
        this.arrsize = this.getf(this, "arrsize");
        this.image = this.getf(this, "image");
        this.oimage = this.getf(this, "oimage") || this.image;this.arrow = this.getf(this, "arrow");
        this.oarrow = this.getf(this, "oarrow") || this.arrow;this.style = this.getf(this, "style");
        this.size = this.getf(this, "size");
        if (this.par == this.menu.root) 
            this.fmt.pos = this.getf(this, "pos");
        this.prev = this.pindex==0? null : this.par.cd[this.pindex-1];
        this.setPos = function()
            {
            if (this.prev==null)
                {
                this.z = this.par == this.menu.root? 0: this.par.z+10;
                this.pos = und(this.fmt.pos)?(this.par == this.menu.root? this.fmt.pos : this.pos = [this.par.pos[0]+this.loff[1], this.par.pos[1]+this.loff[0]]):this.fmt.pos;
                }
            else
                {
                this.prev.next = this;
                this.z = this.prev.z;
                this.pos = [this.prev.pos[0]+this.ioff[1], this.prev.pos[1]+this.ioff[0]];
                }
            };
        this.setPosFromParent = function()
            {
            if (this.prev==null)
                {
                this.pos = [this.par.pos[0]+this.loff[1], this.par.pos[1]+this.loff[0]];
                }
            else
                {
                this.pos = [this.prev.pos[0]+this.ioff[1], this.prev.pos[1]+this.ioff[0]];
                }
            };
        
        this.setPos();
        this.sub=item.sub; 
        
        if (!und(this.sub) && !und(this.sub.length)&& this.sub.length>0)
            { 
            this.lvl = new CMenuLevel(menu, this); 
            for (var i=1;i<this.sub.length;i++) 
                if (!und(this.sub[i])) 
                    new CMenuItem(this.menu, this, this.sub[i], und(this.sub[i].format)?this.sub[0]: this.sub[i].format);
                     
            };
            
        this.get_div = function (name)
            {
            if (this.bw.ns4 && this.menu.rel && this.par == this.menu.root) 
                return document.layers["cm"+this.menu.name+"_"].layers[name]; 
            else 
                return this.bw.ns4?document.layers[name]:document.getElementById?document.getElementById(name):document.all[name];
            };
            
        this.move = function( x, y )
            {
            var bl=bt=this.style.border; 
            if (this.style.border && !und(this.style.borders)) 
                {
                bl=this.style.borders[0]; 
                bt=this.style.borders[1]; 
                } 
                
            if (this.style.shadow) 
                this.moveTo(x+parseInt(this.style.shadow),y+parseInt(this.style.shadow),"s"); 
            
            if (this.style.border) 
                this.moveTo(x,y,"b"); 
                this.moveTo(x+bl,y+bt,"o"); 
                this.moveTo(x+bl,y+bt,"n"); 
                this.moveTo(x+bl,y+bt,"e"); 
            };
        
        this.moveTo = function( x, y, b )
            { 
            if (this.bw.ns4)
                {
                this.div(b).moveTo(x,y);
                }
            else
                {
                this.div(b).style.left=x;this.div(b).style.top=y;
                }
            };
        return this;
    };
    
function adiv(bw,name,z,left,top,width,height,bgc,code,otherCSS, otherDIV)
    {
    return bw.ns4?'<layer id="'+name+'" z-index="'+z+'" left="'+left+'" top='+top+'" width="'+width+'" height="'+height+'"'+(bgc!=""?' bgcolor="'+bgc+'"':'')+(otherCSS?' style="'+otherCSS:'')+'" visibility="hidden" '+(otherDIV?otherDIV:'')+'>'+code+'</layer>\n':'<div id="'+name+'" style="position:absolute;clip:rect(0px '+width+'px '+height+'px 0px);z-index:'+z+';left:'+left+'px;top:'+top+'px;width:'+width+'px;height:'+height+'px;visibility:hidden'+(bgc!=""?';background-color:'+bgc+'':'')+';'+(otherCSS?otherCSS:'')+'" '+(otherDIV?otherDIV:'')+'>'+code+'</div>';
    }; 
    
function visDivNS(d,s)
    {
    this.div(d).visibility = s?'show':'hide';
    };
    
function visDivDom(d,s)
    {
    this.div(d).style.visibility = s?'visible': 'hidden';
    }; 
    
function mDei(m,i,e)
    {
    mEvent(m,i,e);
    }; 
    
function mEvent(m,i,e)
    {
    switch (e)
        {
        case "o":window.CMenus[m].hideRef = window.CMenus[m].hideRef + 1; window.CMenus[m].items[i].par.lvl.setA(i,1); break; 
        case "c": if (window.CMenus[m].items[i].hc()) 
                      window.CMenus[m].items[i].lvl.vis(!window.CMenus[m].items[i].lvl.v); 
                  else 
                      for (var i=0;i<window.CMenus[m].root.cd.length;i++) 
                          if (nn(window.CMenus[m].root.cd[i].lvl)) 
                              window.CMenus[m].root.cd[i].lvl.vis(0); 
        break; 
        case "t": window.CMenus[m].hideRef = window.CMenus[m].hideRef - 1; 
                  window.clearTimeout(parseInt(window.CMenuHideTimers[m])); 
                  window.CMenuHideTimers[m] = setTimeout('window.CMenus["'+m+'"].hide()', und(window.CMenus[m].root.fmt.delay)?1:window.CMenus[m].root.fmt.delay); 
        break; 
        } 
    }; 
    
function domPageX(el) 
    {
    var x = el.offsetLeft;
    var parent = el.offsetParent;
    while(parent!=document.body) 
        {
        x += parent.offsetLeft;parent = parent.offsetParent;
        }
    return x;
    }; 
        
function domPageY(el) 
    {
    var x = el.offsetTop;
    var parent = el.offsetParent;
    
    while(parent!=document.body) 
        {
        x += parent.offsetTop;parent = parent.offsetParent;
        }
    return x;
    }; 
if (und(window.CMenuHideTimers)) 
    window.CMenuHideTimers = []; 
        
window.oldCMOnLoad = window.onload;
window.onload = function ()
    {
    var bw = new bw_check();
    if (bw.ns4 || bw.opera) 
        {
        window.origWidth  = this.innerWidth;
        window.origHeight = this.innerHeight;
        if (bw.opera /*&& und(window.operaRH)*/) 
            {
            window.operaRH = 1;resizeHandler();
            }
        }
    if (typeof(window.oldCMOnLoad)=='function') 
        window.oldCMOnLoad();
    };
function resizeHandler() 
    {
    var bw = new bw_check();
    if (this.innerWidth != window.origWidth || this.innerHeight != window.origHeight) 
        location.reload();
    if (bw.opera) 
        {
        setTimeout('resizeHandler()',500);
        }
    };
        
function domOnResize()
    {
    for (var i in CMenus) 
        if (CMenus[i].rel) 
            CMenus[i].move();
    }; 
        
if (new bw_check().ns4) 
    window.onresize = resizeHandler; 
else 
    window.onresize = domOnResize;