<!--



//copyright e-Business Systems Limited - www.e-businesssystems.co.uk
// This script may not be used without written permission from e-Business Systems Limited.

//version 5 - 28/09/06


//to do:... check for setup_has_been_finalised?

var ebsl_menu = new Array();


//--------------------------------
function Ebsl_find_obj_x(obj,top_level_id)
{
	
	var x = 0;
	var check_top_level_id = (top_level_id != "");
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			x += obj.offsetLeft;
			
			obj = obj.offsetParent;
			
			if (check_top_level_id)
			{
				if (obj.id == top_level_id)
				{
					return x;
				}
			}
			
		}
		
	}
	else if (obj.x) 	x += obj.x;
		
	return x;
	
}



function Ebsl_find_obj_y(obj,top_level_id)
{
	var y = 0;
	var check_top_level_id = (top_level_id != "");
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			y += obj.offsetTop;
			obj = obj.offsetParent;
			
			if (check_top_level_id)
			{
				if (obj.id == top_level_id)
				{
					return y;
				}
			}
		}
	}
	else if (obj.y)	y += obj.y;
		
	return y;
}







function Ebsl_m_on(e)
{
	//try
	{
		
		
	
		
		 
		if (window.event) e = window.event;
		if (e)
		{
			var obj = ( e.srcElement ) ? e.srcElement : e.target;
			if (obj)
			{
				
				obj = Ebsl_m_find_obj(obj);
				if (obj)
				{
					obj.onmouseover();
				}
				
			}
			
		}

	} 
	//catch(ex)
	{
		//alert("There has been an error: " + ex.description);
	}
	
}


function Ebsl_m_off(e)
{
	//try
	{
		
		
		
		if (window.event) e = window.event;
		if (e)
		{
			var obj = ( e.srcElement ) ? e.srcElement : e.target;
			if (obj)
			{
				obj = Ebsl_m_find_obj(obj);
				if (obj)
				{
					obj.onmouseout();
				}
			}
			
		}
		
	} 
	//catch(ex)
	{
		//alert("There has been an error: " + ex.description);
	}
	
}




function Ebsl_m_onfocus(e)
{
		
	if (window.event) e = window.event;
	if (e)
	{
		var obj = ( e.srcElement ) ? e.srcElement : e.target;
		if (obj)
		{
			obj = Ebsl_m_find_obj(obj);
			if (obj)
			{
				obj.Onfocus();
			}
		}
		
	}
	
}

function Ebsl_m_onblur(e)
{
		
	if (window.event) e = window.event;
	if (e)
	{
		var obj = ( e.srcElement ) ? e.srcElement : e.target;
		if (obj)
		{
			obj = Ebsl_m_find_obj(obj);
			if (obj)
			{
				obj.Onblur();
			}
		}
		
	}
	
}



function Ebsl_m_find_obj(obj)
{
	var i,j,k,s,l;
	var found = false;
	s = obj.id;
	
	
	// need to look higher if event is triggered by sub object
	for (i = 1; (!found) ; i++)
	{
		if (s.substr(0,1) == "_")
		{
			found = true;
		}
		else
		{
			if (obj.parentNode == null)
			{
				break;
			}
			obj = obj.parentNode;
			s = obj.id;
		}
	}
	
	if (!(s.substr(0,1) == "_")) 
	{
		return null;
	}
	
	
	if (!found) 
	{
		return null;
	}
	
	if (!ebsl_menu[parseInt(s.substr(2,1))]) 
	{
		return null;
	}
	
	
	k = ebsl_menu[parseInt(s.substr(2,1))].top_menu_layer;
	l = s.length;
	j = 3;
	 
	for (i = 1; (j < l) ; i++)
	{
		k = k.elements[parseInt(s.substr(j,2),10) - 1];
		j+=2;
		
		if ((k.has_sub_layer) && ((l - j) >= 1))	// was >1 ###############
		{
			k = k.sub_layer;
			
		}
		
		if ((l - j) == 1)
		{
			j += 1;
		}
		
	}
	
	return k;
}






//--------------------------------
function Ebsl_menu_control(menu_id_x,menu_css_id_x, menu_id_prefix_x)
{
	//copyright e-Business Systems Limited - www.e-businesssystems.co.uk
	this.menu_id = menu_id_x;
	this.menu_css_id = menu_css_id_x;
	this.setup_has_been_finalised = false;
	this.set_abolute_position = true;
	this.menu_root_is_relatively_positioned = false;	//if true, the menu root is a relatively positioned div ** need to revisit this.  the logic isn't right
	this.menu_id_prefix = menu_id_prefix_x;
	this.layer_x_offset = new Array();
	this.layer_y_offset = new Array();
	this.level_hi_class = new Array();
	this.level_lo_class = new Array();
	
	this.top_menu_layer;
	
	
	this.Finalise_setup = Ebsl_menu_control_finalise_setup;
	this.Set_level_controls = Ebsl_menu_control_set_level_controls;
	this.Set_additional_layer_offsets = Ebsl_menu_control_set_additional_layer_offsets;
}


function Ebsl_menu_control_finalise_setup()
{
	var i,j,k;
	this.top_menu_layer = new Ebsl_menu_layer(1, this.menu_css_id, this, this); 
	
	this.setup_has_been_finalised = true;
}




function Ebsl_menu_control_set_level_controls(level, offset_x, offset_y, level_hi_class, level_lo_class)
{
	this.layer_x_offset[level] = offset_x;
	this.layer_y_offset[level] = offset_y;
	this.level_hi_class[level] = level_hi_class;
	this.level_lo_class[level] = level_lo_class;
	
}


function Ebsl_menu_control_set_additional_layer_offsets(id,offset_x, offset_y)
{
	var obj = Ebsl_m_find_obj(document.getElementById(id));
	obj.additional_x_offset = offset_x;
	obj.additional_y_offset = offset_y;
}


//--------------------------------
function Ebsl_menu_layer(level_x, css_id_x, parent_x, menu_root_x)
{
	this.level = level_x;
	this.parent = parent_x;
	this.menu_root = menu_root_x;
	this.css_id = css_id_x;
	this.is_visible = true;
	this.element_ref = document.getElementById(this.css_id);
	this.mouse_is_over = false;
	this.element_count = 0;
	this.additional_x_offset = 0;
	this.additional_y_offset = 0;
	
	this.elements = new Array();
	
	this.onmouseout = Ebsl_menu_layer_onmouseout;
	this.onmouseover = Ebsl_menu_layer_onmouseover;
	this.Mouse_is_over_child_objects = Ebsl_menu_layer_mouse_is_over_child_objects;
	this.Show = Ebsl_menu_layer_show;
	this.Hide = Ebsl_menu_layer_hide;
	this.Snuff_others = Ebsl_menu_layer_snuff_others;
	
	if (this.level > 1)
	{
		this.element_ref.onmouseover = Ebsl_m_on;
		this.element_ref.onmouseout = Ebsl_m_off;
	}
	
	var i,j,k;
	var core_id;
	var element_found = true;
	if (this.level == 1)
	{
		core_id = this.menu_root.menu_id_prefix + this.menu_root.menu_id;
	}
	else
	{
		core_id = this.parent.css_id;
		this.is_visible = false;
	}
	
	
	for (i = 101; element_found; i++)
	{
		j = i.toString();
		j = j.substr(1,2);
		j = core_id + j;
		k = document.getElementById(j);
		if (k)
		{
			this.elements[this.element_count] = new Ebsl_menu_element(this.level, j, this, this.menu_root);
			this.element_count++;
			
		}
		else
		{
			element_found = false;
		}
		
	}
	

	
}


function Ebsl_menu_layer_onmouseover()
{
	
	//this.element_ref.style.backgroundColor = "red";
	
	
	
	this.mouse_is_over = true;
	if (this.level > 1)
	{
		//this.parent.Make_hi();
		this.parent.onmouseover();
	}
	
}



function Ebsl_menu_layer_onmouseout()
{
	
	//this.element_ref.style.backgroundColor = "blue";
	
	
	
	this.mouse_is_over = false;
	if (this.level > 1)
	{
		if (!this.Mouse_is_over_child_objects())
		{
			this.parent.Make_lo();
		}
	}
}





function Ebsl_menu_layer_mouse_is_over_child_objects()
{
	var i;
	if (this.element_count > 0)
	{
		for (i = 0; (i < this.element_count) ; i++)
		{
			if (this.elements[i].Mouse_is_over_child_objects())
			{
				return true;
			}
		}
	}
	return false;
	
}


function Ebsl_menu_layer_show()
{
	
	this.is_visible = true;
	if (this.menu_root.set_abolute_position)
	{
		this.element_ref.style.left = (Ebsl_find_obj_x(this.parent.element_ref,((this.menu_root.menu_root_is_relatively_positioned) ? this.menu_root.menu_css_id : "")) + this.menu_root.layer_x_offset[this.level] + this.additional_x_offset) + "px";
		this.element_ref.style.top =  (Ebsl_find_obj_y(this.parent.element_ref,((this.menu_root.menu_root_is_relatively_positioned) ? this.menu_root.menu_css_id : "")) + this.menu_root.layer_y_offset[this.level] + this.additional_y_offset) + "px";
	}	
	this.element_ref.style.display = "block";
}


function Ebsl_menu_layer_hide()
{
	this.is_visible = false;
	this.element_ref.style.display = "none";
}

function Ebsl_menu_layer_snuff_others(id)
{
	var i;
	for (i = 0; (i < this.element_count) ; i++)
	{
		if (this.elements[i].css_id != id)
		{
			if (this.elements[i].mouse_is_over)
			
			{
				this.elements[i].onmouseout();
			}
		}
	}
}



//--------------------------------
function Ebsl_menu_element(level_x, css_id_x, parent_x, menu_root_x)
{
	this.level = level_x;
	this.parent = parent_x;
	this.menu_root = menu_root_x;
	this.css_id = css_id_x;
	this.is_visible = true;
	this.element_ref = document.getElementById(this.css_id);
	this.mouse_is_over = false;
	this.has_sub_layer = false;
	this.additional_x_offset = 0;	//not currently used at element level
	this.additional_y_offset = 0;	//not currently used at element level
	this.sub_layer;
	this.has_focus = false;
	
	this.onmouseout = Ebsl_menu_element_onmouseout;
	this.onmouseover = Ebsl_menu_element_onmouseover;
	this.Onfocus = Ebsl_menu_element_onfocus;
	this.Onblur = Ebsl_menu_element_onblur;
	this.Mouse_is_over_child_objects = Ebsl_menu_element_mouse_is_over_child_objects;
	this.Make_lo = Ebsl_menu_element_make_lo;
	this.Make_hi = Ebsl_menu_element_make_hi;
	
	this.element_ref.onmouseover = Ebsl_m_on;
	this.element_ref.onmouseout = Ebsl_m_off;
	this.element_ref.onfocus = Ebsl_m_onfocus;
	this.element_ref.onblur = Ebsl_m_onblur;
	
	
	var i,j,k;
	
	if (this.level > 1)
	{
		this.is_visible = false;
	}
	
	
	j = this.css_id + "c";
	k = document.getElementById(j);
	if (k)
	{
		this.sub_layer = new Ebsl_menu_layer(this.level + 1, j, this, this.menu_root);
		this.has_sub_layer = true;
		
	}

}


function Ebsl_menu_element_onmouseover()
{
	this.mouse_is_over = true;
	this.Make_hi();
	
	if (this.level > 1)
	{
		this.parent.onmouseover();	//#######################
		
	}
	
	this.parent.Snuff_others(this.css_id);
}


function Ebsl_menu_element_onmouseout()
{
	this.mouse_is_over = false;
	this.Make_lo();
	
}

function Ebsl_menu_element_onfocus()
{
	this.has_focus = true;
}


function Ebsl_menu_element_onblur()
{
	
	this.has_focus = false;
}

this.Onfocus = Ebsl_menu_element_onfocus;
	this.Onblur = Ebsl_menu_element_onblur;




function Ebsl_menu_element_mouse_is_over_child_objects()
{
	if (this.has_sub_layer)
	{
		return this.sub_layer.Mouse_is_over_child_objects();
		
	}	
	return false;
	
}



function Ebsl_menu_element_make_lo()
{
	
	if ((!this.has_focus) && (!this.Mouse_is_over_child_objects()))
	{
		if (this.has_sub_layer)
		{
			this.sub_layer.Hide();
		}
		
		if (this.menu_root.level_lo_class[this.level] != "")
		{
			this.element_ref.className = this.menu_root.level_lo_class[this.level];
		}
		
		
		this.mouse_is_over = false;
		
	}
	
	
	
}



function Ebsl_menu_element_make_hi()
{
	if (this.menu_root.level_hi_class[this.level] != "")
	{
		this.element_ref.className = this.menu_root.level_hi_class[this.level];
	}
	
	
	if (this.has_sub_layer)
	{
		this.sub_layer.Show();
	}
	
	if (this.level > 1)
	{
		this.parent.parent.Make_hi();
		
	}
}


//--------------------------------


/*
// call Setup_menu when page has loaded
function Setup_menu()
{
	ebsl_menu[0] = new Ebsl_menu_control(0,"fcmenu","_m");
	
	ebsl_menu[0].Set_level_controls(1,0,0,"m_1_hi","m_1_lo");
	ebsl_menu[0].Set_level_controls(2,-5,15,"m_1_hi","m_1_lo");
	ebsl_menu[0].Set_level_controls(3,130,-5,"m_1_hi","m_1_lo");
	
	
	
	ebsl_menu[0].Finalise_setup();
}
*/


//-->