
var MENU_TPL = [
	{
		'width': 70,
		'height': 22,
		'line-height': 20,
		'left': 69,
		'top': 0,
		'hide_delay': 200,
		'expd_delay': 200,
		'css': {
		        'inner': 'menu-rooti0',
		        'outer': ['menu-rooto0','menu-rooto1']
		},
		'block_left': 100,
		'block_top': 250
	},
	{
		'width': 120,
		'block_left': 0,
		'block_top': 25,
		'left': 0,
		'top': 23,
		'css': {
		        'inner': 'menu-rooti0',
		        'outer': ['menu-sublevelso0','menu-sublevelso1']
		}
	},
	{
		'block_left': 105,
		'block_top': 10
	}
];

var MENU_TPL_TRANS = [
	{
		'width': 70,
		'height': 22,
		'line-height': 20,
		'left': 69,
		'top': 0,
		'hide_delay': 200,
		'expd_delay': 0,
		'css': {
		        'inner': 'menu-rooti0',
		        'outer': ['.menu-rooto0-transparent','menu-rooto1-transparent']
		},
		'block_left': 100,
		'block_top': 250
	},
	{
		'width': 120,
		'block_left': 0,
		'block_top': 25,
		'left': 0,
		'top': 23,
		'css': {
		        'inner': 'menu-rooti0',
		        'outer': ['menu-sublevelso0','menu-sublevelso1']
		}
	},
	{
		'block_left': 105,
		'block_top': 10
	}
];

var TMA=[];
function menu(menu_items,left,top,style){
    if(!document.body || !document.body.style) return;

    this.menu_items=menu_items;

    if(style=="transparent"){
       this.menu_template=MENU_TPL_TRANS;
    } else {
       this.menu_template=MENU_TPL;
    }
    this.menu_template[0].block_left=left;
    this.menu_template[0].block_top=top;


    this.TME=TMA.length;
    this.TMF=[];this.TMG=[];
    this.TMH=TMI;
    this.TMJ=TMK;
    this.onclick=onclick_func;
    this.onmouseout=onmouse_out_func;
    this.onmouseover=onmouseover_func;
    this.onmousedown=onmousedown_func;
    this.TMP={'block_top':16,'block_left':16,'top':20,'left':4,'width':120,'height':22,
	'hide_delay':0,'expd_delay':0,'css':{'inner':'','outer':''}};
    this.template_func=function(TMR){
	return this.TMP[TMR]
    };
    this.TMS=this;
    this.TMT=-1;
    this.TMU=0;
    this.TMV=0;
    var level=1;
    for(i=0;i<menu_items.length;i++) new create_item(this,i);

    TMA[this.TME]=this;
    for(var i=0;i<this.TMG.length;i++) {
	this.TMG[i].TMY.style.visibility='visible';
    }
}

function create_item(Parent,i){
    this.TMT=Parent.TMT+1;
    this.menu_items=Parent.menu_items[i+(this.TMT?3:0)];
    if(!this.menu_items)return;
    this.TMS=Parent.TMS;
    this.Parent=Parent;
    this.i=i;
    this.TME=this.TMS.TMF.length;
    this.TMS.TMF[this.TME]=this;
    Parent.TMG[i]=this;
    var TMS=this.TMS,menu_template=this.TMS.menu_template;
    this.template_func=TMk;
    this.TMg=TMl;
    this.TMi=TMm;
    this.TMU=i?Parent.TMG[i-1].TMU+this.template_func('left'):Parent.TMU+this.template_func('block_left');
    this.TMV=i?Parent.TMG[i-1].TMV+this.template_func('top'):Parent.TMV+this.template_func('block_top');

    if(this.TMT==0 || this.menu_items[3]==null){
    document.write('<a id="e'+TMS.TME+'_'+this.TME+'o" class="'+this.TMg(0,0)+'" href="'+this.menu_items[1]+'"'+(this.menu_items[2]&&this.menu_items[2]['tw']?' target="'+this.menu_items[2]['tw']+'"':'')+' style="position: absolute; top: '+this.TMV+'px; left: '+this.TMU+'px; width: '+this.template_func('width')+'px; height: '+this.template_func('height')+'px; line-height: '+this.template_func('line-height')+'px; visibility: hidden;'+' z-index: '+this.TMT+';" '+'onclick="return TMA['+TMS.TME+'].onclick('+this.TME+');" onmouseout="TMA['+TMS.TME+'].onmouseout('+this.TME+');" onmouseover="TMA['+TMS.TME+'].onmouseover('+this.TME+');" onmousedown="TMA['+TMS.TME+'].onmousedown('+this.TME+');"><div  id="e'+TMS.TME+'_'+this.TME+'i" class="'+this.TMg(1,0)+'">'+this.menu_items[0]+"</div></a>\n");
    } else {
    document.write('<a id="e'+TMS.TME+'_'+this.TME+'o" class="'+this.TMg(0,0)+'" href="'+this.menu_items[1]+'"'+(this.menu_items[2]&&this.menu_items[2]['tw']?' target="'+this.menu_items[2]['tw']+'"':'')+' style="position: absolute; top: '+this.TMV+'px; left: '+this.TMU+'px; width: '+this.template_func('width')+'px; height: '+this.template_func('height')+'px; line-height: '+this.template_func('line-height')+'px; visibility: hidden;'+' z-index: '+this.TMT+';" '+'onclick="return TMA['+TMS.TME+'].onclick('+this.TME+');" onmouseout="TMA['+TMS.TME+'].onmouseout('+this.TME+');" onmouseover="TMA['+TMS.TME+'].onmouseover('+this.TME+');" onmousedown="TMA['+TMS.TME+'].onmousedown('+this.TME+');"><div  id="e'+TMS.TME+'_'+this.TME+'i" class="'+this.TMg(1,0)+'">'+"<table width='100%'><tr><td class='"+this.TMg(1,0)+"'>"+this.menu_items[0]+"</td><td style='text-align:right;' class='"+this.TMg(1,0)+"'>&#183;</td></tr></table>"+"</div></a>\n");


    }

    this.TMh=document.getElementById('e'+TMS.TME+'_'+this.TME+'i');
    this.TMY=document.getElementById('e'+TMS.TME+'_'+this.TME+'o');

    this.TMc=!this.TMT;
    if(this.menu_items.length<4)return;
    this.TMG=[];
    for(var i=0;i<this.menu_items.length-3;i++)new create_item(this,i)
}


function TMK(TME){
    clearTimeout(this.TMZ);
    var TMa=(TME?this.TMF[TME].TMT:0);
    for(TME=0;TME<this.TMF.length;TME++){
	 var TMb=this.TMF[TME];
	 if(TMb.TMT>TMa&&TMb.TMc){
	   TMb.TMY.style.visibility='hidden';
	   TMb.TMc=false
	 }
    }
    if(!TME)this.TMd=null
}


function TMI(TME){
    if(this.TMe) return;
    var TMf=this.TMF[TME];
    if(this.TMd&&this.TMd.TMT>=TMf.TMT)this.TMJ(TMf.TME);
    this.TMd=TMf;
    if(!TMf.TMG)return;
    for(var i=0;i<TMf.TMG.length;i++){
	var TMb=TMf.TMG[i];
	TMb.TMY.style.visibility='visible';TMb.TMc=true
    }
}

function onclick_func(TME){
    return Boolean(this.TMF[TME].menu_items[1])
}


function onmouse_out_func(TME){
    var TMf=this.TMF[TME];
    TMf.TMY.className=TMf.TMg(0,0);
    TMf.TMh.className=TMf.TMg(1,0);
    TMf.TMi(7);
    this.TMe=setTimeout('TMA['+this.TME+'].TMJ();',TMf.template_func('hide_delay'))
}


function onmouseover_func(TME){
    clearTimeout(this.TMe);
    this.TMe=null;
    clearTimeout(this.TMZ);
    var TMf=this.TMF[TME];
    TMf.TMi();
    TMf.TMY.className=TMf.TMg(0,1);
    TMf.TMh.className=TMf.TMg(1,1);
    if(TMf.template_func('expd_delay')<0)return;
    this.TMZ=setTimeout('TMA['+this.TME+'].TMH('+TME+');',TMf.template_func('expd_delay'))
}


function onmousedown_func(TME){
    var TMf=this.TMF[TME];
    TMf.TMY.className=TMf.TMg(0,2);
    TMf.TMh.className=TMf.TMg(1,2);
    this.TMH(TME)
}


function TMk(TMR){
    var TMn=null,menu_template=this.TMS.menu_template[this.TMT];
    if(menu_template) TMn=menu_template[TMR];
    return(TMn==null?this.Parent.template_func(TMR):TMn)
}

function TMl(TMp,TMq){
    var TMr=this.template_func('css');
    var TMs=TMr[TMp?'inner':'outer'];
    if(typeof(TMs)=='string')return TMs;
    for(var TMt=TMq;TMt>=0;TMt--)if(TMs[TMt])return TMs[TMt]
}

function TMm(TMu){
    window.setTimeout("window.status=unescape('"+(TMu?'':(this.menu_items[2]&&this.menu_items[2]['sb']?escape(this.menu_items[2]['sb']):escape(this.menu_items[0])+(this.menu_items[1]?' ('+escape(this.menu_items[1])+')':'')))+"')",10)
}

function getElementPosition(theElement){
    var posX = 0;
    var posY = 0;
    
    while(theElement != null){
	posX += theElement.offsetLeft-theElement.scrollLeft+theElement.clientLeft;
	posY += theElement.offsetTop-theElement.scrollTop+theElement.clientTop;
	theElement = theElement.offsetParent;
    }
    return {x:posX,y: posY};
}

function addListener(obj,evt,func) {
    if (obj.attachEvent)
        obj.attachEvent('on' + evt, func);

    else {
        if (obj.addEventListener) {
            obj.addEventListener(evt,func,false);
        }
        else {
            if (obj.eval) {
                obj["on"+evt] = func;
            } else {

            }
        }
    }
}
