/*
 * animatedMenu.js
 * 
 * simple fade-in/fade-out script for menu's
 * 
 * (C) 2010 - intelliBiz
 * www.intellibiz.org
 * 
 *  PARAMETERS:
 *  animationTime: the gross delay the fades should take (in ms)
 *  animationSteps: performance indicator; in how many frames 
 *  				should the animation take place, higher 
 *  				values make the animation run more smooth,
 *  				lower values save processor speed on clients.
 *  
 *  FUNCTIONS:
 *  startShow(MenuId): starts showing the menu with HTML ID <MenuId>
 *  startHide(MenuId): starts hiding the menu with HTML ID <MenuId>
 *  startShowOrHide(MenuId): starts showing the menu with HTML ID <MenuId>
 *  						 if the menu is currently not visible or starts
 *  						 hiding it when it is visible.
 *  
 *  USAGE:
 *  put the startShow() and startHide() functions on a control 
 *  element's OnClick or onMouseOver/onMouseOut functions;
 */

var animationTime = 500;
var animationSteps = 15;

function hideAllMenus() {

  var hamMenuItems = document.getElementsByClassName("sub");
  var hamNumSubs = hamMenuItems.length;
  
  for (hami=0;hami<hamNumSubs;hami++) {
    hamMenuItems[hami].style.display = "none";
  }

}

function startShowOrHide(sshMenuId) {
	
	var sshMenu = document.getElementById(sshMenuId);
	if (sshMenu.style.display=="none") {
                hideAllMenus();
		showMenu(sshMenuId,0);		
	} else {
		hideMenu(sshMenuId,1);
	}
	
}

function startShow(ssMenuId) {
	showMenu(ssMenuId,0);

}

function startHide(shMenuId) {
	
        hideMenu(shMenuId,1);

	
}

function showMenu (smMenuId,smOpacity) {

        noAnimation = 1;
	var smMenu = document.getElementById(smMenuId);
	var lsmOpacity = smOpacity + ((animationTime/animationSteps)/animationTime);

	/* for real browsers */
	smMenu.style.opacity = lsmOpacity;
	/* for ie */
	smMenu.style.filter = "alpha( opacity="+(lsmOpacity*100)+" )";

	smMenu.style.display = "block";

	if (lsmOpacity < 1) setTimeout("showMenu('"+smMenuId+"',"+lsmOpacity+");",animationTime/animationSteps);

}

function hideMenu (hmMenuId,hmOpacity) {
	
	var hmMenu = document.getElementById(hmMenuId); 
	
	var lhmOpacity = hmOpacity-((animationTime/animationSteps)/animationTime); 
	
	/* for real browsers */
	hmMenu.style.opacity = lhmOpacity;
	/* for ie */
	hmMenu.style.filter = "alpha( opacity="+(lhmOpacity*100)+" )";
	
	if (lhmOpacity > 0) {
		setTimeout("hideMenu('"+hmMenuId+"',"+lhmOpacity+");",animationTime/animationSteps);
	} else {
		hmMenu.style.display = "none";
	}
}

