/*
 * Navigation Indicator
 * by Rober Reinhard
 *
 * Sets the appropriate images in the navigation
 * All three images should have the same size.
 *
 * put the following in the head 
 * <script language="JavaScript1.2" src="ScriptPath/NavigInd.js"></script>
 * where ScriptPath is the path, where the NavigInd.js is located
 *
 * Put the onload into the <body> tag:
 * onload="initNavInd('imagePath','imageNr');"> where
 * imagePath is the path, where the three gifs are located and 
 * imageNr ("nav" + imageNr) for the item which should be selected,
 * (use 0 if you don't want anyone mark as selected)
 *
 * <body bgcolor="#ffffcc" background="IMAGES/bg_navig.jpg" onload="initNavInd('Images','1');">
 *
 * Set the starting gifs and the onouseover onmouseout onmouseup events as following, 
 * use that the same # for the name and the three mouse events, another on each line (the numbers on the
 * lines don't have to	be in sequence, cou con easily introduce a line later or change the lines).
 *
 * <img src="ImagePath/navind_sel.gif" name="nav1" height="11" width="11">&nbsp;<a href="School/school.html" target="data" onmouseup="setImage('1')" onmouseover="swapImage('1')" restoreImage="change('1')">Die Schule</a><br>
 * <img src="ImagePath/navind_off.gif" name="nav2" height="11" width="11">&nbsp;<a href="School/school_sec.html" target="data" onmouseup="setImage('2')" onmouseover="swapImage('2')" restoreImage="change('2')">Oberstufe</a><br>
 * <img src="ImagePath/navind_off.gif" name="nav#" height="11" width="11">&nbsp;<a href="School/school_sec.html" target="data" onmouseup="setImage('#')" onmouseover="swapImage('#')" restoreImage="change('#')">Oberstufe</a><br>
 *
*/
var navind_off;
var navind_ind;
var navind_sel;
var mImgPath;
var mImgNrSel;
var mPref;

/* Initializes for the navigation indicators.
 * Sets the path to the images and the selected image 
 * pPref the prefix, which is used for name and id of the image 
 * (followed by a number).
 */
function initNavInd(pImgPath, pPref)
{
	if (document.getElementById)
	{
		mImgPath = pImgPath;
		mPref = pPref;
		for (idx = 0; idx < document.getElementsByTagName("img").length; idx++)
		{
			theImg = document.getElementsByTagName("img")[idx];
			if(theImg.src.indexOf("navind_sel.gif") >= 0)
			{
				imgSel = theImg.id;
				mImgNrSel = imgSel.substring(mPref.length);
			}
		}
	}
	else if (document.layers)
	{
		mImgPath = pImgPath;
		mPref = pPref;
		navind_off = new Image();
		navind_off.src = mImgPath + "/navind_off.gif";
		navind_ind = new Image();
		navind_ind.src = mImgPath + "/navind_ind.gif";
		navind_sel = new Image();
		navind_sel.src = mImgPath + "/navind_sel.gif";
		
		for (idx = 0; idx < document.images.length; idx++)
		{
			theImg = document.images[idx];
			if(theImg.src.indexOf("navind_sel.gif") >= 0)
			{
				imgSel = theImg.name;
				mImgNrSel = imgSel.substring(mPref.length);
			}
		}
	}
}

/* Sets the image navind_sel.gif on the image with id or name 
 * "nav" + pImgNr
 */
function selImage(pImgNr)
{
	if (document.getElementById)
	{
		theImg=document.getElementById("nav"+mImgNrSel);
		if (theImg != null)
		{
		
			theImg.setAttribute("src",mImgPath+"/navind_off.gif");
		}
		theImg=document.getElementById("nav"+pImgNr);
		theImg.setAttribute("src",mImgPath+"/navind_sel.gif");
	}
	else if (document.layers)
	{
		if (mImgNrSel != undefined)
		{
			document.images[mPref + mImgNrSel].src = eval('navind_off.src');
		}
		document.images[mPref + pImgNr].src = eval('navind_sel.src');
	}
	mImgNrSel = pImgNr;
}

/* Sets the image to navind_ind.gif on the image with id or name
 * "nav" + pImgNr
 */
function swapImage(pImgNr)
{
	if (document.getElementById)
	{
		theImg=document.getElementById("nav"+pImgNr);
		theImg.setAttribute("src",mImgPath+"/navind_ind.gif");
	}
	else if (document.layers)
	{
		document.images[mPref + pImgNr].src = eval('navind_ind.src');
	}
}

/* Sets the image back to navind_sel.gif or navind_off.gif on the 
 * image with id or name "nav" + pImgNr
 */
function restoreImage(pImgNr)
{
	if (document.getElementById)
	{
		if (pImgNr == mImgNrSel)
		{
			theImg=document.getElementById(mPref + pImgNr);
			theImg.setAttribute("src", mImgPath + "/navind_sel.gif");
		}
		else
		{
			theImg=document.getElementById(mPref + pImgNr);
			theImg.setAttribute("src", mImgPath + "/navind_off.gif");
		}
	}
	else if (document.layers)
	{
		if (pImgNr == mImgNrSel)
		{
			document.images[mPref + pImgNr].src = eval('navind_sel.src');
		}
		else
		{
			document.images[mPref + pImgNr].src = eval('navind_off.src');
		}
	}
}
