	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, November 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 timeBeforeAutoHideb = 700;	// Microseconds to wait before auto hiding menu(1000 = 1 second)
	var slideSpeed_outb = 10;	// Steps to move sub menu at a time ( higher = faster)
	var slideSpeed_inb = 10;
		
	
	var slideTimeout_outb = 25;	// Microseconds between slide steps ( lower = faster)
	var slideTimeout_inb = 10;	// Microseconds between slide steps ( lower = faster)
	
	var showSubOnMouseOverb = true;	// false = show sub menu on click, true = show sub menu on mouse over
	var fixedSubMenuHeightb = false;	// Width of sub menu items - A number(width in pixels) or false when width should be dynamic
	
	var xOffsetSubMenub = -1; 	// Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu
	
	var slideDirectionb = 'top';	// Slide to top or bottom ?
	
	/* Don't change anything below here */
	
	var activeSubMenuIdb = false;
	var activeMainMenuItemb = false;
	var currentZIndexb = 1000;		
	var autoHideTimerb = 0;
	var submenuObjArrayb = new Array();
	var okToSlideInSubb = new Array();
	var subPositionedb = new Array();
	

	function stopAutoHideb()
	{
		autoHideTimerb = -1;
	}
	
	function initAutoHideb()
	{
		autoHideTimerb = 0;
		if(autoHideTimerb>=0)autoHideb();
	}
	
	function autoHideb()
	{
		
		if(autoHideTimerb>timeBeforeAutoHideb)
		{
			
			if(activeMainMenuItemb){
				activeMainMenuItemb.className='';
				activeMainMenuItemb = false;
			}
			
			if(activeSubMenuIdb){
				var obj = document.getElementById('subMenuDiv' + activeSubMenuIdb);
				showSubb();
			}
		}else{
			if(autoHideTimerb>=0){
				autoHideTimerb+=50;
				setTimeout('autoHideb()',50);
			}
		}
	}	
	
	function getTopPosb(inputObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	  return returnValue;
	}
	
	function getLeftPosb(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  return returnValue;
	}
	
	function showSubb()
	{
		var subObj = false;
		if(this && this.tagName){
			var numericId = this.parentNode.id.replace(/[^0-9]/g,'');
			okToSlideInSubb[numericId] = false;
			var subObj = document.getElementById('subMenuDivb' + numericId);
			if(activeMainMenuItemb)activeMainMenuItemb.className='';
			if(subObj){
//				if(!subPositionedb[numericId]){
				if(subObj.style.visibility!='visible'){
					if(slideDirectionb=='bottom'){
						subObj.style.top = getTopPosb(submenuObjArrayb[numericId]['parentDiv']) + submenuObjArrayb[numericId]['parentDiv'].offsetHeight + xOffsetSubMenub + 'px';
					}else{
						subObj.style.top = getTopPosb(submenuObjArrayb[numericId]['parentDiv']) + xOffsetSubMenub + 'px';
						
					}
					submenuObjArrayb[numericId]['top'] = subObj.style.top.replace(/[^0-9]/g,'');
					subObj.style.left = getLeftPosb(submenuObjArrayb[numericId]['parentDiv']) + this.parentNode.offsetWidth - subObj.offsetWidth + 'px';
//					subPositionedb[numericId] = true;
				}				
				subObj.style.visibility = 'visible';
				subObj.style.zIndex = currentZIndexb;
				currentZIndexb++;	
				this.className='activeMainMenuItemb';
				activeMainMenuItemb = this;
			}
		}else{
			var numericId = activeSubMenuIdb;
		}
		if(activeSubMenuIdb && (numericId!=activeSubMenuIdb || !subObj))slideMenub(activeSubMenuIdb,(slideSpeed_inb*-1));
		if(numericId!=activeSubMenuIdb && this && subObj){
			subObj.style.height = '0px';	
			slideMenub(numericId,slideSpeed_outb);
			activeSubMenuIdb = numericId;
		}else{
			if(numericId!=activeSubMenuIdb)activeSubMenuIdb = false;
		}
		if(showSubOnMouseOverb)stopAutoHideb();
	}
	
	function slideMenub(menuIndex,speed){
		var obj = submenuObjArrayb[menuIndex]['divObj'];
		var obj2 = submenuObjArrayb[menuIndex]['ulObj'];
		var height = obj.offsetHeight + speed;
		if(speed<0){
			if(height<0)height = 0;
			obj.style.height = height + 'px';
			if(slideDirectionb=='top'){
				obj.style.top = submenuObjArrayb[menuIndex]['top'] - height + 'px';
				obj2.style.top = '0px';
			}else{
				obj2.style.top = height - submenuObjArrayb[menuIndex]['height'] + 'px' 
			}
			if(height>0 && okToSlideInSubb[menuIndex])setTimeout('slideMenub(' + menuIndex + ',' + speed + ')',slideTimeout_inb); else{
				obj.style.visibility = 'hidden';
				obj.style.height = '0px';
				if(activeSubMenuIdb==menuIndex)activeSubMenuIdb=false;
			}
			
		}else{
			if(height>submenuObjArrayb[menuIndex]['height'])height = submenuObjArrayb[menuIndex]['height'];
			if(slideDirectionb=='top'){
				obj.style.top = submenuObjArrayb[menuIndex]['top'] - height + 'px';
				obj2.style.top = '0px';
			}else{
				obj2.style.top = height - submenuObjArrayb[menuIndex]['height'] + 'px' 
			}		
			
			obj.style.height = height + 'px';
			if(height<submenuObjArrayb[menuIndex]['height']){
				setTimeout('slideMenub(' + menuIndex + ',' + speed + ')',slideTimeout_outb);
			}else{
				okToSlideInSubb[menuIndex] = true;
			}
		}
	}
	function resetPositionb()
	{
		subPositionedb.length = 0;
	}
			
	function initMenub()
	{
		initLeftMenub();
		initLeftMenu();
	}

	function initLeftMenub()
	{
		var menuObj = document.getElementById('dhtmlgoodies_bmenu');	
		var mainMenuItemArray = new Array();
		
		var mainMenuItem = menuObj.getElementsByTagName('TD')[0];
		while(mainMenuItem){
			if(mainMenuItem.tagName && mainMenuItem.tagName.toLowerCase()=='td' && mainMenuItem.width !=2){
				mainMenuItemArray[mainMenuItemArray.length] = mainMenuItem;
				var aTag = mainMenuItem.getElementsByTagName('A')[0];
				if(showSubOnMouseOverb)
					aTag.onmouseover = showSubb;	
				else
					aTag.onclick = showSubb;	
			}
			mainMenuItem = mainMenuItem.nextSibling;
		}		
		
		var lis = menuObj.getElementsByTagName('A');
		for(var no=0;no<lis.length;no++){
			if(!showSubOnMouseOverb)lis[no].onmouseover = stopAutoHideb;
			lis[no].onmouseout = initAutoHideb;
			lis[no].onmousemove = stopAutoHideb;
		}
				
		for(var no=0;no<mainMenuItemArray.length;no++){
			var sub = mainMenuItemArray[no].getElementsByTagName('UL')[0];
			if(sub){
				mainMenuItemArray[no].id = 'mainMenuItem' + (no+1);
				var div = document.createElement('DIV');
				div.className='dhtmlgoodies_subMenub';
				document.body.appendChild(div);
				div.appendChild(sub);
				if(slideDirectionb=='bottom'){
					div.style.bottom = getTopPosb(mainMenuItemArray[no]) + mainMenuItemArray[no].offsetHeight + xOffsetSubMenub + 'px';
				}else{
					div.style.bottom = getTopPosb(mainMenuItemArray[no]) + xOffsetSubMenub + 'px';
				}
				div.style.left = getLeftPosb(mainMenuItemArray[no]) + 'px';
				div.id = 'subMenuDivb' + (no+1);
				sub.id = 'submenuUlb' + (no+1);
				sub.style.position = 'relative';	

				if(navigator.userAgent.indexOf('Opera')>=0){
					submenuObjArrayb[no+1] = new Array();
					submenuObjArrayb[no+1]['parentDiv'] = mainMenuItemArray[no];
					submenuObjArrayb[no+1]['divObj'] = div;
					submenuObjArrayb[no+1]['ulObj'] = sub;
					submenuObjArrayb[no+1]['height'] = sub.offsetHeight + 7;
					submenuObjArrayb[no+1]['top'] = div.style.top.replace(/[^0-9]/g,'');
				}
				sub.style.top = 1 - sub.offsetHeight + 'px';	
				
				// if(document.all)div.style.height = '1px';	
					
				if(navigator.userAgent.indexOf('Opera')<0){
					submenuObjArrayb[no+1] = new Array();
					submenuObjArrayb[no+1]['parentDiv'] = mainMenuItemArray[no];
					submenuObjArrayb[no+1]['divObj'] = div;
					submenuObjArrayb[no+1]['ulObj'] = sub;
					submenuObjArrayb[no+1]['height'] = sub.offsetHeight + 7;
					
					
					
					submenuObjArrayb[no+1]['top'] = div.style.top.replace(/[^0-9]/g,'');
					if(fixedSubMenuHeightb)submenuObjArrayb[no+1]['height'] = fixedSubMenuHeightb;
				}	

				if(!document.all)div.style.height = '1px';			
					
			}			
		}
			
		
		
		menuObj.style.visibility = 'visible';
		menuObj.style.display = 'block';
		
		window.onresize = resetPositionb;
	}
	
	window.onload = initMenub;