/* ************************************************************************ */
/* Javascript for Stylianos Papathanasopoulos Home Page                                    */
/* ************************************************************************ */

var br;

function init()
{
	// Figure out what kind of browser we have
	if ( navigator.appName.indexOf("Microsoft Internet Explorer") != -1 )  {
		br = "IE";
	}
	else  {
		br = "N";
	}
	// Draw the initial menus for IE
	if ( br == "IE" )  {
		for (var i = 0; i < NUMMENUS; i++)  {
			if ( arrMenu[i][2] > 0 )  {
				doDiv("MenuDD_" + arrMenu[i][0], i, menuLeft, menuTop + (menuHeight + menuPadding) * i, 0);
			}
		}
	}
	// Initialize the images for Netscape et al.
	// else  {
	// }

	return true;
}

function draw_menu(str_on_menu)
{

	if ( br == "IE" )  {
		document.writeln("<table cellpadding=\"5\" cellspacing=\"2\" border=\"0\" width=\"100%\">");
		for (var i=0; i < NUMMENUS; i++)   {
			if ( i == (NUMMENUS-1) )  {
			//	document.writeln("<tr height=35><td>&nbsp;</td></tr>");
			}
			doDivMenu(i, arrMenu[i][0] == str_on_menu);
		}
		document.writeln("</table>");
	}
	else  {
		document.writeln("<table cellpadding=\"0\" cellspacing=\"2\" border=\"0\" width=\"100%\">");
		for (var i=0; i < NUMMENUS; i++)   {
			if ( i == (NUMMENUS-1) )  {
			//	document.writeln("<tr height=35><td>&nbsp;</td></tr>");
			}
			do_menu(i, arrMenu[i][0] == str_on_menu);
		}
		document.writeln("</table>");
	}

	return true;
}

//*---------------------------------------------------
// shows the drop down menu 
// expected arg is active div
//--------------------------------------------------*/
function showDDNav(strMenuID)
{
	var theObj;

	theObj = document.all[strMenuID];
	if ( theObj ) if ( theObj.style.visibility == 'hidden' ) theObj.style.visibility = 'visible';
}

//*---------------------------------------------------
// hides the drop down menu 
// expected arg is active div 
//--------------------------------------------------*/
function hideDDNav(strMenuID) {
	var oMenu;
	
	oMenu = document.all[strMenuID];

	if ( oMenu ) {
		if ( oMenu.style.visibility == 'visible' ) {
			showElement('SELECT');
			oMenu.style.visibility = 'hidden';
		}
	}
}

//*---------------------------------------------------
// hides drop down menu when menu is active
// expected arg is active menu
//--------------------------------------------------*/
function hideDiv()
{
	args = hideDiv.arguments;
	theObj=eval(args[0]);
	theObj.style.visibility = 'hidden';
	
	/* calculate active size of menu
	leftDiv=theObj.offsetLeft +2
	rightDiv=theObj.offsetLeft + theObj.clientWidth -2
	topDiv=theObj.offsetTop +2
	bottomDiv=theObj.offsetTop + theObj.clientHeight -2		
		
	if ( window.event.clientY > bottomDiv || 
	     window.event.clientY < topDiv || 
	     window.event.clientX < leftDiv || 
	     window.event.clientX > rightDiv) {
			theObj.style.visibility = 'hidden';
	} */				
}

//*---------------------------------------------------
// goes to specified url
// expected arg is url 
//--------------------------------------------------*/
function gotoUrl(strURL) {
	location.href = strURL;
}

//*---------------------------------------------------
// shows specified tag
//--------------------------------------------------*/
function showElement(HTMLtag)
{
	for (i = 1; i < document.all.tags(HTMLtag).length; i++)
	{
		obj = document.all.tags(HTMLtag)[i];
		obj.style.visibility = "visible";
	}
}

//*---------------------------------------------------
// build the divs for IE
// expected args are 'div name','x in menudata aray',
// 'menu left coord','top in pixels' 
//--------------------------------------------------*/
function doDiv(divID, x, divLeft, divTop) {
	var outerDivWidth = menuWidth;
	var innerDivWidth = menuWidth - 8;
	var innerDivHeight = menuHeight - 2;

	objDiv = "<div id=\"" + divID + "\" class=\"flyoutMenu\" " + 
		 "style=\"position:absolute; width:" + outerDivWidth + "px; z-index:2; top:"+ divTop +"px; left:" + divLeft + "; visibility:hidden;\" " +
		 "onMouseover=\"showDDNav('"+ divID +"');\" " +
		 "onMouseout=\"hideDiv('" + divID + "');\">";

	for (y = 0; y < arrMenu[x][2]; y++) {
		if ( menuData[x][y][0] != null ) {
			objDiv += "<div id=\"x" + x + "_" + y + "\" " + 
				  "class=\"flyoutMenuLink\" " +
				  "style=\"position:relative; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px; height:" + innerDivHeight + "px; width:" + innerDivWidth + "px; z-index:3;\" " + 
				  "onmouseover=\"toggleClass('x" + x + "_" + y + "', 'flyoutMenuLink_on')\" " +
				  "onmouseout=\"toggleClass('x" + x + "_" + y + "', 'flyoutMenuLink')\" " +
				  "onClick=\"gotoUrl('" + menuData[x][y][1] + "')\">" + 
				  menuData[x][y][0] + "</div>";
		}
	}

	objDiv += "</div>";
	document.write(objDiv);

}

/////////////////////////////////
// Function ----
/////////////////////////////////
function doDivMenu(x, blnOnMenu)  {

	var thisMenuClass = blnOnMenu ? menuClass + "_on" : menuClass;

	var strMenuHTML = "<tr><td height=" + menuHeight + " width=" + menuWidth + " class='" + thisMenuClass + "' id='Menu_" + x + "' ";

	if ( !blnOnMenu || arrMenu[x][2] > 0 ) {
		strMenuHTML += "onmouseover=\"";
		if ( !blnOnMenu	) strMenuHTML += "toggleClass('Menu_" + x + "', '" + menuClass + "_over');";
		if ( arrMenu[x][2] > 0 ) strMenuHTML += " showDDNav('MenuDD_" + arrMenu[x][0] + "');";
		strMenuHTML += "\" ";

		strMenuHTML += "onmouseout=\"";
		if ( !blnOnMenu	) strMenuHTML += "toggleClass('Menu_" + x + "', '" + menuClass + "');";
		if ( arrMenu[x][2] > 0 ) strMenuHTML += " hideDDNav('MenuDD_" + arrMenu[x][0] + "');";
		strMenuHTML += "\" ";
	}

	strMenuHTML += "onclick=\"gotoUrl('" + arrMenu[x][1] + "');\">"; 
	strMenuHTML += arrMenu[x][0] + "\&nbsp;\&nbsp;";

	// Add the arrow image if the menu has a flyout menu
	if ( arrMenu[x][2] > 0 ) strMenuHTML += "<img width=4 height=7 src='" + arrowImg + "' border=0>";
	strMenuHTML += "</td></tr>";

	document.write(strMenuHTML);

}

function toggleClass(strMenuID, strClassName) {
	var oMenu;

	oMenu = document.all[strMenuID];
	oMenu.className = strClassName;		
}


/* ************************************************************************ */
/* NETSCAPE, OPERA, and other non-IE browsers                               */
/* ************************************************************************ */

function do_menu(x, current) 
{
	//var thisMenuClass = blnOnMenu ? menuClass + "_on" : menuClass;	
	var str = " ";
        
	str += "<tr><td height=\"28\" width=\" + menuWidth +\" class=\"menuCell\" style=\"text-align: right; padding-right: 4px;\">";
	
	str += "<a class=\"flyoutMenuLink\" href = '" + arrMenu[x][1] + "' ";
	if ( ! current )  {
        	str += "onmouseover=\"mouseover('" + x + "')\" ";
        	str += "onmouseout=\"mouseout('" + x + "')\" ";
	}
	str += ">";
	str += arrMenu[x][0];

        /*
	if ( current )  {
		str += "<img name='menu" + x + "' border='0' src='" + arrMenu[x][2].src + "' />";
	}
	else  {
		str += "<img name='menu" + x + "' border='0' src='" + arrMenu[x][1].src + "' />";
	} */
	str += "</a>";
	str += "</td></tr>";

	 if ( (arrMenu[x][2] > 0) && current )  {
	str += "<tr><td  width=\" + menuWidth +\" class=\"menuCell\" style=\"text-align: right; padding: 4px 4px 0 0;\">";
		for (var i=0; i < arrMenu[x][2]; i++)  {

			str += "<a href='" + menuData[x][i][1] + "'>";
			str += "&nbsp;&nbsp;"
			str += menuData[x][i][0];
			str += "</a><br><br>";
		}
	 }
	str += "</td></tr>";
	document.write(str);

	return true;
}

function mouseover (x)
{
	var str = "document.menu" + x;
	var image =  eval(str);
	image.src = arrMenu[x][4].src;
}

function mouseout (x)
{
	var str = "document.menu" + x;
	var image =  eval(str);
	image.src = arrMenu[x][3].src;
}

