/*	

	NextWeb menu bar javascript code v0.2
	-------------------------------------
	Author: Akos Buzikay [ soka@nextra.hu ]
	Created: 01/28/2001
	Target browsers: IE >= 5, NS >= 4
	Modifications: simplified

*/

var DHTML; /* DHTML support */

var detect; /* for browser detection */
var OS,browser,version,total,thestring; /* for browser detection */

var menuShown = 0;	/* stores which menu is stored right now */
var DefaultYPos = 211; /* Stores the default y position of the menues */
var menuImages = 	new Array(
						new Array(new Image(), new Image(), 156, "465", "130px", "hidden"),
						new Array(new Image(), new Image(), 101, "563", "10px", "hidden"),
						new Array(new Image(), new Image(), DefaultYPos, "367", "210px", "hidden")
					);  /* 6 dimensional array storing the menu images. Should contains as menu arrays, as the number of menu groups */

/*	
	function InitLayers() 
	This function initializes the layers. Hides them and sets default position
*/
function InitLayers()
{

	var myObj; /* stores the selected obj */

	// sniff out DHTML support
	DHTML = (document.getElementById || document.all || document.layers);

	// if Netscape add plus one pixel to top positon
	if (navigator.appName == "Netscape") 
	{                                                  
		if (navigator.appVersion.charAt(0) != '4') 
		{ 
			for (i=0;i<=3;i++) { menuImages[i][2] = 101 }
		}
	}

	if (DHTML) {

		// initalize the menu image objects
		for (i=0;i<=2;i++)
		{
			myObj = getObj("ml" + i)	
			myObj.top = menuImages[i][2]
			myObj.left = menuImages[i][3]
			myObj.width = menuImages[i][4]
			myObj.visibility = menuImages[i][5]
			menuImages[i][0].src = "/tmpl/agroforras/img/mg" + i + ".jpg";
			menuImages[i][1].src = "/tmpl/agroforras/img/mg" + i + "sel.jpg";
		}

		if (document.layers)
		{
			/* Netscape does not care the event handlers in the div declarations so these are necessairy :( */

			document.layers["ml0"].captureEvents(Event.MOUSEOUT|Event.MOUSEOVER);
			document.layers["ml0"].onmouseout = fnDivMouseOut0;
			document.layers["ml0"].onmouseover = fnDivMouseOver0;
			document.layers["ml1"].captureEvents(Event.MOUSEOUT|Event.MOUSEOVER);
			document.layers["ml1"].onmouseout = fnDivMouseOut1;
			document.layers["ml1"].onmouseover = fnDivMouseOver1;
			document.layers["ml2"].captureEvents(Event.MOUSEOUT|Event.MOUSEOVER);
			document.layers["ml2"].onmouseout = fnDivMouseOut2;
			document.layers["ml2"].onmouseover = fnDivMouseOver2;
			document.layers["ml3"].captureEvents(Event.MOUSEOUT|Event.MOUSEOVER);
			document.layers["ml3"].onmouseout = fnDivMouseOut3;
			document.layers["ml3"].onmouseover = fnDivMouseOver3;
			document.layers["ml4"].captureEvents(Event.MOUSEOUT|Event.MOUSEOVER);
			document.layers["ml4"].onmouseout = fnDivMouseOut4;
			document.layers["ml4"].onmouseover = fnDivMouseOver4;
			
		}
	}
}


/* General event catcher functions */
function fnImgMouseOver(nImg)
{
	SelectImage(nImg);
	ShowMenu(nImg);
}

function fnImgMouseOut(nImg)
{
	DeselectImage(nImg);
	HideMenu(nImg);	
}

function fnDivMouseOver(nDiv)
{
	SelectImage(nDiv);
	ShowMenu(nDiv);
}

function fnDivMouseOut(nDiv)
{
	DeselectImage(nDiv);	
	HideMenu(nDiv);
}


/* These almost empty declarations are needed for Netscape to work, as there is no way to pass a parameter to a function when the browser invokes an event handler function */
function fnDivMouseOut0() {fnDivMouseOut(0);}
function fnDivMouseOver0() {fnDivMouseOver(0);}
function fnDivMouseOut1() {fnDivMouseOut(1);}
function fnDivMouseOver1() {fnDivMouseOver(1);}
function fnDivMouseOut2() {fnDivMouseOut(2);}
function fnDivMouseOver2() {fnDivMouseOver(2);}
function fnDivMouseOut3() {fnDivMouseOut(3);}
function fnDivMouseOver3() {fnDivMouseOver(3);}
function fnDivMouseOut4() {fnDivMouseOut(4);}
function fnDivMouseOver4() {fnDivMouseOver(4);}



/*	
	function SelectImage(nImg) 
	This function sets the source of the image with number nImg to the selected version 
*/
function SelectImage(nImg)
{
	document.images["mg" + nImg].src = menuImages[nImg][1].src;
}


/*
	function DeselectImage(nImg) 
	This function sets the source of the image with number nImg to the deselected version 
*/
function DeselectImage(nImg)
{
	document.images["mg" + nImg].src = menuImages[nImg][0].src;
}


/*
	function ShowMenu(nMenu) 
	This function shows the menu with number nMenu and sets the menuShown variable
*/
function ShowMenu(nMenu)
{
	var myObj;
	menuShown = nMenu;
	myObj = getObj("ml" + nMenu)
	myObj.visibility = "visible";
}


/*
	function HideMenu(nMenu) 
	This function hides the menu with number nMenu and clears menuShown variable
*/
function HideMenu(nMenu)
{
	var myObj;
	menuShown = -1;
	myObj = getObj("ml" + nMenu)
	myObj.visibility = "hidden";
}


/*
	function getObj(name)
	This function always passes back the DIV object regarding to the DHTML support in the browser
*/
function getObj(name)
{
	if (document.getElementById)
	{
		return document.getElementById(name).style;
	}
	else if (document.all)
	{
		return document.all[name].style;
	}
	else if (document.layers)
	{
		return document.layers[name];
	}
}
