//  Рисуем начальны?те?сл?, исхо? из типа браузера
function layer_start(id,width,height,top,left,zindex,bgcolor){ 
if(navigator.appName == "Netscape"){ 
layr='<layer id="'+id+'" width="'+width+'" height="'+height+'" z-index="'+zindex+'" top="'+top+'" left="'+left+'" visibility="hide" ';
}else{ 
layr='<div id="'+id+'" style="position:absolute; left:'+left+'px; top:'+top+'px; width:'+width+'px; height:'+height+'px; z-index:'+zindex+'; border: 1px none #000000; visibility:hidden;" ';
} return (layr);}

//  Рисуем конечный те?сл?, исхо? из типа браузера
function layer_end(){ 
if(navigator.appName == "Netscape"){layr="<\/layer>";}else{ layr="<\/div>";} 
return (layr);}


var layerRef="null";
var styleSwitch="null";
var lastMenu="null";
var menus = new Array("Layer1","Layer2","Layer3","Layer4","Layer5");
var timeoutid = null;

// Опреде?ем ти?браузера, исхо? из этог?устанавливае?правил?обращения ?сл??
function init()
{
if(navigator.appName == "Netscape")
{layerRef= "document.getElementById"; styleSwitch=".style";} else{layerRef= "document.all"; styleSwitch=".style"; } 
} 
// Отображаем слой по ег?ID
function ShowL(layerName,number,MenuN)
{
if( styleSwitch == "null" ) return;
if( timeoutid != null ) clearTimeout( timeoutid );
if( lastMenu == layerName ) return;
else lastMenu = layerName;
var c = getAnchorPosition(MenuN);
left=c.x-12;
if(number == menus.length ) {
	// Попытать? определить координату исхо? из ширины меню
	//hdr = getAnchorPosition(layerName);
	hdr = eval( layerRef+'("'+layerName+'")'+styleSwitch+'.width' );
	hdr = parseInt(hdr);

	ttl = getAnchorPosition('title'+(number));
	//alert( hdr-ttl.w );
	if( ttl.w != null ) {
		left = c.x + ttl.w - hdr - 4;
	} else {
		left=c.x-86;
	}
}
vtop=c.y-9;
for(i=0;i<menus.length;i++) { 
eval(layerRef+'("'+menus[i]+'")'+styleSwitch+'.visibility = "hidden"');
vari = "javascript:ShowL('"+menus[i]+"',"+i+")"; 
//document.links[i].href = vari; 
} 
eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility = "visible";');
//alert(left);
eval(layerRef+'("'+layerName+'")'+styleSwitch+'.left = "'+left+'"');
eval(layerRef+'("'+layerName+'")'+styleSwitch+'.top = "'+vtop+'"');
vari =" javascript:HideL('"+layerName+"',"+number+")"; 
//document.links[number].href = vari; 
if( eval( layerRef+'("jumper")!=null' ) ) {
	eval(layerRef+'("jumper")'+styleSwitch+'.visibility = "hidden";');
}
}
function TimeoutHideL(layerName, number) {
if( timeoutid != null ) clearTimeout( timeoutid );
	timeoutid = setTimeout( 'HideL("'+layerName+'",'+number+');', 500 );
}

//  Скрываем слой по ег?ID
function HideL(layerName,number){ 
lastMenu = "null";
eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility = "hidden"');
vari = "javascript:ShowL('"+layerName+"',"+number+")"; 
//document.links[number].href = vari;
if( eval( layerRef+'("jumper")!=null' ) ) {
	eval(layerRef+'("jumper")'+styleSwitch+'.visibility = "visible";');
}
} 

function LinkNew(){ 
for(i=0;i<menus.length;i++){ 
vari = "javascript:ShowL('"+menus[i]+"',"+i+")"; 
document.links[i].href = vari; 
} 
} 

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	var w=0,h=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		w = document.all[anchorname].offsetWidth;
		h = document.all[anchorname].offsetHeight;
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=o.offsetLeft; y=o.offsetTop; // x=o.offsetHeight;
		x=AnchorPosition_getPageOffsetLeft(document.getElementById(anchorname));
		y=AnchorPosition_getPageOffsetTop(document.getElementById(anchorname));
		w = document.getElementById(anchorname).offsetWidth;
		h = document.getElementById(anchorname).offsetHeight;
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		w = document.all[anchorname].offsetWidth;
		h = document.all[anchorname].offsetHeight;
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; coordinates.w=0; coordinates.h=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		w = document.anchors[i].width;
		h = document.anchors[i].height;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	coordinates.w=w;
	coordinates.h=h;
	return coordinates;
	}


// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	if( el == null ) return 0;
	//if( el == undefined ) return 0;
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	if( el == null ) return 0;
	//if( el == undefined ) return 0;
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

init ();