dom=(document.getElementById)? true : false;
nn4=(document.layers)? true : false;
ie4=(!dom && document.all)? true : false;
opera = (window.opera)? true : false;

var show_style = (nn4) ? 'show' : 'visible';
var hide_style = (nn4) ? 'hide' : 'hidden';

var currentIndx = -1;
current_menu=-1;
/* for first page only! */
var df=1;

function get_layer(id) {
	return (dom) ? document.getElementById(id).style : ((ie4) ? document.all[id].style : ((nn4) ? document.layers[id] : null));
}

var budilnik=false;
function doMouseOut(){
//	budilnik = setTimeout('hideAll()', 1000);
}

function doMouseOver(){
	if(budilnik)	clearTimeout(budilnik);
}

function showMenu(indx){
	if (!detect_array_element(indx)){
		return false;
	}
	hideAll();

//	doMouseOver()
	detect_submenu_position(indx);
	layer = get_layer('menu'+indx);
	showLayer(layer);
}

function showLayer(layer){
	if(ie4){ layer.pixelTop = positionY; layer.pixelLeft = positionX; }
	else{ layer.top = positionY; layer.left = positionX; }
	layer.visibility = show_style;
}


function detect_submenu_position(indx){
	positionX = (nn4) ? realPositionX('mPos') : realPositionX('mPosDom'); positionX -= 0;
	positionY = (nn4) ? realPositionY('mPos') : realPositionY('mPosDom'); positionY += (nn4)?13:(window.opera)?15:13;
}

function realPositionX(which){
	if (nn4) {
		pos = document.layers[which].pageX
	} else {
		var elem = (dom)? document.getElementById(which) : document.all[which];
		var pos = elem.offsetLeft;
		while (elem.offsetParent != null) {
		elem = elem.offsetParent;
		pos += elem.offsetLeft;
		}
	} return pos;
}

function realPositionY(which) {
	if (nn4) {
		pos = document.layers[which].pageY
	} else {
		var elem = (dom)? document.getElementById(which) : document.all[which];
		var pos = (elem.offsetTop>0)?elem.offsetTop-2:0;
		while (elem.offsetParent != null) {
		elem = elem.offsetParent;
		pos += elem.offsetTop;
		}
	} return pos;
}

function hideAll(){
	for(i=0;i<menuDivId.length;i++){
		layer = get_layer(menuDivId[i]);
		hideLayer(layer);
	}
}

function hideLayer(layer){
	layer.visibility = hide_style;
}

function detect_array_element(indx){
	var detect = false;
	for (i=0;i<menuDivId.length;i++ ){
		if (menuDivId[i]+''=='menu'+indx){
			var detect = true;
		}
	}
	return detect;
}

function showPopupImgWindow(im,w,h,alt){
	imgwindow = window.open('',"_blank","scrollbars=no,resizable=off,width="+w+",height="+h);
	imgwindow.document.open("text/html");
	imgwindow.document.writeln('<html><head><title>'+alt+'<\/title><\/head>');
	imgwindow.document.writeln('<body bgcolor=#ffffff marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" onBlur="self.close();">');
	imgwindow.document.writeln('<div align="left"><a href="javascript:self:close();"><img src="'+im+'" width="'+w+'" height="'+h+'" alt="'+alt+'" border="0"></a></div><\/body><\/html>');
	imgwindow.focus();
}

function showPopupWindow(path,w,h){
	win = window.open(path,"_blank","resize=yes,resizable=yes,menubar=no,status=no,top=0,left=0,scrollbars=yes,width="+w+",height="+h);
	win.focus();
}
