var hideDelay = 500;
var showDelay = 10;
var hideTimer;

function whichElement(e)
{
	var targ
	if (!e) var e = window.event
	if (e.target) targ = e.target
	else if (e.srcElement) targ = e.srcElement
	if (targ.nodeType == 3) targ = targ.parentNode // defeat Safari bug
	return targ;
}


function findDropdownId(e)
{
	while (e)
	{
    	//debug(e.tagName+"["+e.id+"] | ");
	 	if (e.id)
		{
			var id = e.id.substr(0,3);
			if (id=="bar" || id=="tab" ||id=="ddn") return e;
		}
  		e = e.parentNode;
	}
	return null;
}

function dropdown(event)
{
	var e = whichElement(event);
	e = findDropdownId(e);
	if (e && e.id)
	{
		e = document.getElementById("ddn"+e.id.substr(3,1));
		if (e) show_elem(e);
		//else hide_elem();
	}
	//else hide_elem();
}

var last_cursor_e = null;
function trackcursor(event)
{
	var e = whichElement(event);
	last_cursor_e = e;
}

var last_visible_e = null;
var last_visible_bg = null;
function show_elem(e)
{
	if (last_visible_e!=null && last_visible_e!=e)
	{
		hide_elem();
	}
	last_visible_bg="";
	if (e!=null)
	{
		var id = e.id.substr(3,1);
		align_dropdown(e,id);

		//setTimeout("show_elem_timed(document.getElementById('"+e.id+"'))",showDelay);

		e.style.visibility = 'visible';
		var bar = document.getElementById("bar"+id);
		if (bar)
		{
			last_visible_bg = bar.style.background;
			//debug("<>bar: "+bar.tagName+"["+bar.id+"] "+last_visible_bg+"\r\n");
			//debug(show_props(bar.style,"<>bar"));
///			bar.style.background = "url('img/box"+id+"bar.png')";
		}
		startDelayHide();
	}
	last_visible_e = e;
}
function show_elem_timed(e)
{
	var id = e.id.substr(3,1);
	var bar = document.getElementById("bar"+id);
	if (bar)
	{
		last_visible_bg = bar.style.background;
///		bar.style.background = "url('img/box"+id+"bar.png')";
	}
	e.style.visibility = 'visible';
}

function hide_elem()
{
	if (last_visible_e!=null)
	{
		//debug(">>"+last_visible_e.tagName+"["+last_visible_e.id+"]\r\n");
		last_visible_e.style.visibility = 'hidden';
		var id = last_visible_e.id.substr(3,1);
		var bar = document.getElementById("bar"+id);
		if (bar)
		{
			//debug("bar: "+bar.tagName+"["+bar.id+"] "+last_visible_bg+"\r\n");
			//debug(show_props(bar.style,"bar"));
///			if (bar) bar.style.background = "url('img/box"+id+"ligh.png')";//" ";//last_visible_bg;
		}
		last_visible_e = null;
		last_visible_bg = "";
	}
}
function delayHide()
{
	var e = findDropdownId(last_cursor_e);
	//debug(" *\r\n");
	if (e && e.id)
	{
		e = document.getElementById("ddn"+e.id.substr(3,1));
		if (e) startDelayHide();
		else hide_elem();
	}
	else hide_elem();

}

function startDelayHide()
{
	if (hideTimer!="undefined") clearTimeout(hideTimer);
	hideTimer = setTimeout("delayHide()",hideDelay);
}
function align_dropdown(e,id)
{
	var cont = document.getElementById("container");
	//debug(show_props(cont.style,"c"));
	var bodytop = document.body.offsetTop + cont.offsetTop
	var top = bodytop + 127 - e.clientHeight - 3;
	var bodyleft = document.body.offsetLeft + cont.offsetLeft
	var left = bodyleft + 1 + 128*(id-1);
	//debugln("left: "+document.body.offsetLeft+" "+cont.offsetLeft);
	if ((left+e.clientWidth)>(771+cont.offsetLeft)) left = cont.offsetLeft + 771 - e.clientWidth - 2;
	if (left<bodyleft) left = bodyleft;
	e.style.top = top;
	e.style.left= left;
}
function menu_init()
{
 	var i = 1;
 	var e;
	while (e = document.getElementById("ddn"+i++))
	{
		var id = e.id.substr(3,1);
		align_dropdown(e,id);
	}
}

//menu_init();

function CreateLink(name,domena,text)
{
zavin = "@"
    if(CreateLink.arguments.length == 2) {
            document.write("<a href='mai"+"lto:"+name+""+zavin+""+domena+"' title='"+name+""+zavin+""+domena+"' onmouseover=''>"+name+""+zavin+""+domena+"</a>")
    } else {
            document.write("<a href='mai"+"lto:"+name+""+zavin+""+domena+"' title='"+name+""+zavin+""+domena+"' onmouseover=''>"+text+"</a>")
    }

}

function debug(text) {}
function debugln(text) {}
function debug_ex(text) {}
function show_props(obj, objName) {}

