
/* Set style for last elements. The divs that need their border removed:
1. The one before the active one (menu1-level1-act) - if exists (the active one is not the first).
2. The last div (if it's not the active one).
3. The last active div child element (if the active div has childrens).
*/
function initSideMenu()
{
	setStyles();
	
	activateSideMenu();

	setBackgrounds();
//	alert(document.getElementById('xxx').style.width);
}

function activateSideMenu()
{
	/* currentStyle restricts the Javascript to IE only */
	var side_bar_menu_div = document.getElementById('side_bar_menu');
    
	/* Get all the div elements within the menu */
	var divs=side_bar_menu_div.getElementsByTagName("DIV");  

	flagFirstDivFound=false;

	for (i=0; i<divs.length; i++)
	{
		if(divs[i].className=='menu1-level1-no')
		{
			divs[i].onmouseover=function()
			{
			   menu1Level1NoOnMouseOver(this);
			}

			divs[i].onmouseout=function()
			{
			   menu1Level1NoOnMouseOut(this);
			}

			flagFirstDivFound=true;
		}
		
		if(divs[i].className=='menu1-level2-no')
		{
			divs[i].onmouseover=function()
			{
			   menu1Level2NoOnMouseOver(this);
			}

			divs[i].onmouseout=function()
			{
			   menu1Level2NoOnMouseOut(this);
			}

			flagFirstDivFound=true;
		}

		divs[i].onclick=function()
		{
			//alert(this.childNodes[0].tagName);
			obj=this.childNodes[0];
			if(obj.tagName=='IMG')
				obj=obj.nextSibling;
			//alert(obj.tagName);

			document.location=obj.href;
		}
	}
}

function menu1Level2NoOnMouseOver(o)
{
	o.childNodes[0].style.borderColor='#053068';
	o.childNodes[1].style.color='#053068';
}

function menu1Level2NoOnMouseOut(o)
{
	o.childNodes[0].style.borderColor='#CBDFEF';
	o.childNodes[1].style.color='white';
	//o.childNodes[0].className='bullet_off';
}


function menu1Level1NoOnMouseOver(o)
{
	/* Set bck color */
	o.style.backgroundColor='#CBDFEC';
	
	/* Set link color */
	//alert(o.childNodes[0].tagName);
	o.childNodes[0].style.color='#2D89AB';

	/* Only if the div has a sibling we change its border */
	if(borderBefore=o.previousSibling)
		borderBefore.src='fileadmin/fulbright/sys/template/images/bck11_on.gif';
	if(borderAfter=o.nextSibling)
		borderAfter.src='fileadmin/fulbright/sys/template/images/bck11_on.gif';

}

function menu1Level1NoOnMouseOut(o)
{
	/* Set bck color */
	o.style.backgroundColor='#67A0BD';
	o.childNodes[0].style.color='white';

	if(borderBefore=o.previousSibling)
	{
		x=borderBefore.previousSibling;	/* x is the div before the image */
		if(x && (x.className=='menu1-level2-no' || x.className=='menu1-level2-act'))
		{
			borderBefore.src='fileadmin/fulbright/sys/template/images/bck11_on.gif';
		}
		else
			borderBefore.src='fileadmin/fulbright/sys/template/images/bck11.gif';
	}
	if(borderAfter=o.nextSibling)
		borderAfter.src='fileadmin/fulbright/sys/template/images/bck11.gif';
}



function setStyles()
{
	/* Get a reference to the div before the active one (if there is an active one) */
	if(document.getElementById("id_menu1-level1-act"))
		var myDiv=document.getElementById("id_menu1-level1-act").previousSibling;

	/* In case the active div is the first one, it doesn't have a previousSibling.
	This is what we check here. */
	if(myDiv)
		/* Clear the bottom border image */
		myDiv.style.backgroundImage='url(fileadmin/fulbright/sys/template/images/trans.gif)';


	/* Get a reference to the last child div of the side menu div */
	myDiv=document.getElementById("side_bar_menu").lastChild;

	/* In case myDiv has no children, myDiv=null. This is what we check here. */
	if(myDiv)
	/* Clear the bottom border image
	{
		if(myDiv.className=="menu1-level2-no" || myDiv.className=="menu1-level2-act")
			myUrl='url(' + IMAGES_ROOT+'/en/bck13.gif)';
		else
			myUrl='url(' + IMAGES_ROOT+'/trans.gif)';

		myDiv.style.backgroundImage=myUrl;
	}
	 */

	/* Get a reference to the last child div of the active div. (In case it is the last
	side bar div child it is already set to no border by the previous code sagement.)
	we do that by walking the menu tree. We start with the active div.
	From there we continue to the next divs. Once we reach a non active div ("menu1-level1-no")
	we go back one div */
	myDiv=document.getElementById("id_menu1-level1-act");

}


function setBackgrounds()
{

	/* Set Menu1-level2-no divs background */
	myDiv=document.getElementById("side_bar_menu");
	divs=myDiv.getElementsByTagName("DIV");
	for (i=0; i<divs.length; i++)
	{
		cn=divs[i].className;
		if(cn=='menu1-level2-no' || cn=='menu1-level2-act')
		{

			bullet=document.createElement("img");
			element=divs[i].firstChild;
			bullet.src='fileadmin/fulbright/sys/template/images/trans.gif';
			
			if(cn=='menu1-level2-no')
				bullet.className='bullet_off';
			else
				bullet.className='bullet_on';

			divs[i].insertBefore(bullet,element);   

			/* Set background 
			
			ns=divs[i].nextSibling;
			if(divIsLevel2(ns))
				divs[i].style.background=
					'#98BBD1 url(fileadmin/fulbright/sys/template/images/bck12.gif) bottom no-repeat';
			*/
			
			/* If it's the last element and it has a sibling menu1-level1-act or menu1-level1-on, 
			set the height*/
			if(divs[i].nextSibling && divs[i].nextSibling.tagName=='DIV' 
				 && (divs[i].nextSibling.className=='menu1-level1-act' || 
				divs[i].nextSibling.className=='menu1-level1-no'))
			{
				//alert(divs[i].nextSibling.tagId);
				//divs[i].style.height='23px';
				divs[i].style.backgroundImage='none';
			}
		}	
	}

	/* Adding the background lines images */
	for (i=0; i<divs.length; i++)
	{
		cn=divs[i].className;
		
		/* We add lines before level1_no and only if isn't the first div link  */
		if(divs[i].className=='menu1-level1-no' && divs[i].previousSibling 
			&& divs[i].previousSibling.className!='menu1-level1-act' )
		{
			border=document.createElement("img");
			element=divs[i].previousSilbing;
			if(divs[i].previousSibling && (
					divs[i].previousSibling.className=='menu1-level2-no' ||
					divs[i].previousSibling.className=='menu1-level2-act'))
				border.src='fileadmin/fulbright/sys/template/images/bck11_on.gif';
			else
				border.src='fileadmin/fulbright/sys/template/images/bck11.gif';
			border.className='border_on';
			myDiv.insertBefore(border,divs[i]);    
		}
	}
}

function divIsLevel2(div)
{
	return (div && (div.className=='menu1-level2-no' || div.className=='menu1-level2-act'));
}
