// MENU set construct0r
function ew_menu_set(name)
{
	// properties
	this.name = name;
	this.menu_struct = new Array();
	this.timeout = 500;
	this.img_path = '';
	this.img_sub_menu = '';
	this.bg_color = '';
	this.css_class = '';
	this.seperator_width = 0;
	this.seperator_color = '';
	this.border_width = 0;
	this.border_color = '';
	this.cell_padding = 2;
	
	// methods
	this.create_menu = create_menu;
	this.place = place;
	this.show = show;
	this.hide = hide;
	this.chk_to_hide = chk_to_hide;
	
	function create_menu(name, width, x_pos, y_pos, parent_id)
	{	
		current_array_length = this.menu_struct.length;
		this.menu_struct[current_array_length] = new ew_drop_menu(name, width, x_pos, y_pos, this.name, parent_id);
		return this.menu_struct[current_array_length];
	}
	function show(id_list)
	{
		id_array = id_list.split(',');
		for (i=0; i < id_array.length; i++)
		{
			eval(id_array[i] + '.to_hide = 0;');
		}
		// loop thru entire menu structure, turning off all unrequired elements
		// this behavior is to eliminate menus remaining open when going from one top level menu to another
		for (i = 0; i < this.menu_struct.length; i++)
		{
			if(this.menu_struct[i].to_hide == 1 && !in_array(id_array, this.menu_struct[i].name))
			{
				document.getElementById(this.menu_struct[i].name).style.visibility = "hidden";
			}
			else
			{
				document.getElementById(this.menu_struct[i].name).style.visibility = "visible";
			}
		}
	}
	function hide(id_list)
	{
		id_array = id_list.split(',');
		for (i=0; i < id_array.length; i++)
		{
			eval(id_array[i] + '.to_hide = 1;');
			setTimeout(this.name + '.chk_to_hide(\'' + id_array[i] + '\');', this.timeout);
		}
	}
	function chk_to_hide(id)
	{
		if(eval(id + '.to_hide') == 1)
		{
			document.getElementById(id).style.visibility = "hidden";
		}
	}
	function get_parents(id, str)
	{
		var str = '';
		while(typeof(eval(id + '.parent_id')) != 'undefined')
		{
			if(str != ''){str += ',' + eval(id + '.parent_id')}
			else{str = eval(id + '.parent_id')}
			id = eval(id + '.parent_id');
		}
		return str;
	}
	function place()
	{
		for (i=0; i < this.menu_struct.length; i++)
		{
			// init menu
			html_menu = '';
			html_menu += '<table border="0" cellspacing="0" cellpadding="0" width="100%" style="';
				if(this.border_width != 0)
				{
					html_menu += 'border:' + this.border_width + 'px solid #' + this.border_color + ';';
				}
			html_menu += '">';
			for (j=0; j < this.menu_struct[i].menu_struct.length; j++)
			{
				// establish mouse_over and mouse_outs
					id_list = this.menu_struct[i].name;
					
					// TARGET MENU DEFINED / CHILD MENU
					if(typeof(this.menu_struct[i].menu_struct[j].target_menu) != 'undefined'
						&& this.menu_struct[i].menu_struct[j].target_menu != ''
						&& this.menu_struct[i].menu_struct[j].target_menu != null)
					{
						id_list += ',' + this.menu_struct[i].menu_struct[j].target_menu;
					}
					// LIST OF PARENTS
					if(typeof(this.menu_struct[i].parent_id) != 'undefined')
					{
						id_list += ',' + get_parents(this.menu_struct[i].name);
					}
					mouse_over = this.menu_struct[i].constructor_name + '.show(\'' + id_list + '\');';
					mouse_out = this.menu_struct[i].constructor_name + '.hide(\'' + id_list + '\');';
					
				html_menu += '<tr>';
					html_menu += '<td width="100%" style="padding:' + this.cell_padding + 'px;';
						// seperator - only display if not last item, if last item no need to seperate
						if(j != this.menu_struct[i].menu_struct.length - 1 && this.seperator_width != 0)
						{
							html_menu += 'border-bottom:' + this.seperator_width + 'px solid #' + this.seperator_color + ';';
						}
						html_menu += '"';
						html_menu += ' class="' + this.css_class + '" ';
						html_menu += ' onmouseover="';
						html_menu += mouse_over;
						html_menu += '" onmouseout="';
						html_menu += mouse_out;
						html_menu += '"><a href="' + this.menu_struct[i].menu_struct[j].url;
						html_menu += '" target="' + this.menu_struct[i].menu_struct[j].url_target + '" class="' + this.css_class + '" ';
						html_menu += 'onmouseover="';
						html_menu += mouse_over;
						html_menu += '" onmouseout="';
						html_menu += mouse_out;
						html_menu += '"><b>';
						html_menu += this.menu_struct[i].menu_struct[j].description + '</b></a></td>';
					// if target menu is defined, put white arrow to indicate sub menu
					html_menu += '<td style="padding:' + this.cell_padding + 'px;';
						// seperator - only display if not last item, if last item no need to seperate
						if(j != this.menu_struct[i].menu_struct.length - 1 && this.seperator_width != 0)
						{
							html_menu += 'border-bottom:' + this.seperator_width + 'px solid #' + this.seperator_color + ';';
						}
						html_menu += '"';
						html_menu += ' class="' + this.css_class + '" ';
						html_menu += 'onmouseover="';
						html_menu += mouse_over;
						html_menu += '" onmouseout="';
						html_menu += mouse_out;
						html_menu += '">';
					if(typeof(this.menu_struct[i].menu_struct[j].target_menu) != 'undefined' 
						&& this.menu_struct[i].menu_struct[j].target_menu != ''
						&& this.menu_struct[i].menu_struct[j].target_menu != null
						&& typeof(this.img_sub_menu) != 'undefined' 
						&& typeof(this.img_path) != 'undefined')
					{
						html_menu += '<img src="' + this.img_path + '/' + this.img_sub_menu + '" border="0">';
					}
					else
					{
						html_menu += '<img src="' + this.img_path + '/blank.gif" width="1" height="1" border="0">';
					}
				html_menu += '</td></tr>';
			}

			// terminate menu
			html_menu += '</table>';
			// alert(html_menu);
			
			// div code
			id_list = this.menu_struct[i].name;
			// PARENT MENU
			if(typeof(this.menu_struct[i].parent_id) != 'undefined')
			{
				id_list += ',' + get_parents(this.menu_struct[i].name);
			}
			mouse_out = this.menu_struct[i].constructor_name + '.hide(\'' + id_list + '\');';
			mouse_over = this.menu_struct[i].constructor_name + '.show(\'' + id_list + '\');';
			
			div_code = '';
			div_code += '<div id="' + this.menu_struct[i].name + '" style="width:' + this.menu_struct[i].width + 'px; position:absolute; ';
			div_code += 'left:' + this.menu_struct[i].x_pos + 'px; top:' + this.menu_struct[i].y_pos + 'px; visibility:hidden; z-index:99;background-color:#FFCC00;" ';
			div_code += 'onmouseover="' + mouse_over + ';" ';
			div_code += 'onmouseout="' + mouse_out + ';"';
			div_code += '>';
			div_code += html_menu;
			div_code += '</div>';
			
			//alert(div_code);
			
			document.write(div_code);
		}
		//alert(get_parents('test_child'));
	}
}
// MENU construct0r
function ew_drop_menu(name, width, x_pos, y_pos, constructor_name, parent_id)
{
	// properties
	this.name = name;
	this.constructor_name = constructor_name;
	this.width = width;
	this.x_pos = x_pos;
	this.y_pos = y_pos;
	this.to_hide = 1;
	this.menu_struct = new Array();
	this.parent_id = parent_id;
	
	// methods
	this.add_nav = add_nav;
	
	// MENU-ITEM construct0r
	function menu_item(str_desc, str_link, target_menu, url_target)
	{
		this.description = str_desc;
		this.url = str_link;
		if(typeof(url_target) != 'undefined')
			{this.url_target = url_target;}
		else
			{this.url_target = '_top';}
		
		this.target_menu = target_menu;
	}
	
	// METHODS
	function add_nav(str_desc, str_link, target_menu, url_target)
	{
		return this.menu_struct[this.menu_struct.length] = new menu_item(str_desc, str_link, target_menu, url_target);
	}
	function do_hide(id)
	{
		document.getElementById(id).style.visibility = "hidden";
		// if parent exists, must turn this one off as well
		str_eval = id + '.parent_id';
		if(typeof(eval(str_eval)) != 'undefined')
		{
			str_eval = eval(str_eval) + '.chk_to_hide();';
			eval(str_eval);
		}
	}
}
function in_array(array_var, val)
{
	for (indx=0; indx < array_var.length; indx++)
	{
		if(array_var[indx] == val)
		{
			return true;
		}
	}
	return false;
}
function smail(id){
	maArray = new Array('info','admin','sales','support')
		em = 'mailto:'+maArray[id-1]+'@everyware.ch'
			self.location.href = em;
			}
