///////////////////////////////////////////////////////////
// JavaScript Hierarchy Dynamic 2 levels upper Menu source code
// Support IE and Firefox brousers
// Author: Zvika Gur-Esh; z-soft; go_zvika@netvision.net.il
///////////////////////////////////////////////////////////
var oMenu = null;
var clsMenu = function()
{
	this.menu=null;
	this.firstlevel=null;
	this.ix=-1;
	this.state0=false;
	this.state1=false;
	this.state2=false;
	this.selcel=null;
	this.fly1=null;
	this.fly2=null;
	this.interval=0;
	this.timeout=1000;
	this.isie = true;
	this.ishe = _lang=='HE'?true:false;
	this.curtype = 'curhand';
	if(typeof menuLevels != 'undefined' && menuLevels)this.menu=menuLevels;
	if ( !document.all ) 
	{
		this.isie = false;
		this.curtype = 'curdef';
	}
	this.LBImg = new Image();
	this.RBImg = new Image();
	this.MBImg = new Image();
	this.LBImg.src = "../Shared/Images/HE/Header_new/menuButtonLeft_up.gif";
	this.RBImg.src = "../Shared/Images/HE/Header_new/menuButtonRight_up.gif";
	this.MBImg.src = "../Shared/Images/HE/Header_new/menuButtonMiddle_up.gif";
	this.LBImgOn = new Image();
	this.RBImgOn = new Image();
	this.MBImgOn = new Image();
	this.LBImgOn.src = "../Shared/Images/HE/Header_new/menuButtonLeft_roll.gif";
	this.RBImgOn.src = "../Shared/Images/HE/Header_new/menuButtonRight_roll.gif";
	this.MBImgOn.src = "../Shared/Images/HE/Header_new/menuButtonMiddle_roll.gif";
}
clsMenu.prototype.hilicell=function(src)
{

	//var celltbl = this.selcel.getElementsByTagName("TABLE")[0];
	//if ( celltbl )
	//{
	//	celltbl.cells[0].style.backgroundImage = "url("+this.RBImgOn.src+")";
	//	celltbl.cells[1].style.backgroundImage = "url("+this.MBImgOn.src+")";
	//	celltbl.cells[2].style.backgroundImage = "url("+this.LBImgOn.src+")";
	//}
	var cellDiv = this.selcel.getElementsByTagName("DIV")[0];
	if ( cellDiv )
	{	
		//cellDiv.style.borderBottom = "solid 3px #caea35";
	}
}
clsMenu.prototype.clrcell=function(src)
{
	//var celltbl =  this.selcel.getElementsByTagName("TABLE")[0];
	//if ( celltbl )
	//{
	//	celltbl.cells[0].style.backgroundImage = "url("+this.RBImg.src+")";
	//	celltbl.cells[1].style.backgroundImage = "url("+this.MBImg.src+")";
	//	celltbl.cells[2].style.backgroundImage = "url("+this.LBImg.src+")";
	//}
	var cellDiv = this.selcel.getElementsByTagName("DIV")[0];
	if ( cellDiv )
	{
		//cellDiv.style.borderBottom = "solid 3px #ffffff";
	}
}
clsMenu.prototype.cellover = function(src, ix) {
    if (document.all) event.cancelBubble = true;
    clearTimeout(this.interval);

    this.state0 = true;
    this.selcel = src;
    this.ix = ix;

    this.clrcell(src);
    this.hilicell(src);
    if (this.menu == null) {
        if (typeof menuLevels != 'undefined' && menuLevels) this.menu = menuLevels;
    }
    if (this.menu == null) {
        status = 'this.menu is null';
        return;
    }
    var node = this.menu[ix];
    if (node && node.level && node.level.length) {
        this.drowsub(src, node, 1);
    }
    else if (this.fly1) {
        //this.fly1.style.display = 'none';
        if (this.fly2) {
            //	this.fly2.style.display = 'none';
        }
    }
}
clsMenu.prototype.cellout = function(src, ix) {
    if (document.all) event.cancelBubble = false;
    this.state0 = false;
   
    this.clrcell(src);
 
    if (this.fly1 && this.fly1.style.display != 'none' && !this.state0) {
        this.interval = setTimeout('oMenu.clearsub()', this.timeout);
    }
}
clsMenu.prototype.hilisubcell=function(src)
{
	src.className = 'level2_on ' + this.curtype;
	//src.nextSibling.style.backgroundColor='#535e79';
}
clsMenu.prototype.subcellover=function(src,ix)
{
	if(document.all)event.cancelBubble=true;
	clearTimeout(this.interval);
	
	this.hilicell();
	this.hilisubcell(src);
	//var node = this.menu[this.ix];var nodes = node.level;node = nodes[ix];
	//if(node.level && node.level.length){
	//if(document.all)var div=src.all.tags('DIV')[1];
	//else var div = src.getElementsByTagName("DIV")[1];
	//this.drowssub(div,node,2,ix);}
	//else if(this.fly2&&this.fly2.style.display=='block'){this.fly2.style.display='none';}
}
clsMenu.prototype.subcellout=function(src,ix){this.clrsubcell(src);}
clsMenu.prototype.clrsubcell=function(src)
{
	src.className = 'level2 ' + this.curtype;
	//src.nextSibling.style.backgroundColor='#606f8c';
}
clsMenu.prototype.clearsub = function() {

    if (this.fly1) { this.fly1.style.display = 'none'; }
    if (this.selcel && !this.state0) { this.clrcell(); }
    if (this.fly2 && this.fly2.style.display == 'block') { this.fly2.style.display = 'none'; }
}
clsMenu.prototype.ssubcellout=function(src,ix){this.clrsubcell(src);}
clsMenu.prototype.cellclick=function(url){location.href=url;}
clsMenu.prototype.ssubcellover=function(src,ix){clearTimeout(this.interval);this.hilisubcell(src);}
clsMenu.prototype.subover=function(src,ix){clearTimeout(this.interval);this.hilicell();}
clsMenu.prototype.ssubover=function(src,ix){this.hilicell();}

clsMenu.prototype.ssubout=function(src,ix){this.interval=setTimeout('oMenu.clearsub()',this.timeout);}
clsMenu.prototype.subout=function(src,ix){this.interval=setTimeout('oMenu.clearsub()',this.timeout);}

clsMenu.prototype.drowsub = function(src, node, level, ix) {
    var isSrcImg = false;
    var src1 = src;

    if (src.tagName == "IMG") {
        src1 = src.parentElement.parentElement.parentElement;
        isSrcImg = true;
    }
    if (document.all) var src = src1.all.tags('DIV')[0];
    else var src = src1.getElementsByTagName("DIV")[0];

    var fly = null, j = 0;
    if (level > 2) return;
    if (!this.fly1) {
        this.fly1 = document.createElement('DIV');
        this.fly1.id = 'FLY_1';
        document.body.appendChild(this.fly1);
    }
    var sub = node.level;
    var name_length = 0;
    with ([]) {
        var dh3 = ' onmouseover="oMenu.subover(this,' + j + ')" onmouseout="oMenu.subout(this,' + j + ')" ';
        push('<table ' + dh3 + ' id="tblSUB" class="tb_level2" width="100%" cellpadding="0" cellspacing="0" border="0">');
        for (j = 0; j < sub.length; j++) {
            node = sub[j];
            var url = "";
            var dh = "";

            if (node) {
                if (node.name.length > name_length) name_length = node.name.length;
                if (level > 2) {
                    dh = ' onmouseover="oMenu.subcellover(this,' + j + ');" onmouseout="oMenu.subcellout(this,' + j + ');" ';
                }
                else {
                    dh = ' onmouseover="this.className=this.className+\'_h\';" onmouseout="this.className=this.className.replace(\'_h\',\'\');" ';
                }
                if (node.href) {
                    //dh += ' onclick=oMenu.cellclick(\''+node.href+'\')';
                    url = node.href;
                };
                var st = (j == 0) ? 'border-top:0px;' : ';';
                var arrow = ''; //(node.level&&node.level.length?'second_level_arrow_on':'second_level_arrow_off');
                push('<tr class="tb_level2">');
                push('<td ' + dh + ' class="tb_level2" style="' + st + '">');
                push('<div id="SUB_' + j + '_' + level + '" class="tb_level2"><a id="SUB_A_' + j + '_' + level + '" href="' + url + '" class="tb_level2">' + node.name + '</a></div>');
                push('</td>');
                push('</tr>');
               } 
        }
        push('</table>');
        if ( this.isie )
        	var flyWidth = src.parentElement.offsetWidth + 40; //(this.ishe ? 20 : 24 );
        else var flyWidth = src.parentNode.offsetWidth + 40;
        if (name_length * 8 > flyWidth) flyWidth = (name_length * 8);
        with (this.fly1) {
            innerHTML = join('');
            var nTop = src.offsetTop + 32;
            if (isSrcImg) nTop = src.offsetTop + 42;
            className = 'flydiv';
            style.width = flyWidth + "px";
            
            var le = (src.offsetParent.offsetLeft + src.offsetLeft) +(this.ishe ? (src.parentElement.offsetWidth - parseInt(style.width) + 4) : 0);
            if (isSrcImg) le = (src.offsetParent.offsetLeft + src.offsetLeft) + (this.ishe ? (src.parentElement.offsetWidth - parseInt(style.width) + 4) : 24);
           // alert(le)
            style.left = le + "px";
            style.top = nTop + "px";
            style.display = 'block';
            onmouseenter = function() { oMenu.state1 = true; }
            onmouseleave = function() { oMenu.state1 = false; }
        }
    }
}
clsMenu.prototype.drowssub=function(src,node,level,ix)
{	
	var fly=null,j=0;if(level>2)return;
	if(!this.fly2){this.fly2=document.createElement('DIV');
	this.fly2.id='FLY_2';
	document.body.appendChild(this.fly2);}
	var sub=node.level;with([]){
	var dh3=' onmouseover="oMenu.ssubover(this,'+j+')" onmouseout="oMenu.ssubout(this,'+j+')" ';
	push('<table '+dh3+' id="tblSSUB" style="margin-left:2px;" class="sub_table" width="100%" cellpadding="0" cellspacing="0" border="0">');
	for(j=0;j<sub.length;j++){	
	node=sub[j];
	var dh=' onmouseover="oMenu.ssubcellover(this,'+j+')" onmouseout="oMenu.ssubcellout(this,'+j+')" ';
	var dh2=' onmouseover="oMenu.ssubcellover(this.previousSibling,'+j+')" onmouseout="oMenu.ssubcellout(this.previousSibling,'+j+')" ';
	if(node.href){dh+=' onclick=oMenu.cellclick(\''+node.href+'\')';dh2+=' onclick=oMenu.cellclick(\''+node.href+'\')';};
	var st=(j>0)?'border-top:0px;':';';
	var arrow = '';//(node.level&&node.level.length?'second_level_arrow_on':'second_level_arrow_off');
	push('<tr class="second_level_row handcursor">');
	push('<td '+dh+' class="level2"  style="border-right:0px;'+st+'"><div id="SUB_'+j+'_'+level+'" class="level2">'+node.name+'</div></td>');
	push('<td '+dh2+' class="'+arrow+'" style="border-left: 0px;'+st+'"><img src="../Shared/Images/'+_lang+'/1pix.gif"></td>');
	push('</tr>');}push('</table>');
	with(this.fly2){innerHTML=join('');className='flydiv';
	style.width=this.fly1.offsetWidth;
	style.left=this.fly1.offsetLeft+this.fly1.offsetWidth-3;
	style.top=this.fly1.offsetTop+(ix*20);
	style.display='block';
	onmouseenter = function(){oMenu.state2=true;}
	onmouseleave = function(){oMenu.state2=false;}}}
}
clsMenu.prototype.drow = function() {	/*
	var node=null,i=0;
	with([])
	{
		push('<table class="first_level_table" width="100%" cellpadding="0" cellspacing="0" border="0">');
		push('<tr class="first_level_row">');
		for( var i=0; i<this.menu.length; i++)
		{
			var node = this.menu[i];
			var cls1='first_level_cell_off',cls2='first_level_cell_arrow_off';
			if(i==page_number-1)
			{
				cls1='first_level_cell_on';
				cls2='first_level_cell_arrow_on';
			}
			var dh=' onmouseover="oMenu.cellover(this,'+i+')" onmouseout="oMenu.cellout(this,'+i+')" ';
			var dh2=' onmouseover="oMenu.cellover(this.previousSibling,'+i+')" onmouseout="oMenu.cellout(this.previousSibling,'+i+')" ';
			if(node.href) dh+=' onclick=oMenu.cellclick(\''+node.href+'\')';
			push('<td '+dh+' class="'+cls1+'" valign="top" align="center" style="border:0 solid red;"><div id="MAIN_'+i+'" onmouseover="oMenu.clearsub()" style="height:4px;overflow:hidden;width:100%;margin-bottom:4px;position:relative;z-index:5;"></div>'+node.name+'</td>');
			push('<td '+dh2+' class="'+cls2+'"><img src="../Shared/Images/'+_lang+'/1pix.gif"></td>');
			if(i<this.menu.length-1)push('<td onmouseenter="oMenu.clearsub()" class="first_level_cell_border"><img src="../Shared/Images/'+_lang+'/1pix.gif"></td>');
		}
		push('</tr>');
		push('</table>');
		mainmenu.innerHTML=join('');
	}
	*/
}
