
//The is the initialize_slider_menu
slider_menu = function(menu_container_id, slide_height)
{
	var me = new Object();
	me.menu_container_id = menu_container_id;
	me.active = 0;
	me.duration = 0.2;
	me.iix = -1;
	me.eix = 0;
	me.execute = new Array();
	
	/*Private Function*/
	me.open_close = function (id_to_open, id_to_close) {
		if(id_to_open!="" && id_to_close!="" && id_to_open != id_to_close) {
			if(!me.active) {
				me.active = 1;
				
				//effects array
				var ea = [ new Effect.Morph(id_to_open,{
							style:{
								height:slide_height+'px'
							},
							sync: true,
							beforeStart:function(effect) {
								effect.element.style.display='block';
							},
							afterFinish:function(effect) {
								var this_div = $(id_to_open);
								this_div.setAttribute("state", 1);
							}
						}),
						new Effect.Morph(id_to_close,{
							style:{
								height:'1px'
							},
							sync: true,
							afterFinish:function(effect) {
								effect.element.style.display='none';
								var this_div = $(id_to_close);
								this_div.setAttribute("state", 0);
							}
						})
					];
				
				//open header fade
				var oh = $(id_to_open+'_over_img');
				if(oh) {
					var ohf = [ new Effect.Opacity(id_to_open+'_over_img',{
									from: 0.0,
									to:1.0,
									sync: true
								})
							];
					ea = ea.concat(ohf);
				}
				
				//close header fade
				var ch = $(id_to_close+'_over_img');
				if(ch) {
					var chf = [ new Effect.Opacity(id_to_close+'_over_img',{
									from: 1.0,
									to:0.0,
									sync: true
								})
							];
					ea = ea.concat(chf);
				}
				
				
				new Effect.Parallel(
					ea,
						{
							duration:me.duration,
							afterFinish: function(effect) {
								me.active = 0;
								var maxix = 0;
								while(me.execute[maxix]!=null) {
									maxix++;
								}
								maxix--;
								eval(me.execute[maxix]);
								maxix = 0;
								while(me.execute[maxix]!=null) {
									me.execute[maxix]=null;
									maxix++;
								}
								me.iix = -1;
								me.eix = 0;
							} 
						}
				);
			}
		}
	}
	/*Private Function*/
	me.find_open_div = function (id_to_open) {
		var id_to_close = "";
		var html_node = $(menu_container_id);
		if(html_node) {
			var html_child_nodes = html_node.childNodes; 
			if(html_child_nodes) {
				var i;
				for(i=0;i<html_child_nodes.length;i++) {
					var this_html_node = html_child_nodes.item(i);
					if(this_html_node) {
						var re = /div/i;
						if(this_html_node.tagName && this_html_node.tagName.match(re)) {
							re = /menu_detail/i;
							if(this_html_node.className && this_html_node.className.match(re)) {
								//assume closed
								var state = this_html_node.getAttribute("state");
								if(state==null) {
									state = 0;
									this_html_node.setAttribute("state", state);
								}
								if(state==1) {
									id_to_close = this_html_node.id;
								}
							}
						}
					}
				}
			}
		}
		return id_to_close;
	}
	
	/*Public Functions*/
	open_it = function (id_to_open) {
		var id_to_close = me.find_open_div(id_to_open);
		me.open_close(id_to_open, id_to_close);
	}
	
	me.open = function (id_to_open) {
		if( me.eix <= me.iix && !me.active) {
			me.iix = -1;
			me.eix = 0;
		}
		if(me.iix == -1) {
			open_it(id_to_open);
			me.iix = 0;
		}
		else {
			me.execute[me.iix] = "open_it('" + id_to_open + "');";
			me.iix++;
		}
	}
	
	return me;
}