var dom = (document.getElementById)? true : false;
var isMSIE = (document.all)? true : false;
var isNN6 = (dom && !document.all)? true : false;
var isNN4 = (navigator.appName.indexOf("Netscape") >= 0 && parseInt(navigator.appVersion) == 4 ) ? true : false;

var TimeOut1;


function MenuItem(name,pos){

	this.lines = new Array();
	
	this.name = name;
	this.position = pos;
	this.zIndex = 100;
	
	
	this.make = drawDiv;
	this.addLine = addStLine;
}
function addStLine(url,name) {this.lines[this.lines.length] = new Array(url,name);}

function drawDiv(){
	var str = '';
	
	if(isNN4){
		str +='<layer visibility="hide" name="'+this.name+'" z-index="'+this.zIndex+'" top="0" left="0" width="100%">';
	}
	else{
		str+='<div id='+this.name+' style="position:absolute;top: 0; left: 0; width: 100%; z-index: '+this.zIndex+';  visibility: hidden; ">';
	}
	
	
		if(this.position==1){
	str +='<table cellspacing="0" cellpadding="0" border="0" width="100%">';
	str +='<tr>';
    str +='<td width="32%"><img src="img/pixel.gif" alt="" width="181" height="2" border="0"></td>';
    str +='<td>';
	}
	else{
	
	str +='<table cellspacing="0" cellpadding="0" border="0" width="100%">';
	str +='<tr>';
    str +='<td width="32%"><img src="img/pixel.gif" alt="" width="247" height="5" border="0"></td>';
    str +='<td width="68%">';
	str +='<table cellspacing="0" cellpadding="0" border="0" width="100%">';
	str +='<tr>';
	str +='<td width="54%"><img src="img/pixel.gif" alt="" width="130" height="1" border="0"></td>';
	str +='<td>';
	
	}
	
			str +='<table width="171px" cellpadding="2" cellspacing="0" bgcolor="white" border="0">';
			str +='<tr>';
			str +='<td>';
			str +='<table width="100%" cellspacing="0" cellpadding="0" border="0">';
			str +='<tr>';
			str +='<td bgcolor="#9FA8B0"><img src="img/pixel.gif" alt="" width="1" height="5" border="0"></td>';
			str +='<td width="100%" bgcolor="#A32526"><img src="img/pixel.gif" alt="" width="164" height="1" border="0"></td>';
			str +='<td bgcolor="#9FA8B0"><img src="img/pixel.gif" alt="" width="1" height="5" border="0"></td>';
			str +='</tr>';	
			str +='<tr>';
			str +='<td bgcolor="#9FA8B0"><img src="img/pixel.gif" alt="" width="1" height="5" border="0"></td>';
			str +='<td width="100%" bgcolor="white" align="center">';								
			str +='<table cellspacing="0" cellpadding="0" border="0" width="141px">';
			str +='<tr>';
			str +='<td><img src="img/pixel.gif" alt="" width="1" height="8" border="0"></td>';
			str +='</tr>';
	
	
	
	
		
		
		for (i = 0; i < this.lines.length; i++){
			//str+=this.lines[i][1]+'<br>';
			
			str+='<tr>';
			str+='<td height="18px" valign="middle"><small><a href="'+this.lines[i][0]+'" onmouseout="D_hide(\''+this.name+'\')" onmouseover="sshow(\''+this.name+'\'); ">'+this.lines[i][1]+'</a></small></td>';
			//str+='<td height="18px" valign="middle"><small><a href="javascript:void(0);" onclick="showY()">'+this.lines[i][1]+'</a></small></td>';
			str+='</tr>';
			if(i==this.lines.length-1) break;
			str+='<tr>';
			str+='<td bgcolor="#9FA8B0"><img src="img/pixel.gif" alt="" width="141" height="1" border="0"></td>';
			str+='</tr>';
		}
		
		str +='<tr>';
		str +='<td><img src="img/pixel.gif" alt="" width="1" height="12" border="0"></td>';
		str +='</tr>';
		str +='</table>';					
		str +='</td>';
		str +='<td bgcolor="#9FA8B0"><img src="img/pixel.gif" alt="" width="1" height="5" border="0"></td>';
		str +='</tr>';
		str +='<tr>';
		str +='<td colspan="3" bgcolor="#9FA8B0"><img src="img/pixel.gif" alt="" width="1" height="1" border="0"></td>';
		str +='</tr>';							
		str +='</table>';					
		str +='</td>';
		str +='</tr>';
		str +='</table>';
		
		
	if(this.position==1){
	str +='</td>';
	str +='<td width="68%"><img src="img/pixel.gif" alt="" width="1" height="2" border="0"></td>';
	str +='</tr>';
	str +='</table>';
	}
	else{	
	str +='</td>';
	str +='<td width="46%"><img src="img/pixel.gif" alt="" width="1" height="1" border="0"></td>';
	str +='<td><img src="img/pixel.gif" alt="" width="129" height="5" border="0"></td>';
	str +='</tr>';
	str +='</table>';
	str +='</td>';
	str +='</tr>';
	str +='</table>';	
	}	
	
	
	
	if(isNN4){
		str+='</layer>';
	}
	else{
		str+='</div>';
	}
	
	return str;
}





function MenuCollection(){
	this.divs = new Array();
	this.make = menuMake;
	this.addMenu = menuAddMenu;
}
	
function menuAddMenu(newMenu) {this.divs[this.divs.length] = newMenu;}

function menuMake(){
	strFul = "";
	
	
	for (j = 0; j < this.divs.length; j++){
	
		this.divs[j].zIndex = 100+j; 
		
		strFul += this.divs[j].make();
		//strFul += this.divs[0]; //у эл-тов массива должен быть метод make()
		//strFul += this.divs.length;
		//alert(strFul);
	}
		document.write(strFul);
}



function hide(obj) {
clearTimeout(TimeOut1);
	if (isNN4)   document.layers[obj].visibility = "hide";
	if (isNN6)   document.getElementById(obj).style.visibility = "hidden";
	if (isMSIE && document.all[obj])  document.all[obj].style.visibility = "hidden";
}


function D_hide(obj) {
TimeOut1=setTimeout("hide('"+obj+"')",600);
}



function show(obj) {

//alert(obj);

for (var u=0; u < allMenus.divs.length; u++) {
	 //alert(allMenus.divs[u].name);
	 hide(allMenus.divs[u].name);
}

if (isNN4)   {
	document.layers[obj].top = tempY;
	//document.layers[obj].left = mX;
	document.layers[obj].visibility = "show";
}
if (isNN6)   {
	document.getElementById(obj).style.top = tempY;
	//document.getElementById(obj).style.left = mX;
	document.getElementById(obj).style.visibility = "visible";
}
if (isMSIE && document.all[obj]) {
	if(document.all[obj].style.visibility =="hidden"){
		document.all[obj].style.top =  tempY;
	}
	//document.all[obj]
	document.all[obj].style.visibility ="visible";
}
	

}


function sshow(obj) {

//alert(obj);

for (var u=0; u < allMenus.divs.length; u++) {
	 hide(allMenus.divs[u].name);
}

if (isNN4)   {	
	document.layers[obj].visibility = "show";
}
if (isNN6)   {	
	document.getElementById(obj).style.visibility = "visible";
}
if (isMSIE && document.all[obj]) {	
	document.all[obj].style.visibility ="visible";
}
	

}







//mouse handle

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0



function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0;}
  if (tempY < 0){tempY = 0;}  
  return true;
}

function showY(){
	alert(tempY);
}
