//size of button you use with the menu
var button_height = 25;
var button_width = 123;

//used for the speed of animation
var inc = 10;
var inc_delay = 1;

//menu array and one for each item
var menu = new Array();
menu[0] = 'category1';
menu[1] = 'category2';
menu[2] = 'category3';
menu[3] = 'category4';
menu[4] = 'category5';
menu[5] = 'category6';
	
function initialize(){
	for(i=0;i<menu.length;i++){
		initializeLayer(menu[i]);
	}
}
function toggleImage(name,over){
	if(over){
		document.images[name+"_image"].src = "/images/navigation/" + name + "_on.gif";
	}
	else{
		document.images[name+"_image"].src = "/images/navigation/" + name + ".gif";
	}
}
function toggleBullet(name,over){
	if(over){
		document.images[name].src = "/images/navigation/bullet_on.gif";
	}
	else{
		document.images[name].src = "/images/navigation/bullet.gif";
	}
}
function initializeLayer(layer){
	obj = getObject(layer);
	height = getObjHeight(obj);
	moveObjTo(obj,0,(button_height-height));
	clipObjTo(obj,height,button_width,height,0);
	obj.state = 'closed';
	show(obj);
}
function nav(layer,action){
	obj = getObject(layer);
	if(action == 'open'){
		if(obj.state == 'closed' || obj.state == 'closing'){
			obj.state = 'opening';
			hideAllBut(layer);
			toggleImage(layer,true);
			toggleAnimation(layer,true);
		}
	}
	if(action == 'close'){
		if(obj.state == 'opened'){
			obj.state = 'closing';
			toggleAnimation(layer,true);
		}
	}
}
function hideAllBut(layer){
	for(i=0;i<menu.length;i++){
		if(layer != menu[i]){
			nav(menu[i],'close');
		}
	}
}
function sleep(mils){
	then=new Date().getTime();
	now=then;
	while((now-then) < mils){
		now=new Date().getTime();
	}
}
function toggleAnimation(layer,firsttime){
	obj = getObject(layer);
	currentTop = getTop(obj);
	if(obj.state == 'opening'){
		if(currentTop < button_height){
			if(!firsttime){
				if((button_height-currentTop) < inc) {
					moveObjBy(obj,0,button_height-currentTop);
					clipObjBy(obj,((button_height-currentTop)*-1),0,0,0);
				}
				else {
					moveObjBy(obj,0,inc);
					clipObjBy(obj,(inc*-1),0,0,0);
				}
			}
			setTimeout("toggleAnimation('"+layer+"',false)", inc_delay);
		}
		else{
			obj.state = 'opened';
		}
	}
	else if(obj.state == 'closing'){
		currentHeight = getObjHeight(obj);
		if(currentTop > (button_height-currentHeight)){
			if(!firsttime){
				pixelsLeft = ((-1*(button_height-currentHeight))+currentTop);
				if(pixelsLeft < inc) {
					moveObjBy(obj,0,(pixelsLeft*-1));
					clipObjBy(obj,pixelsLeft,0,0,0);
				}
				else {
					moveObjBy(obj,0,(inc*-1));
					clipObjBy(obj,inc,0,0,0);
				}
			}
			setTimeout("toggleAnimation('"+layer+"',false)", inc_delay);
		}
		else{
			toggleImage(layer,false);
			obj.state = 'closed';
		}
	}
}