//================================================
//
//  Slavon.net menu v0,7b "over" lib
//
//================================================


if(typeof HTMLElement!="undefined"){
if(!HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling)             
				this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

/*
 Проверяем не, а не 4й ли это Firefox
 Если да - то не отрабатываем этот кусок
*/
browser = browserDetectNav();
if (browser[0]+browser[1] != "Firefox4" && browser[0]+browser[1] != "Firefox8")
{

if (!HTMLElement.prototype.innerHTML){
	HTMLElement.prototype.innerHTML = function (str) {
	   var r = this.ownerDocument.createRange();
	   r.selectNodeContents(this);
	   r.deleteContents();
	   var df = r.createContextualFragment(str);
	   this.appendChild(df);
	   return str;
	}
	
	HTMLElement.prototype.outerHTML = function (str) {
	   var r = this.ownerDocument.createRange();
	   r.setStartBefore(this);
	   var df = r.createContextualFragment(str);
	   this.parentNode.replaceChild(df, this);
	   return str;
	}
}
}
}

var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

var tttt = "";

function getRef(id) {
    if (isDOM) return document.getElementById(id);
    if (isIE4) return document.all[id];
    if (isNS4) return document.layers[id];
}

function getSty(id) {
    return (isNS4 ? getRef(id) : getRef(id).style);
} 

var menu_show = new Array();
var menu_gen = new Array();
var menu_id = "";
var menu_x = 0;
var menu_y = 0;
var popTimer = 0;
// var menu = new Array();

function Item(pid, text, url, img, img_over, type, ori, div_style, table_style, td_style //, temp1, temp2, ..., tempN
		){
	this.pid = pid;
	this.text = text;
	this.url = url;
	this.img = (img?img:false);
	this.img_over = (img_over?img_over:false);
	this.ori = ori;
	this.type = type;
	this.div_style = (div_style?div_style:false);
	this.table_style = (table_style?table_style:false);
	this.td_style = (td_style?td_style:false);
	this.x = 0;
	this.y = 0;
	this.h = 0;
	this.w = 0;

// !!! Uncoment for arguments !!!
/*	if(Item.arguments.length>10){
		var a = Item.arguments; 
		for(i=1; (i+9)<a.length; i++)
			eval("this.temp" + i + "= a[i+9]");
	}
*/
}

function check_sys(){
	var temp = new Array();
	var i = "";
	var hide;

	temp[temp.length] = menu_status;
	if (menu_status != 0)
		if(menu[menu_status].pid != '')
		{
			i=menu[menu_status].pid;
			temp[temp.length] = i;
			while (menu[i].pid != ''){
				i=menu[i].pid;
				temp[temp.length] = i;
			}
		}
	for(i=0; i<menu_show.length; i++){
	hide = true;
		for(j=0; j<temp.length; j++){
			if(menu_show[i] == temp[j]){
				hide = false;
				break;
			}
		}
		if(hide == true)
		{
			getSty("a" + menu_show[i]).visibility = "hidden";
		}


	}
// ADDED
//`	alert(tttt);

	if(tttt){
	if (getRef("a" + tttt)){
		if (getSty("a" + tttt).visibility == "hidden"){
//			getRef("td_x_" + tttt).style.background = "#0A5F09";
			if (menu[tttt].img && !menu[tttt].div_style)
				getRef("td_y_" + tttt).src = menu[tttt].img;
//			tttt = '';
		}
	}else{
		if(popTimer){
//			getRef("td_x_" + tttt).style.background = "#0A5F09";
			if (menu[tttt].img && !menu[tttt].div_style)
				getRef("td_y_" + tttt).src = menu[tttt].img;
			tttt = '';
		}
	}
	}
// \ADDED
}

function td_menu_over(id){
	clearTimeout(popTimer);
	write_menu_custom(id);
	menu_status = id;
	check_sys();
	popTimer = 0;
// ADDED
//	if (menu[id].pid == 0 && getRef("a" + id)){
//		getRef("td_x_" + id).style.background = "#007500";
//		tttt = id;
//	}
	if (menu[id].pid == 0){
//		getRef("td_x_" + id).style.background = "#007500";
			if (menu[id].img_over && !menu[id].div_style)
			getRef("td_y_" + id).src = menu[id].img_over;
		tttt = id;
	}

// \ADDED
	if (getRef("a" + id) && id != ''){
		getSty("a" + id).visibility = "visible";
		var add = true;
		for(i=0; i<menu_show.length; i++)
			if(menu_show[i] == id)
				add = false;
		if (add == true)
			menu_show[menu_show.length] = id;
	}
	check_sys();
}

function td_menu_out(){
	menu_status = 0;
	clearTimeout(popTimer);
	popTimer = setTimeout('check_sys()', 600);
}

function browserDetectNav(chrAfterPoint)
	{
	var
	    UA=window.navigator.userAgent,       // содержит переданный браузером юзерагент
	    //--------------------------------------------------------------------------------
	    OperaB = /Opera[ \/]+\w+\.\w+/i,     //
	    OperaV = /Version[ \/]+\w+\.\w+/i,   //
	    FirefoxB = /Firefox\/\w+\.\w+/i,     // шаблоны для распарсивания юзерагента
	    ChromeB = /Chrome\/\w+\.\w+/i,       //
	    SafariB = /Version\/\w+\.\w+/i,      //
	    IEB = /MSIE *\d+\.\w+/i,             //
	    SafariV = /Safari\/\w+\.\w+/i,       //
	        //--------------------------------------------------------------------------------
	    browser = new Array(),               //массив с данными о браузере
	    browserSplit = /[ \/\.]/i,           //шаблон для разбивки данных о браузере из строки
	    OperaV = UA.match(OperaV),
	    Firefox = UA.match(FirefoxB),
	    Chrome = UA.match(ChromeB),
	    Safari = UA.match(SafariB),
	    SafariV = UA.match(SafariV),
	    IE = UA.match(IEB),
	    Opera = UA.match(OperaB);
	         
	        //----- Opera ----
	        if ((!Opera=="")&(!OperaV=="")) browser[0]=OperaV[0].replace(/Version/, "Opera")
	                else
	                    if (!Opera=="") browser[0]=Opera[0]
	                        else
	                            //----- IE -----
	                            if (!IE=="") browser[0] = IE[0]
	                                else
	                                    //----- Firefox ----
	                                    if (!Firefox=="") browser[0]=Firefox[0]
	                                        else
	                                            //----- Chrom ----
	                                            if (!Chrome=="") browser[0] = Chrome[0]
	                                                else
	                                                    //----- Safari ----
	                                                    if ((!Safari=="")&&(!SafariV=="")) browser[0] = Safari[0].replace("Version", "Safari");
	//------------ Разбивка версии -----------
	 
	    var
	            outputData;                                      // возвращаемый функцией массив значений
	                                                             // [0] - имя браузера, [1] - целая часть версии
	                                                             // [2] - дробная часть версии
	    if (browser[0] != null) outputData = browser[0].split(browserSplit);
	    if ((chrAfterPoint==null)&&(outputData != null))
	        {
	            chrAfterPoint=outputData[2].length;
	            outputData[2] = outputData[2].substring(0, chrAfterPoint); // берем нужное ко-во знаков
	            return(outputData);
	        }
	            else return(false);
	}
