/************************************************************************************************************
(C) www.dhtmlgoodies.com, October 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/	
var expandFirstItemAutomatically2 = true;	// Expand first menu item automatically ?
var initMenuIdToExpand2 = false;	// Id of menu item that should be initially expanded. the id is defined in the <li> tag.
var expandMenuItemByUrl2 = true;	// Menu will automatically expand by url - i.e. if the href of the menu item is in the current location, it will expand


var initialMenuItemAlwaysExpanded2 = true;	// NOT IMPLEMENTED YET

var dhtmlgoodies_slmenuObj2;
var divToScroll2 = false;
var ulToScroll2 = false;	
var divCounter2 = 1;
var otherDivsToScroll2 = new Array();
var divToHide2 = false;
var parentdivToHide2 = new Array();
var ulToHide2 = false;
var offsetOpera2 = 0;
if(navigator.userAgent.indexOf('Opera')>=0)offsetOpera2=1;	
var slideMenuHeightOfCurrentBox2 = 0;
var objectsToExpand2 = new Array();
var initExpandIndex2 = 0;
var alwaysExpanedItems2 = new Array();
	
function popMenusToShow2()
{
	var obj = divToScroll2;
	var endArray = new Array();
	while(obj && obj.tagName!='BODY'){
		if(obj.tagName=='DIV' && obj.id.indexOf('slideDiv')>=0){
			var objFound = -1;
			for(var no=0;no<otherDivsToScroll2.length;no++){
				if(otherDivsToScroll2[no]==obj){
					objFound = no;		
				}					
			}	
			if(objFound>=0){
				otherDivsToScroll2.splice(objFound,1);	
			}		
		}	
		obj = obj.parentNode;
	}	
}

function showSubMenu2(e,inputObj)
{

	if(this && this.tagName)inputObj = this.parentNode;
	if(inputObj && inputObj.tagName=='LI'){
		divToScroll2 = inputObj.getElementsByTagName('DIV')[0];
		for(var no=0;no<otherDivsToScroll2.length;no++){
			if(otherDivsToScroll2[no]==divToScroll2)return;
		}			
	}
	hidingInProcess = false;
	if(otherDivsToScroll2.length>0){
		if(divToScroll2){				
			if(otherDivsToScroll2.length>0){
				popMenusToShow2();
			}
			if(otherDivsToScroll2.length>0){	
				autoHideMenus2();
				hidingInProcess = true;
			}
		}	
	}		
	if(divToScroll2 && !hidingInProcess){
		divToScroll2.style.display='';
		otherDivsToScroll2.length = 0;
		otherdivToScroll2 = divToScroll2.parentNode;
		otherDivsToScroll2.push(divToScroll2);	
		while(otherdivToScroll2 && otherdivToScroll2.tagName!='BODY'){
			if(otherdivToScroll2.tagName=='DIV' && otherdivToScroll2.id.indexOf('slideDiv')>=0){
				otherDivsToScroll2.push(otherdivToScroll2);
									
			}
			otherdivToScroll2 = otherdivToScroll2.parentNode;
		}			
		ulToScroll2 = divToScroll2.getElementsByTagName('UL')[0];
		if(divToScroll2.style.height.replace('px','')/1<=1)scrollDownSub2();
	}	
	

}



function autoHideMenus2()
{
	if(otherDivsToScroll2.length>0){
		divToHide2 = otherDivsToScroll2[otherDivsToScroll2.length-1];
		parentdivToHide2.length=0;
		var obj = divToHide2.parentNode.parentNode.parentNode;
		while(obj && obj.tagName=='DIV'){			
			if(obj.id.indexOf('slideDiv')>=0)parentdivToHide2.push(obj);
			obj = obj.parentNode.parentNode.parentNode;
		}
		var tmpHeight = (divToHide2.style.height.replace('px','')/1 - slideMenuHeightOfCurrentBox2);
		if(tmpHeight<0)tmpHeight=0;
		if(slideMenuHeightOfCurrentBox2)divToHide2.style.height = tmpHeight  + 'px';
		ulToHide2 = divToHide2.getElementsByTagName('UL')[0];
		slideMenuHeightOfCurrentBox2 = ulToHide2.offsetHeight;
		scrollUpMenu2();		
	}else{
		slideMenuHeightOfCurrentBox2 = 0;
		showSubMenu2();			
	}
}


function scrollUpMenu2()
{

	var height = divToHide2.offsetHeight;
	height-=15;
	if(height<0)height=0;
	divToHide2.style.height = height + 'px';

	for(var no=0;no<parentdivToHide2.length;no++){	
		parentdivToHide2[no].style.height = parentdivToHide2[no].getElementsByTagName('UL')[0].offsetHeight + 'px';
	}
	if(height>0){
		setTimeout('scrollUpMenu2()',5);
	}else{
		divToHide2.style.display='none';
		otherDivsToScroll2.length = otherDivsToScroll2.length-1;
		autoHideMenus2();			
	}
}	

function scrollDownSub2()
{
	if(divToScroll2){			
		var height = divToScroll2.offsetHeight/1;
		var offsetMove =Math.min(15,(ulToScroll2.offsetHeight - height));
		height = height +offsetMove ;
		divToScroll2.style.height = height + 'px';
		
		for(var no=1;no<otherDivsToScroll2.length;no++){
			var tmpHeight = otherDivsToScroll2[no].offsetHeight/1 + offsetMove;
			otherDivsToScroll2[no].style.height = tmpHeight + 'px';
		}			
		if(height<ulToScroll2.offsetHeight)setTimeout('scrollDownSub2()',5); else {
			divToScroll2 = false;
			ulToScroll2 = false;
			if(objectsToExpand2.length>0 && initExpandIndex2<(objectsToExpand2.length-1)){
				initExpandIndex2++;
				
				showSubMenu2(false,objectsToExpand2[initExpandIndex2]);
			}
		}
	}
}
	
function initSubItems2(inputObj,currentDepth)
{		
	divCounter2++;		
	var div = document.createElement('DIV');	// Creating new div		
	div.style.overflow = 'hidden';	
	div.style.position = 'relative';
	div.style.display='none';
	div.style.height = '1px';
	div.id = 'slideDiv' + divCounter2;
	div.className = 'slideMenuDiv' + currentDepth;		
	inputObj.parentNode.appendChild(div);	// Appending DIV as child element of <LI> that is parent of input <UL>		
	div.appendChild(inputObj);	// Appending <UL> to the div
	var menuItem = inputObj.getElementsByTagName('LI')[0];
	while(menuItem){
		if(menuItem.tagName=='LI'){
			var aTag = menuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth'+currentDepth;	
			var subUl = menuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				initSubItems2(subUl[0],currentDepth+1);					
			}
			aTag.onclick = showSubMenu2;				
		}			
		menuItem = menuItem.nextSibling;						
	}		
}

function initSlideDownMenu2()
{
	dhtmlgoodies_slmenuObj2 = document.getElementById('dhtmlgoodies_slidedown_menu2');
	dhtmlgoodies_slmenuObj2.style.visibility='visible';
	var mainUl = dhtmlgoodies_slmenuObj2.getElementsByTagName('UL')[0];		
	var mainMenuItem = mainUl.getElementsByTagName('LI')[0];
	mainItemCounter = 1;
	while(mainMenuItem){			
		if(mainMenuItem.tagName=='LI'){
			var aTag = mainMenuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth1';	
			var subUl = mainMenuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				mainMenuItem.id = 'mainMenuItem' + mainItemCounter;
				initSubItems2(subUl[0],2);
				aTag.onclick = showSubMenu2;
				mainItemCounter++;
			}				
		}			
		mainMenuItem = mainMenuItem.nextSibling;	
	}		
	
	if(location.search.indexOf('mainMenuItemToSlide')>=0){
		var items = location.search.split('&');
		for(var no=0;no<items.length;no++){
			if(items[no].indexOf('mainMenuItemToSlide')>=0){
				values = items[no].split('=');
				showSubMenu2(false,document.getElementById('mainMenuItem' + values[1]));	
				initMenuIdToExpand2 = false;				
			}
		}			
	}else if(expandFirstItemAutomatically2>0){
		if(document.getElementById('mainMenuItem' + expandFirstItemAutomatically2)){
			showSubMenu2(false,document.getElementById('mainMenuItem' + expandFirstItemAutomatically2));
			initMenuIdToExpand2 = false;
		}
	}

	if(expandMenuItemByUrl2)
	{
		var aTags = dhtmlgoodies_slmenuObj2.getElementsByTagName('A');
		for(var no=0;no<aTags.length;no++){
			var hrefToCheckOn = aTags[no].href;				
			if(location.href.indexOf(hrefToCheckOn)>=0 && hrefToCheckOn.indexOf('#')<hrefToCheckOn.length-1){
				initMenuIdToExpand2 = false;
				var obj = aTags[no].parentNode;
				while(obj && obj.id!='dhtmlgoodies_slidedown_menu2'){
					if(obj.tagName=='LI'){							
						var subUl = obj.getElementsByTagName('UL');
						if(initialMenuItemAlwaysExpanded2)alwaysExpanedItems2[obj.parentNode] = true;
						if(subUl.length>0){								
							objectsToExpand2.unshift(obj);
						}
					}
					obj = obj.parentNode;	
				}
				showSubMenu2(false,objectsToExpand2[0]);
				break;					
			}			
		}
	}
			
	if(initMenuIdToExpand2)
	{
		objectsToExpand2 = new Array();
		var obj = document.getElementById(initMenuIdToExpand2)
		while(obj && obj.id!='dhtmlgoodies_slidedown_menu2'){
			if(obj.tagName=='LI'){
				var subUl = obj.getElementsByTagName('UL');
				if(initialMenuItemAlwaysExpanded2)alwaysExpanedItems2[obj.parentNode] = true;
				if(subUl.length>0){						
					objectsToExpand2.unshift(obj);
				}
			}
			obj = obj.parentNode;	
		}
		
		showSubMenu2(false,objectsToExpand2[0]);

	}
	
}