// animMenu.jsp				
// author: Mark C. Harris
// date: July 11th 2005
// edited: Aug 28 2005 - added function to close all menus
//
// animates menues closing and opening
// requires menues named: ex: id=menu1, menu2, menu3
// supports 3 animated menues.
// default open menu is menu1, can be modified. by section //DEFAULT KEY POSITION



//Declair variables
var maxHeight= 95;
var delay = 17; //in milliseconds 1000 = 1 second;

//KEYFRAMES - percentages of maxHeight
var keys = new Array();
keys[0]= (1/maxHeight);  //in IE div must be at least 1 pixel tall.
keys[1]= 0.10;
keys[2]= 0.25;
keys[3]= 0.50
keys[4]= 0.65;
keys[5]= 0.75;
keys[6]= 0.82;
keys[7]= 0.91;
keys[8]= 0.94
keys[9]= 0.97;
keys[10]= 0.98;
keys[11]= 0.99;
keys[12]= 1.00;

//timeLine OBJECT for each MENU
function TimeLine(){};
var menu1 = new TimeLine();
var menu2 = new TimeLine();
var menu3 = new TimeLine();

//DEFAULT MENU POSITION;
menu1.frame=0 //if you want to start open use this  (keys.length -1);
menu2.frame=0;
menu3.frame=0;

//DEFAULT HEIGHT
menu1.maxHeight = maxHeight;
menu2.maxHeight = maxHeight;
menu3.maxHeight = maxHeight;

function upDateMenu(id,size){
	eval(id).maxHeight = size;
	
	
	
	//Close All Menues
	if(menu1.frame > 0){animate("menu1",1)};
	if(menu2.frame > 0){animate("menu2",1)};
	if(menu3.frame > 0){animate("menu3",1)};


	//Open menu
	if(eval(id).frame == 0){		
		//special
		
		animate(id,0);	
		//SPECIAL CASE - if menu2 has too much content and needs scrolls
		// IE can still see scroll bar, so kill it, and only give menu 2 scroll bars
		if(id == "menu2"){document.getElementById(id).style.overflow ="hidden";}
	}
}

function closeAllMenus(){
			
	//Close All Menues
	if(menu1.frame > 0){animate("menu1",1)};
	if(menu2.frame > 0){animate("menu2",1)};
	if(menu3.frame > 0){animate("menu3",1)};
		
}



function animate(id,method){
	var size= keys.length;
	var currentFrame = eval(id).frame;//Refers to menu's TIMELINE OBJECT

	if(method == 0){

		if(currentFrame <= keys.length - 1){
			//alert("growing")
			setTimeout("drawMenu('"+ id + "',"+ method +")",delay)
		}else if(currentFrame > keys.length-1){ //error indexing array
			//alert("done growing")
			eval(id).frame = keys.length-1;
		}
	}
	else if(method == 1){

		if(currentFrame >= 0){
				
			
			//alert("shrinking")
			setTimeout("drawMenu('"+ id + "',"+ method +")",delay)
		}else if(currentFrame < 0){ //error indexing array
			//alert("done shrinking: "+ id)
			eval(id).frame = 0;
			document.getElementById(id).style.overflow = "hidden";
			
	
	
		}
	}
}

//SETS HEIGHT of menus
//Multiplies the % based keyframes(keys[]) 
//times the given pixel height(maxHeight) of the object.

function drawMenu(id, method){

	var currentFrame = eval(id).frame;
	var val = keys[currentFrame] * eval(id).maxHeight;
	document.getElementById(id).style.height = val;
	
	
	if(method == 0){
		eval(id).frame ++;
	}else{
		eval(id).frame --;
	}
	animate(id,method);
}
