var bw = "IE"; 
 if(navigator.userAgent.indexOf('Opera') != -1){
	bw = "OP";
	if(navigator.userAgent.indexOf('Opera 6') != -1)
		var noDHTML=1;
}else if(navigator.userAgent.indexOf("Mozilla/5") != -1 || navigator.userAgent.indexOf("Gecko") != -1){
	bw = "MZ";
}else if(!document.all){
	alert("Please use Internet Explorer 4+ or Mozilla/Netscape 7 or Opera 6+");
	bw = "MZ";
}
var ima = new Array();
function preloadImg(str)
{
		var imgs = str.split(";");

		 for(var i=0; i<imgs.length; i++)
		 {
				var im = ima[ima.length] = new Image();
				im.src = imgs[i];
		 }
}  // preloadImg

function menuMouseOver(obj)
{
		if(!noDHTML){
		if(bw=="IE"){
			if(obj.bg=='img')obj.background="/images/controlPanelSelected-bg.gif";
    	else obj.bgColor= '#ECECEC'; //'#0C65FF'
			if(obj.all.bullet){
				var img = obj.all.bullet.src;
				img = img.split("-");
				img[img.length -1] = "red.gif";
				obj.all.bullet.src = img.join("-");
			}
		}else if(bw=="MZ" || bw=="OP"){
			if(obj.getAttribute('bg')=="img"){obj.setAttribute("background","/images/controlPanelSelected-bg.gif"); }
    	else obj.bgColor= '#ECECEC'; //'#0C65FF'
				if(obj.getElementsByTagName("IMG")[0]){
					var im = obj.getElementsByTagName("IMG")[0];
					if(im.getAttribute("id") == "bullet")
					{
						var img = im.getAttribute("src");
						img = img.split("-");
						img[img.length -1] = "red.gif";
						im.setAttribute("src",img.join("-"));
					 }
				}
		}
		}
		if(window.hPDm && (obj.t=='PD' || obj.getAttribute('bg')=="img")){
			clearTimeout(window.hPDm);
			window.hPDm = false;
		}
}

function menuMouseOut(obj)
{
		if(!noDHTML){
		if(bw=="IE"){
        if(obj.bg=='img' )obj.background='#ECECEC';
        else obj.bgColor=(obj.pcolor ? obj.pcolor :'#ECECEC'); //343E7F
				if(obj.all.bullet){
					var img = obj.all.bullet.src;
					img = img.split("-");
					img[img.length -1] = "blue.gif";
					obj.all.bullet.src = img.join("-");
				}
		}else if(bw=="MZ" || bw=="OP"){
        if(obj.getAttribute('bg')=="img")obj.setAttribute("background","#ECECEC");
        else  obj.bgColor= (obj.getAttribute("pcolor") ? obj.getAttribute("pcolor") : '#ECECEC');
				var im = obj.getElementsByTagName("IMG")[0];
				if(im){
					if(im.getAttribute("id") == "bullet")
					{
						var img = im.getAttribute("src");
						img = img.split("-");
						img[img.length -1] = "blue.gif";
						im.setAttribute("src",img.join("-"));
					 }
				}
		}
		}
	if(!window.hPDm)window.hPDm =  setTimeout("hideAllpdMenu()",1000);
}


function menuMouseClick(obj)
{
		if(!noDHTML){
		if(bw=="IE"){
        if(obj.bg=='img' )obj.background='#ECECEC';
        else obj.bgColor=(obj.pcolor ? obj.pcolor :'#ECECEC'); //343E7F
				if(obj.all.bullet){
					var img = obj.all.bullet.src;
					img = img.split("-");
					img[img.length -1] = "blue.gif";
					obj.all.bullet.src = img.join("-");
				}
		}else if(bw=="MZ" || bw=="OP"){
        if(obj.getAttribute('bg')=="img")obj.setAttribute("background","#ECECEC");
        else  obj.bgColor= (obj.getAttribute("pcolor") ? obj.getAttribute("pcolor") : '#ECECEC');
				var im = obj.getElementsByTagName("IMG")[0];
				if(im){
					if(im.getAttribute("id") == "bullet")
					{
						var img = im.getAttribute("src");
						img = img.split("-");
						img[img.length -1] = "blue.gif";
						im.setAttribute("src",img.join("-"));
					 }
				}
		}
		}
	if(!window.hPDm)window.hPDm =  setTimeout("hideAllpdMenu()",1000);
}

function menu(text,href,dID)
{
        this.text=text;
        this.href = href;
        this.dID = dID;
		var d;
		if(bw == "IE") d = document.all[dID];
		else if(bw == "MZ" || bw == "OP") d=document.getElementById(dID);
		if(!d || !d.innerHTML) this.allOpen=1;
        this.addMenu = addMenu;
        this.draw = draw;
        this.children = new Array();
        this.trazd=false;
        this.root=this;
		this.parent=this;
          this.mOver='menuMouseOver(this)';
        this.mOut='menuMouseOut(this)';
     
        this.level = 0;
        this.opened=true;
        this._open =_open;
		this.closeR = closeR;
        this.isOpen = new Array(10);
        for(var i=0; i< 10; i++)this.isOpen[i] = false;
        if(!window.umID)window.umID=0;
        window.umID = this.id = window.umID*1+1;
        if(!window.allMenuIt)
          window.allMenuIt = new Array();
        window.allMenuIt[this.id] = this;
}



function addMenu(text,href,isopen)
{

        var m = new menu(text);
        m.trazd = this.trazd;
		m.href = href;
        m.root = this.root;
		m.parent = this;
        m.opened = isopen;
		m.level = this.level+1;
		if(m.opened && m.root.isOpen){
			m.root.isOpen[m.level] = m;
			var e = m.parent;
			
			while(e.level > 0){
				m.root.isOpen[e.level]=e;
				e = e.parent;
			}
		}
        this.children[this.children.length] = m;
        return m;
}

function closeR(obj)
{
	obj.opened=false;
	for(var i=0; i < obj.children.length; i++){
		closeR(obj.children[i]);
	}
}

function draw(style,level)
{
        var str = "";
        this.style = style;
        if(style=="left") //for left  menu
        {
                if(this.text){
                        if(this.root.trazd) ;
                        else this.root.trazd = true;
                        str += '<table cellpadding=0 cellspacing=0 width=170 border=0 ;">';
                        str += '<tr>'
                        str += '<td '+((this.level==3 || (this.level==2 && this.href) )? "bgcolor='#ECECEC' pcolor='#ECECEC' " :  (this.level==2 ? "bgcolor='#ECECEC' pcolor='#ECECEC'" :  ""))+' width=170 class=bluel onmouseover='+this.mOver+' onmouseout='+this.mOut+' onclick="window.allMenuIt[\''+this.id+'\']._open(\'left\');"><div z-index:39 style="padding : 1px 1px 1px '+((this.level==2 && !this.href ) ? 15 : (this.level==3 || (this.level==2 && this.href)) ? 25 : 5+this.level*10)+'px; cursor: '+(this.children.length == 0 ? "hand" : "default")+'">'; //Left 3 menu
						if(this.level==1) str += "<b>";
						if(this.level==2 && !this.href) str += "<table border='0' width=150 ><tr><td valign='top'><img id='bullet' src='.."+(this.opened ? "/img/arrow.gif" : "arrow.gif")+"' border='0'/></td><td class='bluel'>";
						if(this.level==3 || (this.level==2 && this.href)) str += "<table border='0' width=120 cellspacing=0 cellpadding=0><tr><td class='bluel' style='padding-left:3px; text-align: left;align='left' width=100%>";
						str += this.text;
						if(this.level==3) str += "</td></tr></table>";
						if(this.level==2) str += "</td></tr></table>";
						if(this.level==1) str += "</b>";
						str += '</div></td>';
                        str += '</tr></table>';
                }
                if(this.opened){
                        for(var i=0; i< this.children.length; i++)
                        {
                                str += this.children[i].draw(style,level+1);
                        }
                }
                if(this.root == this && this.dID){
				if(!this.root.allOpen){
                        if(bw=="IE"){
                                document.all[this.dID].innerHTML = str;
                        }else if(bw=="MZ" || bw=="OP"){
                                document.getElementById(this.dID).innerHTML = str;
                        }
									}else{document.write(str);}
                }
                        }else if(style == "topPD"){
                                if(level==0){
                                        str += "<table cellpadding=0 cellspacing=0 border=0 id='tmCont'><tr>";
                                }else if(level==1)
                                {
                                        str += "<td><img src=/images/controlPanel-separator.gif width=2 height=30 border=0></td>";
                                        str += "<td bg='img' t='PD' onmouseover='"+this.mOver+"; window.allMenuIt[\""+this.id+"\"]._open(\"topPD\",event,\"over\");' onmouseout="+this.mOut+" onclick=\"window.allMenuIt[\'"+this.id+"\']._open(\'topPD\',event,\'go\');\"><div z-index:39 style='padding : 5px 6px 5px 6px; cursor: "+(this.href ? "hand" : "default")+"' class=controlPanel>"+this.text;
                                }else{
                                        str += '<table cellpadding=0 cellspacing=0 width="170" style="Border-Top:#A1ACD6 1px solid;" border='+(noDHTML ? "1" : "0")+'  >';
                                        str += '<tr>'
                                        str += '<td bg="color" bgcolor="#343E7F" t="PD" class=controlPanelVertical onmouseover=\''+this.mOver+'; window.allMenuIt[\"'+this.id+'\"]._open(\"topPD\",event,\"over\");\' onmouseout=\''+this.mOut+'\' onclick="window.allMenuIt[\''+this.id+'\']._open(\'topPD\',event,\'go\');"><div z-index:39 style="padding : 5px 10px 5px 10px; cursor: '+(this.href ? "hand" : "default")+'">';
                                        str +=this.text;
                                        str +='</div></td>';
                                        str += '</tr>';
                                        str += '</table>';
                                }
                                if( this.children.length >0){
                                        if(level >=1){
                                                str += "<div z-index:39 style='border: none; height:15px;  position: absolute; background-color : #343E7F; left: -1000px; top: -1000px;' id='mb_"+this.id+"'>";
                                        }
                                        for(var i=0; i< this.children.length; i++)
                                        {
                                                str += this.children[i].draw(style,level+1,i);
                                        }
                                        if(level >=1){
                                                str += "</div>";
                                         }
                                }
                                if(level==0){
				str += "<td><img src=/images/controlPanel-separator.gif width=2 height=30 border=0></td>";
                                  str += "</tr></table>";
					if(!this.root.allOpen){
                                  	if(bw=="IE"){
                                  		document.write(str);
                                    	document.all[this.dID].innerHTML = str;
                                  	}else if(bw=="MZ" || bw=="OP"){
                                    	document.getElementById(this.dID).innerHTML = str;
                  		           	}
								}else{document.write(str);}
                        }
        }
        return str;
}

function _open(style,evnt,act)
{
        if(style=="left"){
                if(this.children.length >0 && !noDHTML){
					if(this.root.isOpen[this.level] && this.root.isOpen[this.level].opened && this.root.isOpen[this.level] != this){
					this.root.isOpen[this.level].opened = false;
					var i=this.level;
					
					var p=this;
					while(i >=0){
						if(this.root.isOpen[i] !=p){
							if(this.root.isOpen[i])
							closeR(this.root.isOpen[i]);
							i--; p = p.parent;
						}else{break;}
					}
				}
				//alert(12);
                this.opened = !this.opened;
				if(this.opened){
					this.root.isOpen[this.level] = this;
				}
                this.root.draw(style,0);
				cancel();
                }else{
                   if(this.href) document.location=this.href;
                   else alert("Простите, страница \""+this.text+"\" находиться в разработке.");
                }
        }else if(style=="top"){
                if(this.children.length ==0 && act=='go'){
                        if(this.href) document.location=this.href;
                        else alert("Простите, страница \""+this.text+"\" находиться в разработке.");
                }
                if(this.root.isOpen[this.level] && this.root.isOpen[this.level] != this && act=='over')
                {
                                this.root.isOpen[this.level]._open(style,evnt,'close');
                }
                this.opened = true;
                if(document.all)obj = document.all["mb_"+this.id];
                if(!obj) return;
                if(this.opened){
                        var obj;
                        var e = document.all.tmCont;
                        x = (this.level == 1 ? 0 : e.offsetWidth); y = e.offsetHeight +2;
                        while(e){
                                        x+= e.offsetLeft;
                                        y +=e.offsetTop;
                                        if(e.style.position == "absolute")
                                        {
                                                y = 2;
                                                x= (e.clientWidth*2+e.offsetLeft > document.body.clientWidth ? -e.clientWidth : e.clientWidth);
                                                break;
                                        }
                                        e= e.parentElement;
                        }
                        obj.style.left=x;
                        obj.style.width = document.all.tmCont.clientWidth+20;
                        obj.style.top=y;
                        this.root.isOpen[this.level]=this;
                }
                if(act == 'close'){
                        for(var i=0; i< this.children.length; i++)
                        {
                                this.children[i]._open(style,evnt,'close');
                        }
                        obj.style.left="-1000px";
                        obj.style.top="-1000px";
                        this.root.isOpen[this.level]=false;
                }
        }else if(style=="topPD"){
                if(this.href && act=='go' && !this.root.cancel){
                        if(this.href) document.location=this.href;
                        else alert("Простите, страница \""+this.text+"\" находиться в разработке.");
						this.root.cancel = 1;
                }
                if(this.root.isOpen[this.level] && this.root.isOpen[this.level] != this && act=='over')
                {
                                this.root.isOpen[this.level]._open(style,evnt,'close');
                }
                this.opened = true;
                if(bw=="IE")obj = document.all["mb_"+this.id];
								else if(bw=="MZ" || bw=="OP") obj = document.getElementById("mb_"+this.id);
                if(!obj) return;
                if(this.opened){
                        var obj;
                        var e = (obj.parentElement ? obj.parentElement : obj.parentNode);
                        x = (this.level == 1 ? 0 : e.offsetWidth); y = e.offsetHeight +4;
                        while(e){
													if(bw=="IE"){
		                        x += e.offsetLeft;
  	                        y +=e.offsetTop;
    	                      if(e.style.position == "absolute")
      	                    {
        	                  	y = 2;
          	                	x= (e.clientWidth*2+e.offsetLeft > document.body.clientWidth ? -e.clientWidth : e.clientWidth);
            	              	break;
              	            }
														e= e.parentElement ;
													}else if(bw=="MZ" || bw=="OP"){
															if(e.style && e.style.position != "absolute"){
																x += e.offsetLeft;
																y += e.offsetTop;
															}
															e = e.parentNode;

													}
                        }
												        obj.style.left=x-2;
                                obj.style.top=y;
                                this.root.isOpen[this.level]=this;
                        }
                        if(act == 'close'){
                                for(var i=0; i< this.children.length; i++)
                                {
                                        this.children[i]._open(style,evnt,'close');
                                }
                                obj.style.left="-1000px";
                                obj.style.top="-1000px";
                                this.root.isOpen[this.level]=false;
                        }
        }
        //cancel();
}


function cancel(){
			if(!window.event) return;
        window.event.cancelBubble = true;
        window.event.returnValue = false;

}

function hideAllpdMenu( )
{
        //alert(11);
        for(var i=0; i <window.allMenuIt.length; i++){
                if(window.allMenuIt[i] && window.allMenuIt[i].isOpen){
                        var io = window.allMenuIt[i].isOpen;
                        	for(var z=0; z < io.length ; z++) if(io[z] && io[z].style != "left")io[z]._open(io[z].style,'','close');
  	                      }
        }
}  // hideAllpdMenu

function pageOnLoad(){
if(bw=="IE"){
 	document.body.attachEvent("onclick",hideAllpdMenu);
}

}

