var subdir = "en";
var dir = document.location.href;
var NS4 = false;
var NS6 = false;
var newWin = null;
var layerRef;
var layerLeft;
var left_array = [290, 388, 460, 535, 645, 795, 853];
var subLeft_array = [285, 383, 455, 530, 640, 790, 848];
var imagedir="img/";

if (dir.indexOf("file") != -1)
{
	dir = dir.substring(0, dir.lastIndexOf(subdir) + subdir.length + 1);
} else
{
	dir = "/en/";
}

if (!document.all && document.getElementById)
{
	NS6 = true;
}
if (navigator.appName == "Netscape" && document.getElementById == undefined)
{
	NS4 = true;
}

imagedir = dir + "common/img/";

if (NS4 || NS6)
{
	if (NS4)
	{
		layerRef = "document.layers[";
		layerLeft = "].left";
		layerVis = "].visibility";
	} else
	{
		layerRef = "document.getElementById(";	
		layerLeft= ").style.left";
		layerVis = ").style.visibility";		
	}
} else
{
	layerRef = "document.all[";
	layerLeft= "].style.pixelLeft";	
	layerVis = "].style.visibility";	
}

//-------------------About------------
var menu0 = new Array();
menu0.name = '<a href="' + dir + 'about/general.php">Company Info</a>';
menu0.push(new classLink("Success Formula", dir + "about/general.php"));
menu0.push(new classLink("Projects Portfolio", dir + "about/portfolio.php"));
menu0.push(new classLink("Skills Set", dir + "about/skills.php"));
menu0.push(new classLink("News Archive", dir + "about/newsarchive.php"));
menu0.push(new classLink("DigitalXpert Team", dir + "about/team.php"));
menu0.push(new classLink("Our Advantages", dir + "about/advantages.php"));
//alert(menu0.img);

//-------------------Service------------
var menu1 = new Array();
menu1.name = '<a href="' + dir + 'service/development.php">Services</a>';
menu1.push(new classLink("Software Development", dir + "service/development.php"));
menu1.push(new classLink("Integration", dir + "service/integration.php"));
menu1.push(new classLink("Software Re-engineering", dir + "service/reengine.php"));
menu1.push(new classLink("Content Works", dir + "service/content.php"));
menu1.push(new classLink("Audit & Consulting", dir + "service/audit.php"));
menu1.push(new classLink("Support & Maintenance", dir + "service/support.php"));

//-------------------Solutions------------
var menu2 = new Array();
menu2.name = '<a href="' + dir + 'solution/multim.php">Solutions</a>';
menu2.push(new classLink("Multimedia & Web", dir + "solution/multim.php"));
menu2.push(new classLink("Business Intelligence Systems", dir + "solution/bi.php"));
menu2.push(new classLink("Complex Portal solutions", dir + "solution/portal.php"));
menu2.push(new classLink("Other Solutions", dir + "solution/other.php"));

//-------------------Branches------------
var menu3 = new Array();
menu3.name = '<a href="' + dir + 'branch/education.php">Expertise Areas</a>';
menu3.push(new classLink("Education & e-Learning", dir + "branch/education.php"));
menu3.push(new classLink("State sector", dir + "branch/state.php"));
menu3.push(new classLink("Industry", dir + "branch/industry.php"));
menu3.push(new classLink("Medicine", dir + "branch/medicine.php"));
menu3.push(new classLink("Trade", dir + "branch/trade.php"));

//-------------------Partnership------------
var menu4 = new Array();
menu4.name = '<a href="' + dir + 'partner/customers.php">Customers & Partners</a>';
menu4.push(new classLink("Work-For-Hire", dir + "partner/customers.php"));
menu4.push(new classLink("Partnership", dir + "partner/partners.php"));
menu4.push(new classLink("Methods and Procedures", dir + "partner/methods.php"));
menu4.push(new classLink("Testimonials", dir + "partner/testim.php"));

//-------------------Career------------
var menu5 = new Array();
menu5.name = '<a href="' + dir + 'career/career1.php">Career</a>';


//-------------------Contact------------
var menu6 = new Array();
menu6.name = '<a href="' + dir + 'contact/contact1.php">Contacts</a>';

function classLink(title, url)
{
	this.name = title
	this.url = url
}

function createMenu(){
	writeMiddleMenu();
	writeSearchForm();
	window.onresize = showCenter;
}

function writeSearchForm(){
	var up_str		= "";
	var down_str	= "";
	var center_str	= "";
	if (NS4)
	{
		up_str = '<layer id="searchLayer" Z-INDEX=1 TOP=226 VISIBILITY=HIDE>';
		down_str= '</layer>';
	} else
	{
		up_str	= '<div id="searchLayer" style="position: absolute; top: 226; visibility:hidden; z-index:1;">';
		down_str= '</div>';	
	}		
	center_str = '<table border=0 bgcolor="#E0F0FF" cellspacing=0 cellpadding=1>';
	center_str += 	'<tr>';
	center_str += 		'<td>';
	center_str +=			'<table border=0 cellpadding=3 cellspacing=0>';
	center_str += 				'<form method="POST" action="' + dir + 'search.php" name="searchForm">';
	center_str += 					'<tr>';
	center_str +=						'<td bgcolor="#E0F0FF" align="center"><font color="#FFFFFF"><b>Поиск</b></font></td>';
	center_str +=					'</tr>';
	center_str += 					'<tr>';
	center_str +=						'<td bgcolor="#ECF6E8" align="center"><INPUT type="text" size=40 name="text" style="font-size: 8pt"></td>';
	center_str +=					'</tr>';
	center_str += 					'<tr>';
	center_str +=						'<td bgcolor="#ECF6E8" align="center"><INPUT type="submit" value="Найти" style="font-size: 8pt; font-weight: bold"><INPUT type="button" onClick="hideLayer(\'searchLayer\')" value="Закрыть" style="font-size: 8pt; font-weight: bold"></td>';
	center_str +=					'</tr>';
	center_str +=				'</form>';
	center_str +=			'</table>';
	center_str +=		'</td>';
	center_str +=	'</tr>';
	center_str += '</table>';
	document.write(up_str + center_str + down_str);
}

function writeMiddleMenu()
{
	var up_str = '<table border="0" cellspacing="0" cellpadding="0">';
	up_str += 	'<tr>';
	up_str += 		'<td colspan="3" align="left"><img border="0" src="' + imagedir + 'white.gif" width="2" height="20"></td>';
	up_str += 	'</tr>';
	up_str += 	'<tr>';
	up_str += 		'<td colspan="3" bgcolor="#ffffff"><img border="0" src="' + imagedir + 'zero.gif" width="10" height="1"></td>';
	up_str += 	'</tr>';
	up_str += 		'<tr>';
	up_str += 			'<td width="1" bgcolor="#ffffff"><img border="0" src="' + imagedir + 'zero.gif" width="1" height="1"></td>';
	up_str += 			'<td bgcolor="#E0F0FF">';
	up_str += 				'<table border="0" cellspacing="0" cellpadding="0">';
	up_str += 					'<tr>';
	up_str += 						'<td width="7" bgcolor="#E0F0FF"></td>';		
	up_str += 						'<td bgcolor="#E0F0FF"><p class="middlemenu">';

	var down_str = 					'</p>';
	down_str +=						'</td>';
	down_str += 					'<td width="7" bgcolor="#E0F0FF"></td>';			
	down_str += 				'</tr>';
	down_str += 				'<tr>';
	down_str +=						'<td colspan="3" bgcolor="#E0F0FF"><img border="0" src="' + imagedir + 'zero.gif" width="1" height="5"</td>';
	down_str +=					'</tr>';	
	down_str += 			'</table>';
	down_str +=			'</td>';
	down_str += 		'<td bgcolor="#ffffff" width="1"><img border="0" src="' + imagedir + 'zero.gif" width="1" height="1"></td>';
	down_str += 	'</tr>';
	down_str += 	'<tr>';
	down_str += 		'<td colspan="3" bgcolor="#ffffff"><img border="0" src="' + imagedir + 'zero.gif" width="10" height="1"></td>';
	down_str += 	'</tr>';
	down_str += '</table>';			

	for (var i=0; i<left_array.length; i++)
	{
		writeLayer(i, up_str, down_str);	
	}
}

function showLayer(layerName){
	eval (layerRef+'"'+layerName+'"'+layerVis+' = "visible"');
}

function hideLayer(layerName){
	eval (layerRef+'"'+layerName+'"'+layerVis+' = "hidden"');
}

function showMenuItem(index)
{
	//overMenu(index);
	var aMenu= eval("menu"+index);
	if (aMenu.length > 0)
	{
		showLayer("subla"+ index);
	}
}

function hideMenuItem(index)
{
	//alert('hideMenuItem-' + index);
	//outMenu(index);
	var aMenu= eval("menu"+index);
	if (aMenu.length > 0)
	{
		hideLayer("subla"+ index);
	}
}
	
function writeLayer(index, upTemplate_str, downTemplate_str) {
	var top		= 165;
	var up_str	= "";
	var down_str= "";
	var center_str = "";
	var item_array = eval("menu" + index);
	if (NS4)
	{
		up_str = "<layer id=\"la"+ index +"\" Z-INDEX=1 VISIBILITY=HIDE LEFT="+ left_array[index] +" TOP="+ top +" onMouseover=\"showMenuItem("+ index +")\" onMouseout=\"hideMenuItem("+ index +")\">" + item_array.name + "</layer>";
		center_str	= "<layer id=\"subla"+ index +"\" VISIBILITY=HIDE Z-INDEX=2 LEFT="+ subLeft_array[index] +" TOP="+ (top + 17) +" onMouseover=\"showMenuItem("+ index +")\" onMouseout=\"hideMenuItem("+ index +")\">";
		down_str= "</layer>";
	}
	else
	{
		up_str		= "<div class=\"menuGen\" id=\"la"+ index +"\" style=\"position: absolute; visibility:hidden; left: " + left_array[index] + "; top: " + top + "; z-index:1;\"  onmouseover=\"showMenuItem("+ index +")\" onmouseout=\"hideMenuItem("+ index +")\"><A HREF=\"#\">"+item_array.name+"</A></div>";
		center_str	= "<div id=\"subla"+ index +"\" style=\"position: absolute; visibility:hidden; left: " + subLeft_array[index] + "; top: " + (top + 16) + "; z-index:2;\" onmouseover=\"showMenuItem("+ index +")\" onmouseout=\"hideMenuItem("+ index +")\">";
		down_str	+="</div>";	
	}
	center_str += upTemplate_str;
	for (var i=0;i<item_array.length;i++){
		center_str += "<A HREF=\"" + item_array[i].url+"\">" + item_array[i].name + "</A><br>";		
	}	
	center_str += downTemplate_str;
	document.write(up_str + center_str + down_str);
}

function showMenu(){
	showCenter();
	for (var i=0; i<left_array.length; i++)
	{
		showLayer("la"+ i);
	}
}

function showCenter(){
	var left,objLayer;
	var w  = getWidth();
	
	if (w > 950){
		left = parseInt((w - 950) / 2) + 375;
		//if (NS4 || NS6) left -= 10;
		eval (layerRef + '"searchLayer"' + layerLeft + ' = ' + left);
		for (var i=0; i<left_array.length; i++){
			left = parseInt((w - 950) / 2) + left_array[i];
			//if (NS4 || NS6) left -= 10;
			eval (layerRef + '"la' + i + '"' + layerLeft+' = ' + left);
			left = parseInt((w - 950) / 2) + subLeft_array[i];
			//if (NS4 || NS6) left -= 10;
			eval (layerRef + '"subla' + i+'"' + layerLeft + ' = ' + left);
		}
	}
	else
	{
		eval (layerRef + '"searchLayer"' + layerLeft+' = ' + 375);
		for (var i=0; i<left_array.length; i++){
			eval (layerRef + '"la' + i+'"' + layerLeft + ' = ' + left_array[i]);
			eval (layerRef + '"subla' + i + '"' + layerLeft + ' = ' + subLeft_array[i]);
		}	
	}
}	

function getWidth()
{
	/*if (document.all == null) 
	{
		//alert("1");
		return window.innerWidth;		
	}
	else
	{
		alert("2 - " + document.body.clientWidth);	
		return document.body.clientWidth;		
	}*/
	return document.body.clientWidth;
}

function showImage(im,w,h,nm){
	if(newWin!=null) if (!newWin.closed)newWin.close();
	var top = (screen.height-h)/2;
	var left = (screen.width-w)/2;
	var windstatus;
	windstatus='width='+w+',height='+h+',top='+top+',left='+left+',status=no,resizable=no,scrollbars=no';
	newWin=window.open('','',windstatus);
	newWin.document.open();
	newWin.document.writeln('<html>');
	newWin.document.writeln('<head>');
	newWin.document.writeln('<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">');
	if (navigator.appName.indexOf("Netscape")!= -1) newWin.document.writeln('<title></title>');
	else newWin.document.writeln('<title>'+nm+'</title>');
	newWin.document.writeln('</head>');
	newWin.document.writeln('<body bgcolor=\"#FFFFFF\" leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">');
	newWin.document.writeln('<A HREF=\"javascript:close()\"><img border=\"0\" src=\"'+im+'\" width=\"'+w+'\" height=\"'+h+'\"></A>');
	newWin.document.writeln('</body>');
	newWin.document.writeln('</html>');
	newWin.document.close();
}
