/*
 * AcmeMenu v2.7
 *
 * Copyright (c) 2003-2005 Mackley F. Pexton.  All rights reserved.
 *
 * This is free software for individual, educational, and non-profit
 * use provided that this copyright notice appears on all copies.
 * Instructions and source code are available at www.acmebase.org/menu.
 * Optimized version is for sale at https://order.acmebase.com.
 * Commercial web sites are required to have an inexpensive license.
 * This software is part of the AcmeBase project at www.acmebase.org.
 * Send correspondence and feedback to: mack_pexton[at]acmebase.org.
 */

/*
 * Detect browser version
 */

bv.isNS     = (navigator.userAgent.indexOf("Netscape")     >= 0) ? true : false;
bv.isNS71   = (navigator.userAgent.indexOf("Netscape/7.1") >= 0) ? true : false;

bv.isOpr    = (navigator.userAgent.indexOf("Opera")    >= 0) ? true : false;
bv.isOpr5   = (navigator.userAgent.search(/Opera.5/)   >= 0) ? true : false;
bv.isOpr6   = (navigator.userAgent.search(/Opera.6/)   >= 0) ? true : false;
bv.isOpr7   = (navigator.userAgent.search(/Opera.7/)   >= 0) ? true : false;

bv.isSafari = (navigator.userAgent.search(/Safari/)   >= 0) ? true : false;

bv.isKonq   = (navigator.vendor == "KDE") ? true : false;

bv.isIE     = (document.all && ! bv.isOpr && ! bv.isKonq);
bv.isIE6    = (bv.isIE && document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
bv.isIE5Mac = (bv.isIE && navigator.userAgent.indexOf('Mac') >= 0) ? true : false;
bv.isIE5    = (bv.isIE && ! bv.isIE5Mac && ! bv.isIE6) ? true : false;

bv.isMoz    = (! bv.isNS && ! bv.isOpr && ! bv.isIE && ! bv.isSafari && ! bv.isKonq && navigator.userAgent.indexOf("Mozilla") == 0) ? true : false;

function bv() {
	var v,s = "";
	for (v in bv) if (v.substring(0,2) == "is" && bv[v]) s += (s ? " " : "") + v;
	return s;
}

/*
 * Main functions
 */

function make_menu(id, header_id, keep_open) {

	

	var m;

	if (Menu.menus[id]) {

		

		var menu_id;
		for (menu_id in Menu.menus) {
			m = Menu.menus[menu_id];
			if (m.top.id == id) {
				m.hide_menu();
				delete Menu.menus[menu_id];
			}
		}
	}

	var manual    = false;
	keep_open = (keep_open != null && keep_open) ? true : Menu.KeepOpen;

	m = new Menu(id, header_id, manual, keep_open);

	m.configure_menu();

	var header_e = m.header_e;

	if (header_e) {

		if (header_e.onmouseover && header_e.onmouseover != Menu.onmouseover_handler)
			header_e.orig_onmouseover = header_e.onmouseover;
		if (header_e.onmouseout && header_e.onmouseout != Menu.onmouseout_handler)
			header_e.orig_onmouseout = header_e.onmouseout;
	
		header_e.onmouseover = Menu.onmouseover_handler;
		header_e.onmouseout  = Menu.onmouseout_handler;

		if (bv.isNS) Menu.set_enclosed_elements_handler(header_e);
	}
	else {

		m.setup_menu();
	}
	if (document.body.parentNode.onclick
	&& document.body.parentNode.onclick != Menu.onclick_body_handler)
		Menu.orig_onclick_body_handler = document.body.parentNode.onclick;
	document.body.parentNode.onclick = Menu.onclick_body_handler;
	if (window.onresize && window.onresize != Menu.onresize_handler)
		Menu.orig_onresize_handler = window.onresize;
	window.onresize = Menu.onresize_handler;
	
	return m;
}

function menu(id, header_id, keep_open) {
	var m = Menu.menus[id];
	if (!m) {
		if (! getElementRef(id)) {
			
			return;
		}

		var manual = true;
		keep_open = keep_open ? true : false;

		m = new Menu(id, header_id, manual, keep_open);

		m.configure_menu();
		
		Menu.build_submenus(m, getElementRef(id));
	}

	if (! m.header_e) {
		return;
	}
	if (m.keep_open && ! m.manual) {
		m.freeze();
		return;
	}
	if (m.is_visible) {
		if (m.manual) {
			if (m.click_stop_auto_set) m.click_stop_auto_set = m.ClickStop = false;
			m.hide_submenu();
		}
		else {
			m.ClickStop = true;
			m.click_stop_auto_set = true;
			m.show_menu();

			if (Menu.is_effects_loaded && autoplay.is_activated) autoplay.pause();
			Menu.click_stop_menu = m;
		}
	}
	else {
		m.show_menu();
	}
}

function submenu(id) {

	

	var m = Menu.menus[id];

	if (m) {
		if (! m.manual) return;

		if (m.is_visible) { m.hide_submenu(); }
		else {
			if (m.parent.child) m.parent.hide_submenu();
			m.parent.show_submenu(id);
		}

		return;
	}

	
}

function hide_menus(force_relocation) {

	

	var m,id;
	for (id in Menu.menus) {
		m = Menu.menus[id];
		if (! m.keep_open) m.hide_menu();
		if (force_relocation) m.is_located = false;
	}

	Menu.click_start_enabled = false;
}

function reset_menus() { initialize_menus(); }

function initialize_menus() {

/*
 * Menu settings
 */
Menu.MenuOffsetX = 0;
Menu.MenuOffsetY = 0;
Menu.SubmenuOffsetX = 0;
Menu.SubmenuOffsetY = 0;
Menu.MenuPosition    = "R";
Menu.SubmenuPosition = "L";
Menu.MenuAlign = "L";
Menu.SubmenuAlign = "D";
Menu.AllowReposition = true;
Menu.MenuOrientation    = "V";
Menu.SubmenuOrientation = "V";
Menu.BodyMarginTop = 0;
Menu.ClickStart = false;
Menu.ClickStop = Menu.ClickStart || false;
Menu.KeepOpen = false;
Menu.HideDelayTime = 0;
Menu.AllowFreeze = true;
Menu.CacheLocation = true;
Menu.MenuFixed = false;
Menu.SubmenuFixed = false;
Menu.ZIndex = 1000;
Menu.HighlightSuffix = "-hilite";
Menu.OnShowMenu = null;
Menu.OnHideMenu = null;
Menu.TimeToShow = 150;
Menu.TimeToHide = 100;
Menu.Group++;
if (Menu.initialize_effects) Menu.initialize_effects();

}
Menu.Group = -1;

initialize_menus();
Menu.menus = {};
Menu.click_start_enabled = false;
Menu.click_stop_menu = null;
Menu.hide_delay_timer = null;
Menu.keep_open_menu = [];
Menu.frozen_menu = null;
Menu.max_z = 0;
Menu.is_effects_loaded = false;
Menu.menu_re    = /menu\([ 	]*(['"]?)([^'",)]+)/;
Menu.submenu_re = /submenu\([ 	]*(['"]?)([^'",)]+)/;

/*
 * Menu object definition
 */

function Menu(id, header, manual, keep_open) {
	
	

	if (id)     this.e        = getElementRef(id);
	if (header) this.header_e = getElementRef(header);

	if (header && ! this.header_e) {
		
	}

	this.id			= id;

	this.is_submenu		= false;
	this.is_setup		= false;
	this.is_located		= false;
	this.is_finalized	= false;
	this.is_fixed		= false;
	this.is_static		= this.header_e ? false : true;
	this.is_visible		= this.is_static ? true : false;

	this.parent		= null;
	this.child		= null;
	this.top		= this;

	this.x			= null;
	this.y			= null;
	this.z			= Menu.ZIndex;

	this.evt		= null;

	this.frozen_e		= null;
	this.frozen_onmouseout	= null;
	this.saved_body_onclick	= null;

	this.show_timer		= 0;
	this.hide_timer		= 0;

	this.manual		= manual;
	this.keep_open		= keep_open;
	Menu.menus[id] = this;
}

/*
 * Event handlers
 */

Menu.get_evt = function(evt) {

	return evt ? evt : window.event ? window.event : null;
}

Menu.get_evt_target = function(evt) {

	return evt.target ? evt.target : evt.srcElement ? evt.srcElement : null;
}

Menu.get_menu_id = function(href) {

	if (bv.isKonq) {
		return href.match(Menu.menu_re).replace(/.*['"]/,"");
	}
	else {
		return RegExp.$1 ? RegExp.$2 : eval(RegExp.$2);
	}
}


Menu.onmouseover_handler = function(evt) {
	evt = Menu.get_evt(evt);
	var e = Menu.get_evt_target(evt);

	

	clearTimeout(Menu.hide_delay_timer);
	var menu_id, submenu_id, submenu_target;	
	var m, target_e;
	for (target_e = e; target_e != null; target_e = target_e.parentNode) {
		if (target_e.orig_onmouseover) target_e.orig_onmouseover(evt);

		if (target_e.id && (m = Menu.menus[target_e.id])) {

			if (Menu.frozen_menu
			&& Menu.frozen_menu.e != target_e) Menu.frozen_menu.thaw();

			m.save_event(evt);
			if (m.child && (! submenu_id || m.child.id != submenu_id)) {
				m.child.hide_submenu();
			}

			if (submenu_id) { m.show_submenu(submenu_id,submenu_target); }
			else            { m.show_menu(); }

			if (Menu.is_effects_loaded && autoplay.is_activated) autoplay.pause();

			break;
		}

		if (target_e.href) {
			if (target_e.href.match(Menu.submenu_re)) {
				submenu_id = Menu.get_menu_id(target_e.href);
				submenu_target = target_e;
				continue;
			}

			if (target_e.href.match(Menu.menu_re)) {

				if (Menu.is_effects_loaded && autoplay.is_activated) 
					autoplay.pause();

				menu_id = Menu.get_menu_id(target_e.href);

				if (Menu.frozen_menu) Menu.frozen_menu.thaw();

				if ((m = Menu.menus[menu_id])) {

					if (! m.is_located) m.save_event(evt);
					if (m.ClickStart && ! Menu.click_start_enabled) {
						
						break;
					}

					m.show_menu();
				}

				break;
			}
		}
	}
}

Menu.onmouseout_handler = function(evt) {
	evt = Menu.get_evt(evt);
	var e = Menu.get_evt_target(evt);
	

	if (bv.isNS) {

		if (e.nodeName == "TEXTAREA") return;
		if (e.nodeName == "OPTION") return;
	}
	var m, top;
	var menu_id, submenu_id;
	var target_e;
	for (target_e = e; target_e != null; target_e = target_e.parentNode) {
		if (target_e.orig_onmouseout) target_e.orig_onmouseout(evt);

		if (target_e.id && (m = Menu.menus[target_e.id])) {
			if (Menu.is_effects_loaded && autoplay.is_activated
			&& ! Menu.frozen_menu && ! Menu.click_stop_menu) autoplay.resume();
			if (m.keep_open) break;
			if (m.top.ClickStop) {
				if (m.top.click_stop_auto_set)
					m.top.click_stop_auto_set = m.top.ClickStop = false;
				if (m.top.HideDelayTime) {
					

					Menu.hide_delay_timer = setTimeout(
					  "hide_menus()", m.top.HideDelayTime);
				}
				break;
			}
			m.top.hide_submenu();

			break;
		}

		if (target_e.href) {

			if (target_e.href.match(Menu.submenu_re)) {
				submenu_id = Menu.get_menu_id(target_e.href);
				continue;
			}

			if (target_e.href.match(Menu.menu_re)) {

				menu_id = Menu.get_menu_id(target_e.href);

				if ((m = Menu.menus[menu_id])) {
					if (Menu.is_effects_loaded && autoplay.is_activated
					&& ! Menu.frozen_menu && ! Menu.click_stop_menu)
						autoplay.resume();
					if (m.ClickStop) {

						if (m.HideDelayTime) {
							

							Menu.hide_delay_timer = setTimeout(
							  "hide_menus()", m.HideDelayTime);

							break;
						}
						else {

							

							break;
						}
					}
					if (m.keep_open) {
						if (Menu.keep_open_menu[m.Group]
						&&  Menu.keep_open_menu[m.Group] != m) {
							clearTimeout(m.show_timer);
							Menu.keep_open_menu[m.Group].show_menu();
						}

						

						break;
					}
					m.hide_submenu();
				}

				break;
			}
		}
	}
}

Menu.onclick_handler = function(evt) {
	evt = Menu.get_evt(evt);
	var e = Menu.get_evt_target(evt);
	var m, target_e;
	for (target_e = e; target_e != null; target_e = target_e.parentNode) {

		if (target_e.href && ! target_e.href.match(Menu.submenu_re)) {
			hide_menus();
			if (Menu.is_effects_loaded && autoplay.is_activated) autoplay.pause();
			break;
		}

		if (! target_e.onclick) continue;

		if (target_e.orig_onclick) target_e.orig_onclick(evt);

		if (target_e.id && (m = Menu.menus[target_e.id])) {

			m.freeze();
			break;
		}
	}

	if (! bv.isSafari) {
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
	}

	return true;
}

Menu.onclick_handler_ignore = function(evt) {
	evt = Menu.get_evt(evt);
	var e = Menu.get_evt_target(evt);

	

	if (e.orig_onclick) e.orig_onclick(evt);

	evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();

	if (bv.isSafari || bv.isKonq) {
		while (e) {
			if (e.href && e.href.match(Menu.submenu_re)) {

				submenu(Menu.get_menu_id(e.href));
				break;
			}
			e = e.parentNode;
		}
	}

	return true;
}

Menu.onclick_body_handler = function(evt) {

	

	hide_menus();

	if (Menu.orig_onclick_body_handler) {
		
		return Menu.orig_onclick_body_handler(evt);
	}
}

Menu.onresize_handler = function(evt) {

	

	hide_menus('relocate');
	if (Menu.orig_onresize_handler) return Menu.orig_onresize_handler(evt);
}

/*
 * Freezing methods
 */
Menu.onclick_body_handler_thaw = function(evt) {

	

	if (Menu.frozen_menu) Menu.frozen_menu.thaw();
}

Menu.prototype.freeze = function() {
	if (this.is_fixed) this.hide_opened_menus();

	if (Menu.frozen_menu) {
		if (Menu.frozen_menu == this) {
			return;	
		}
		else {
			Menu.frozen_menu.thaw();
		}
	}

	this.frozen_e = this.e;
	this.frozen_onmouseout   = this.frozen_e.onmouseout;
	this.frozen_e.onmouseout = null;

	this.saved_body_onclick = document.body.parentNode.onclick;
	document.body.parentNode.onclick = Menu.onclick_body_handler_thaw;

	if (Menu.is_effects_loaded && autoplay.is_activated) autoplay.pause();

	Menu.frozen_menu = this;
	if (bv.isMoz) this.show_menu();
}

Menu.prototype.thaw = function() {

	

	if (this.frozen_e) {
		this.frozen_e.onmouseout = this.frozen_onmouseout;
		document.body.parentNode.onclick = this.saved_body_onclick;
	}

	this.frozen_e = null;

	Menu.frozen_menu = null;

	if (! this.top.keep_open) {
		if (this.child) this.hide_submenu();
		var m = this;
		do {
			

			m.hide_menu();
		} while ((m = m.parent));
	}
	if (Menu.is_effects_loaded && autoplay.is_activated) autoplay.resume();

}

/*
 * Menu builder
 */
Menu.filter_object = {
	"#text":	true,
	"SELECT":	true,
	"TEXTAREA":	true};

Menu.build_submenus = function(m,e) {

	

	if (e.href && e.href.match(Menu.submenu_re)) {

		var id = Menu.get_menu_id(e.href);

		var submenu = m.make_submenu(id,e);
		Menu.build_submenus(submenu, getElementRef(id));

		

		return;
	}

	if (e.childNodes) {

		var n;
		for (n = 0; n < e.childNodes.length; n++) {

			if (! Menu.filter_object[e.childNodes[n].nodeName]) {

				

				Menu.build_submenus(m, e.childNodes[n]);
			}
		}
	}

	
}

Menu.set_enclosed_elements_handler = function(e) {

	var child_e;

	if (e.childNodes) {

		var n;
		for (n = 0; n < e.childNodes.length; n++) {

			child_e = e.childNodes[n];

			if (child_e.nodeType != 1) continue;
			if (child_e.onmouseover
			&& child_e.onmouseover != Menu.onmouseover_handler)
				child_e.orig_onmouseover = child_e.onmouseover;

			child_e.onmouseover = Menu.onmouseover_handler;

			
		}
	}
}

Menu.prototype.make_submenu = function(menu_id, header) {

	var submenu = new Menu(menu_id, header, this.manual, this.keep_open);
	submenu.parent = this;
	submenu.top    = this.top;
	submenu.is_submenu = true;
	submenu.z = this.z + 10;
	
	return submenu;
}

Menu.prototype.configure_menu = function() {

	var v,c;
	for (v in Menu) {
		c = v.substr(0,1);
		if (c == c.toUpperCase()) {

			

			this[v] = Menu[v];
		}
	}
}


Menu.prototype.setup_menu = function() {

	if (! this.e) this.e = getElementRef(this.id);

	if (! this.e) {
		
		return;
	}

	if (this.manual) {

		this.is_located   = true;
		this.is_finalized = true;

		this.e.style.zIndex = Menu.ZIndex;

		this.AllowReposition = false;

		if (document.body.parentNode.onclick && ! this.e.onclick) {
			this.e.onclick = Menu.onclick_handler_ignore;
		}
	}
	else {
		if (! this.is_submenu) this.setup_top_menu();
		this.is_fixed = this.is_submenu
			      ? (this.top.SubmenuFixed || false)
			      : (this.top.MenuFixed || false);
		if (this.e.onmouseover && this.e.onmouseover != Menu.onmouseover_handler)
			this.e.orig_onmouseover = this.e.onmouseover;
		if (this.e.onmouseout && this.e.onmouseout != Menu.onmouseout_handler)
			this.e.orig_onmouseout  = this.e.onmouseout;
		if (this.e.onclick && this.e.onclick != Menu.onclick_handler)
			this.e.orig_onclick     = this.e.onclick;
		this.e.onmouseover = Menu.onmouseover_handler;
		this.e.onmouseout  = Menu.onmouseout_handler;

		if (this.top.AllowFreeze) this.e.onclick = Menu.onclick_handler;

		if (bv.isNS) Menu.set_enclosed_elements_handler(this.e);
	}

	this.set_display_none	= (getElementStyle(this.e,"display") == "none") || bv.isSafari
				? true
				: false;

	this.is_setup = true;
}

Menu.prototype.setup_top_menu = function() {

	if (this.ClickStart) this.ClickStop = true;

	if (this.HideDelayTime) {
		this.HideDelayTime = parseFloat(this.HideDelayTime) * 1000.0;
		this.ClickStop = true;

		
	}

	if (Menu.is_effects_loaded) {
		this.setup_triggers();
		this.setup_fade();
	}
}

Menu.prototype.locate_menu = function() {

	

	if (this.evt) {
		if (this.is_submenu)	{ this.compute_position_submenu(); }
		else			{ this.compute_position_menu();    }

		var fudge = bv.isIE5 && self.parent.frames.length == 0 ? -2 : 0;
		this.e.style.left = (this.x + fudge) + "px";
		this.e.style.top  = (this.y + fudge) + "px";
		if (bv.isOpr5) this.e.style.pixelTop  = (this.y + fudge);

		
	}

	this.e.style.zIndex  = this.z;

	if (this.top.CacheLocation
	&& (! this.parent || this.parent.is_located))
		this.is_located = true;
	this.is_finalized = false;
}

Menu.prototype.locate_static_menu = function(submenu) {

	var p = this.top.SubmenuPosition;
	if (p == "R" || p == "L") {

		this.x = getEventElementLeft(submenu.evt, this.e, 
					this.get_border_width("left"),
					this.get_padding("left"));
	}
	else {
		this.y = getEventElementTop(submenu.evt, this.e, 
					this.get_border_width("top"),
					this.get_padding("top"));
	}

	this.is_located = true;
}

Menu.prototype.finalize_menu = function() {

	if (! this.e) return;

	this.is_finalized = true;

	if (this.manual) return;

	if (this.is_submenu) {
		this.finalize_position_submenu();
		this.finalize_alignment_submenu();
	}
	else {
		this.finalize_position_menu();   
		this.finalize_alignment_menu();
	}

	var fudge = bv.isIE5 && self.parent.frames.length == 0 ? -2 : 0;
	this.e.style.left = (this.x + fudge) + "px";
	this.e.style.top  = (this.y + fudge) + "px";
	if (bv.isOpr5) this.e.style.pixelTop  = this.y;

	
}

Menu.prototype.save_event = function(evt) {

	this.evt = {
		"target"  : (evt.target ? evt.target : evt.srcElement ? evt.srcElement : null),

		"offsetX" : (evt.offsetX ? evt.offsetX : 0),
		"offsetY" : (evt.offsetY ? evt.offsetY : 0),
		"clientX" : (evt.clientX ? evt.clientX : 0),
		"clientY" : (evt.clientY ? evt.clientY : 0) };
}

/*
 * Showing methods
 */

Menu.prototype.show_menu = function() {

	

	clearTimeout(this.hide_timer);
	clearTimeout(this.show_timer);

	if (this.is_submenu) this.show_parentmenu();

	if (this.is_static) this.track_shown_keep_open_menus();

	if (this.is_visible) return;
	this.show_timer = setTimeout("Menu.menus['"+this.id+"'].do_show_menu()", this.top.TimeToShow);

	
}

Menu.prototype.do_show_menu = function() {

	

	if (this.is_visible) return;
	if (this.top.ClickStop && this.parent && ! this.parent.is_visible) return;

	if (! this.is_setup) this.setup_menu();

	if (! this.is_fixed
	&& (! this.is_located || (this.parent && ! this.parent.is_located))) this.locate_menu();
	if (Menu.is_effects_loaded
	&&  this.z > Menu.max_z) { Menu.max_z = this.z; }
	else			 { this.e.style.zIndex = this.z = ++Menu.max_z; }
	this.hide_opened_menus();
	if (this.tear_off_menu) this.tear_off_menu.close();
	if (Menu.is_effects_loaded) { this.show_menu_fade(); }
	else {
		if (this.set_display_none) this.e.style.display = "block";
		this.e.style.visibility = "visible";
	}

	if (! this.is_fixed) {

		if (! this.is_finalized) this.finalize_menu();

		if (this.top.AllowReposition) this.reposition_menu();
	}
	if (this.header_e.className) {
		this.header_e.className += this.top.HighlightSuffix;
	}

	this.is_visible = true;

	if (! this.is_submenu && ! this.manual) this.track_shown_keep_open_menus();

	if (this.top.OnShowMenu) this.top.OnShowMenu(this);
}

/*
 * Hiding methods
 */

Menu.prototype.hide_menu = function() {

	

	clearTimeout(this.hide_timer);
	clearTimeout(this.show_timer);

	if (this.is_static) this.track_hidden_keep_open_menus();

	if (! this.is_visible) return;
	this.hide_timer = setTimeout("Menu.menus['"+this.id+"'].do_hide_menu()", this.top.TimeToHide);

	
}

Menu.prototype.do_hide_menu = function() {

	

	if (! this.is_visible || this.is_static) return;
	if (Menu.is_effects_loaded) { this.hide_menu_fade(); }
	else {
		if (! this.tear_off_menu) {
			this.e.style.visibility = "hidden";
			if (this.set_display_none) this.e.style.display = "none";
		}
	}
	if (this.header_e.className && this.top.HighlightSuffix) {
		var re = new RegExp(this.top.HighlightSuffix);
		this.header_e.className = this.header_e.className.replace(re,"");
	}

	this.is_visible = false;

	if (! this.is_submenu && ! this.manual) this.track_hidden_keep_open_menus();

	if (this.top.OnHideMenu) this.top.OnHideMenu(this);
}

/*
 * Sub-menu methods
 */

Menu.prototype.show_submenu = function(menu_id,header) {

	

	var submenu = Menu.menus[menu_id];
	if (! submenu) submenu = this.make_submenu(menu_id,header);
	this.child = submenu;
	submenu.evt = this.evt;

	submenu.show_menu();
}

Menu.prototype.hide_submenu = function() {
	if (this.child) this.child.hide_submenu();

	this.hide_menu();
}

/*
 * Parent-menu methods
 */

Menu.prototype.show_parentmenu = function() {

	

	var m, child = this;

	while ((m = child.parent)) {

		

		m.show_menu();

		if (m.child && m.child != child) m.child.hide_submenu();

		m.child = child;

		child = m;
	}
}

/*
 * Open menu methods
 */

Menu.prototype.hide_opened_menus = function() {
	if (Menu.click_stop_menu && Menu.click_stop_menu != this.top) {

		

		Menu.click_stop_menu.hide_submenu();

		Menu.click_start_enabled = false;
	}
	if (this.keep_open) {
		var m = Menu.keep_open_menu[this.top.Group];
		if (m && m != this.top) {
			

			m.hide_submenu();
		}
	}
}

Menu.prototype.track_shown_keep_open_menus = function() {

	

	if (this.ClickStop) {
		if (Menu.click_stop_menu && Menu.click_stop_menu != this) {
			clearTimeout(Menu.hide_delay_timer);
			Menu.click_stop_menu.do_hide_menu();
		}

		Menu.click_stop_menu = this;
		Menu.click_start_enabled = true;

		
	}

	if (this.keep_open) {
		var m = Menu.keep_open_menu[this.top.Group];
		if (m && m != this) m.do_hide_menu();

		Menu.keep_open_menu[this.top.Group] = this;
		Menu.click_start_enabled = false;

		
	}
}

Menu.prototype.track_hidden_keep_open_menus = function() {

	

	if (Menu.click_stop_menu && Menu.click_stop_menu == this) {

		

		if (this.click_stop_auto_set) this.click_stop_auto_set = this.ClickStop = false;

		Menu.click_stop_menu = null;
	}

	var m = Menu.keep_open_menu[this.top.Group];
	if (m && m == this) {

		

		Menu.keep_open_menu[this.top.Group] = null;
	}
}

/*
 * Positioning methods
 */

Menu.prototype.compute_position_menu = function() {

	this.x	= getEventElementLeft(this.evt, this.header_e,
			this.get_header_border_width("left"),
			this.get_header_padding("left")) +
		  this.top.MenuOffsetX;

	this.y	= this.get_header_top() +
		  this.get_header_height() +
		  this.top.MenuOffsetY;

	
}

Menu.prototype.compute_position_submenu = function() {

	var parent = this.parent;

	if (parent.is_static && ! parent.is_located) parent.locate_static_menu(this);

	this.x	= (this.top.SubmenuOrientation == "V" && this.top.MenuOrientation == "V"
		? parent.x +
		  getElementWidth(parent.e)
		: getEventElementLeft(this.evt, this.header_e,
			this.get_header_border_width("left"),
			this.get_header_padding("left")) +
		  getElementWidth(this.header_e)
		  ) +
		  this.top.SubmenuOffsetX;

	this.y	= (this.top.SubmenuOrientation != "N"
		? this.compute_vert_menu_y()
		: this.get_header_top()
		  ) +
		  this.top.SubmenuOffsetY;

	
}

Menu.prototype.finalize_position_menu = function() {

	

	switch (this.top.MenuPosition) {
	case "U":
		this.y -= getElementHeight(this.e) +
			  this.get_header_height() +
			  this.top.MenuOffsetY * 2;
		break;

	case "L":
		this.x -= getElementWidth(this.e) +
			  this.top.MenuOffsetX * 2;

		this.y	= this.get_header_top() +
			  this.top.MenuOffsetY;
		break;

	case "R":
		this.x += getElementWidth(this.header_e);
		this.y	= this.get_header_top() +
			  this.top.MenuOffsetY;
		break;

	case "D":
	default:
	}
}

Menu.prototype.finalize_position_submenu = function() {

	

	switch (this.top.SubmenuPosition) {
	case "L":
		this.x	= (this.top.SubmenuOrientation == "V" && this.top.MenuOrientation == "V"
			? this.parent.x
			: getEventElementLeft(this.evt, this.header_e,
				this.get_header_border_width("left"),
				this.get_header_padding("left"))
			  ) -
			  getElementWidth(this.e) -
			  this.top.SubmenuOffsetX;
		break;

	case "D":
		this.x	= (this.top.SubmenuOrientation != "N"
			? this.compute_horz_menu_x()
			: getEventElementLeft(this.evt, this.header_e,
				this.get_header_border_width("left"),
				this.get_header_padding("left"))
			  ) +
			  this.top.SubmenuOffsetX;

		this.y	= (this.top.SubmenuOrientation == "H" && this.top.MenuOrientation == "H"
			? this.parent.y +
			  getElementHeight(this.parent.e, this.parent.getBorderHeight())
			: this.get_header_top() +
			  this.get_header_height()
			  ) +
			  this.top.SubmenuOffsetY;
		break;

	case "U":
		this.x	= (this.top.SubmenuOrientation != "N"
			? this.compute_horz_menu_x()
			: getEventElementLeft(this.evt, this.header_e,
				this.get_header_border_width("left"),
				this.get_header_padding("left"))
			  ) +
			  this.top.SubmenuOffsetX;

		this.y	= (this.top.SubmenuOrientation == "H" && this.top.MenuOrientation == "H"
			? this.parent.y
			: this.get_header_top()
			  ) -
			  getElementHeight(this.e, this.getBorderHeight()) -
			  this.top.SubmenuOffsetY;
		break;

	case "R":
	default:
	}
}

Menu.prototype.finalize_alignment_menu = function() {
	switch (this.top.MenuAlign) {
	case "R":
		this.x -= getElementWidth(this.e)
			- getElementWidth(this.header_e)
			+ this.top.MenuOffsetX;
		break;
	case "B":
		this.y -= getElementHeight(this.e)
			- getElementHeight(this.header_e)
			+ this.top.MenuOffsetY;
		break;
	case "L":
	case "T":
	default:
	}
}

Menu.prototype.finalize_alignment_submenu = function() {
	switch (this.top.SubmenuAlign) {
	case "R":
		this.x -= getElementWidth(this.e)
			- getElementWidth(this.parent.e)
			+ this.top.SubmenuOffsetX;
		break;
	case "B":
		this.y -= getElementHeight(this.e)
			- getElementHeight(this.parent.e)
			+ this.top.SubmenuOffsetY;
		break;
	case "L":
	case "T":
	default:
	}
}

Menu.prototype.reposition_menu = function() {

	var reposition = false;

	var e = this.e;
	var b = document.body;
	var wwidth  = window.innerWidth	 ? window.innerWidth
		    : b.clientWidth	 ? b.clientWidth
		    : b.offsetWidth;
	var wheight = window.innerHeight ? window.innerHeight
	            : b.clientHeight     ? b.clientHeight
		    : b.offsetHeight;
	var wleft   = b.scrollLeft	 ? b.scrollLeft
		    : (b.parentNode && b.parentNode.scrollLeft) ? b.parentNode.scrollLeft
		    : 0;
	var wtop    = b.scrollTop	 ? b.scrollTop
		    : (b.parentNode && b.parentNode.scrollTop) ? b.parentNode.scrollTop
		    : 0;
	var wright  = wleft + wwidth;
	var wbottom = wtop  + wheight;
	var ewidth  = e.offsetWidth	? e.offsetWidth	 : getElementWidth(e);
	var eheight = e.offsetHeight	? e.offsetHeight : getElementHeight(e);
	var eleft   = e.offsetLeft	? e.offsetLeft	 : getElementLeft(e);
	var etop    = e.offsetTop	? e.offsetTop	 : getElementTop(e);
	var eright  = eleft + ewidth;
	var ebottom = etop  + eheight;

	
	

	if (eright > wright) {
		eleft = wright - ewidth;
		reposition = true;
	}

	if (ebottom > wbottom) {
		etop = wbottom - eheight;
		reposition = true;
	}

	if (eleft < wleft) {
		eleft = wleft;
		reposition = true;
	}

	if (etop < wtop) {
		etop = wtop;
		reposition = true;
	}

	if (reposition) {
		this.e.style.left = eleft + "px";
		this.e.style.top  = etop  + "px";

		if (bv.isOpr5) this.e.style.pixelTop = etop;

		this.is_located = false;

		
	}
}

Menu.prototype.compute_horz_menu_x = function() {

	var l = getEventElementLeft(this.evt, this.header_e,
				this.get_header_border_width("left"),
				this.get_header_padding("left"));
	var o = tableOffset(this.e);
	var p = this.get_padding("left");
	var b = this.get_border_width("left");

	

	return l - o - p - b;
}

Menu.prototype.compute_vert_menu_y = function() {

	var t = this.get_header_top();
	var o = tableOffset(this.e);
	var p = this.get_padding("top");
	var b = this.get_border_width("top");

	

	return t - o - p - b;
}

Menu.prototype.get_header_top = function() {
	
	var header_e = this.header_e;
	var hy;

	if (bv.isIE) {
		hy = getEventElementTop(this.evt, header_e,
					this.get_header_border_width("top"),
					this.get_header_padding("top"));

		
		return hy;
	}
		
	hy = getEventElementTop(this.evt, header_e);

	var is_aimg = false;
	if (this.evt.target.nodeName == "IMG") {
		var d = getElementStyle(header_e,"display");
		if (d == "inline") is_aimg = true;
		if (d == "") is_aimg = true;
	}
	if ((bv.isOpr5 || bv.isOpr6)
	&& this.evt.target.toString().indexOf("HTMLImage") > 0) is_aimg = true;

	if (is_aimg) {

		

		var iy = getEventElementTop(this.evt);

		

		return iy < hy ? iy : hy;
	}

	
	return hy;
}

Menu.prototype.get_header_height = function() {

	var header_e = this.header_e;

	if (bv.isIE) return getElementHeight(header_e);

	var is_aimg = false;
	if (this.evt.target.nodeName == "IMG") {
		var d = getElementStyle(header_e,"display");
		if (d == "inline") is_aimg = true;
		if (d == "") is_aimg = true;
	}
	if ((bv.isOpr5 || bv.isOpr6)
	&& this.evt.target.toString().indexOf("HTMLImage") > 0) is_aimg = true;
	if (bv.isOpr7) is_aimg = true;

	if (is_aimg) {

		

		var ih = getElementHeight(this.evt.target);
		var hh = getElementHeight(header_e);
		return ih > hh ? ih : hh;
	}

	return getElementHeight(header_e);
}

/*
 * Style properties
 */

Menu.prototype.get_border_width = function(position) {

	var width = getBorderWidth(this.e,position);

	

	if (getBorderWidth.found) return width;

	

	if (this.is_submenu && this.top.SubmenuBorderWidth != null)
		return this.top.SubmenuBorderWidth;

	if (this.top.MenuBorderWidth != null)
		return this.top.MenuBorderWidth;

	return 0;
}

Menu.prototype.get_header_border_width = function(position) {

	var width = getBorderWidth(this.header_e,position);

	

	if (getBorderWidth.found) return width;

	

	if (this.is_submenu) {
		if (this.top.SubmenuHeaderBorderWidth != null)
			return this.top.SubmenuHeaderBorderWidth;
	}
	else {
		if (this.top.MenuHeaderBorderWidth != null) 
			return this.top.MenuHeaderBorderWidth;
	}
	return 0;
}

Menu.prototype.get_padding = function(position) {

	var p = getPadding(this.e,position);

	

	if (getPadding.found) return p;

	

	if (this.is_submenu) {
		if (this.top.SubmenuPaddingHorz != null
		&& (position == "left" || position == "right"))
			return this.top.SubmenuPaddingHorz;

		if (this.top.SubmenuPaddingVert != null
		&& (position == "top" || position == "bottom"))
			return this.top.SubmenuPaddingVert;

		if (this.top.SubmenuPadding != null)
			return this.top.SubmenuPadding;
	}

	if (this.top.MenuPaddingHorz != null
	&& (position == "left" || position == "right"))
		return this.top.MenuPaddingHorz;

	if (this.top.MenuPaddingVert != null
	&& (position == "top" || position == "bottom"))
		return this.top.MenuPaddingVert;

	if (this.top.MenuPadding != null)
		return this.top.MenuPadding;

	return 0;
}

Menu.prototype.get_header_padding = function(position) {

	var p = getPadding(this.header_e,position);

	

	if (getPadding.found) return p;

	

	if (this.is_submenu) {
		if (this.top.SubmenuHeaderPaddingHorz != null
		&& (position == "left" || position == "right"))
			return this.top.SubmenuHeaderPaddingHorz;

		if (this.top.SubmenuHeaderPaddingVert != null
		&& (position == "top" || position == "bottom"))
			return this.top.SubmenuHeaderPaddingVert;

		if (this.top.SubmenuHeaderPadding != null)
			return this.top.SubmenuHeaderPadding;
	}

	return 0;
}

Menu.prototype.getBorderWidth = function() {
	if (this.BorderWidth == null) this.BorderWidth = Math.floor((this.get_border_width("left") + this.get_border_width("right"))/2);
	return this.BorderWidth;
}

Menu.prototype.getBorderHeight = function() {
	if (this.BorderHeight == null) this.BorderHeight = Math.floor((this.get_border_width("top") + this.get_border_width("bottom"))/2);
	return this.BorderHeight;
}



/*
 * Utility functions
 */

function parseNum(s) {

	if (s) return parseInt("0"+s,10);
	return 0;
}

function getElementRef(id) {

	if (! id) return null;
	if (typeof id == "string") {
		if (document.getElementById) return document.getElementById(id);
		if (document.all) return document.all[id];
		return null;
	}
	if (typeof id == "object") return id;
	return null;
}

function getEventElementLeft(evt,target_e	,border_width,padding_width) {

	if (! evt) evt = window.event;
	if (! target_e) target_e = evt.target ? evt.target     : 
			       evt.srcElement ? evt.srcElement : null;
	target_e = getElementRef(target_e);

	var x;

	var e, ox;
	var target_offset = 0;

	if (bv.isIE5 || bv.isOpr5) {

		if (border_width == null) border_width = getBorderWidth(target_e,"left");
		e = evt.target ? evt.target : evt.srcElement ? evt.srcElement : null;

		if (! e.nodeName || e.nodeName != "IMG"
		|| ! e.parentNode || e.parentNode.nodeName != "A"
		|| ! e.offsetParent || e.offsetParent.nodeName == "A") {

			while (e) {
				if (e == target_e) break;

				

				target_offset += e.offsetLeft;

				e = e.offsetParent;
			}
		}

		target_offset += border_width;

		x = evt.clientX - evt.offsetX - target_offset;

		if (bv.isIE5) x += document.body.scrollLeft;

		

		return x;
	}
	else if (bv.isIE5Mac) {

		if (border_width == null)  border_width  = getBorderWidth(e,"left");
		if (padding_width == null) padding_width = getPadding(e,"left");
		e = evt.target ? evt.target : evt.srcElement ? evt.srcElement : null;

		if (e.nodeName && e.nodeName == "IMG"
		&& e.parentNode && e.parentNode.nodeName == "A"
		&& e.offsetParent && e.offsetParent.nodeName != "A") {

			x = evt.clientX - evt.offsetX - border_width - padding_width;

			
		}
		else {
			ox = 0;
			target_found = false;

			while (e) {
				

				ox += e.offsetLeft;

				if (e == target_e) target_found = true;
				if (! target_found) { target_offset += e.offsetLeft; }

				e = e.offsetParent;
			}

			target_offset += border_width + padding_width;

			x = getMargin(document.body,"left") + ox - target_offset;

			
		}

		return x;
	}
	else if (bv.isOpr6) {

		x = getElementLeft(target_e);

		

		return x;
	}
	else {
		e = target_e;
		while (e && e.nodeType != 1) { e = e.parentNode };

		x = getElementLeft(e);

		

		return x;
	}

	return 0;
}

function getEventElementTop(evt,target_e	,border_width,padding_width) {

	if (! evt) evt = window.event;
	if (! target_e) target_e = evt.target ? evt.target     : 
			       evt.srcElement ? evt.srcElement : null;
	target_e = getElementRef(target_e);

	

	var y;

	var e, oy;
	var target_offset = 0;

	if (bv.isIE5 || bv.isIE5Mac || bv.isOpr5) {

		if (border_width == null) border_width = getBorderWidth(target_e,"top");
		if (bv.isIE5Mac && padding_width == null) padding_width = getPadding(target_e,"top");
		e = evt.target ? evt.target : evt.srcElement ? evt.srcElement : null;
		oy = evt.offsetY;

		if (! e.nodeName || e.nodeName != "IMG"
		|| ! e.parentNode || e.parentNode.nodeName != "A"
		|| ! e.offsetParent || e.offsetParent.nodeName == "A") {

			while (e) {
				if (e == target_e) break;

				

				target_offset += e.offsetTop;

				e = e.offsetParent;
			}
		}

		target_offset += border_width;
		if (bv.isIE5Mac) target_offset += padding_width;

		y = evt.clientY - oy - target_offset;

		if (bv.isIE5) y += document.body.scrollTop;

		

		return y;
	}
	else if (bv.isOpr6) {

		y = getElementTop(target_e) + Menu.BodyMarginTop;

		

		return y;
	}
	else {
		e = target_e;
		while (e && e.nodeType != 1) { e = e.parentNode };

		y = getElementTop(e);

		

		return y;
	}

	return 0;
}

function getElementLeft(e) {

	

	var x = e.offsetLeft;

	while ((e = e.offsetParent)) {
		

		x += e.offsetLeft;

		if (bv.isSafari || bv.isKonq) {
			if (getElementStyle(e,'position') == 'absolute') break;
		}
		else {
			if (! ((bv.isNS71 || bv.isIE6 || bv.isMoz) && e.nodeName == 'TABLE') ) {
				x += getBorderWidth(e,"left");
			}
		}

		if (e.border && parseNum(e.border) > 0) {
			if (bv.isNS  || bv.isMoz)  x--;
			if (bv.isIE6 || bv.isOpr7) x++;
		}
	}

	

	return x;
}

function getElementTop(e) {

	

	var y = e.offsetTop;

	while ((e = e.offsetParent)) {
		

		y += e.offsetTop;

		if (bv.isSafari || bv.isKonq) {
			if (getElementStyle(e,'position') == 'absolute') break;
		}
		else {
			if (! ((bv.isNS71 || bv.isIE6 || bv.isMoz) && e.nodeName == 'TABLE') ) {
				y += getBorderWidth(e,"top");
			}
		}

		if (parseNum(e.border) > 0) {
			if (bv.isNS  || bv.isMoz)  y--;
			if (bv.isIE6 || bv.isOpr7) y++;
		}
	}

	

	return y;
}

function getElementStyle(e,
			dom_prop,		css_attr,
			dom_gen_prop,		css_gen_attr,     position,
			dom_border_prop,	css_border_attr,  component,
			dom_border_gen_prop,	css_border_gen_attr) {

	if (! css_attr) css_attr = dom_prop;

	

	var sty;

	if (e.style) {
		if ((sty = e.style[dom_prop])) {
			
		}
		else if (dom_gen_prop != null && (sty = e.style[dom_gen_prop])) {
			
			sty = parseStyleSetting(sty,position);
		}
		else if (dom_border_prop != null && (sty = e.style[dom_border_prop])) {
			
			sty = parseBorderSetting(sty,component);
		}
		else if (dom_border_gen_prop != null && (sty = e.style[dom_border_gen_prop])) {
			
			sty = parseBorderSetting(sty,component);
		}

		if (sty) {
			if (component == null || component != "width") {
				return sty;
			}
			else {

				if (sty.match(/\d/)) return sty;
			}
		}
	}

	

	var vs, v = document.defaultView;
	if (v && v.getComputedStyle && (vs = v.getComputedStyle(e,""))) {

		sty = vs.getPropertyValue(css_attr);

		if (sty != null) {

			if (sty == '0px' && e.nodeName == 'TABLE'
			&& (css_gen_attr == 'padding' || css_gen_attr == 'margin')) {
				;
				
			}
			else {
				return sty;
			}
		}

		if (css_gen_attr != null) {
			sty = parseStyleSetting(vs.getPropertyValue(css_gen_attr),position);

			if (sty != null) {
				
				return sty;
			}
		}

		if (css_border_attr != null) {
			sty = parseBorderSetting(
			  vs.getPropertyValue(css_border_attr),component);

			if (sty != null) {
				
				return sty;
			}
		}

		if (css_border_gen_attr != null) {
			sty = parseBorderSetting(
			  vs.getPropertyValue(css_border_gen_attr),component);

			if (sty != null) {
				
				return sty;
			}
		}
	}

	

	if (e.currentStyle) {

		sty = e.currentStyle[dom_prop];

		if (sty != null) {
			
			return sty;
		}

		if (dom_gen_prop != null) {
			sty = parseStyleSetting(e.currentStyle[dom_gen_prop],position);

			if (sty != null) {
				
				return sty;
			}
		}

		if (dom_border_prop != null) {
			sty = parseBorderSetting(e.currentStyle[dom_border_prop],component);

			if (sty != null) {
				
				return sty;
			}
		}

		if (dom_border_gen_prop != null) {
			sty = parseBorderSetting(e.currentStyle[dom_border_gen_prop],component);

			if (sty != null) {
				
				return sty;
			}
		}
	}
	var sheets = document.styleSheets;
	var sheet, s;
	if(sheets && sheets.length > 0) {
		for(var x = 0; x < sheets.length; x++) {
			var rules = sheets[x].cssRules;
			if(rules && rules.length > 0) {
				for(var y = 0; y < rules.length; y++) {
					if (rules[y].style) {
						s = getElementStyleFromRule(e,css_attr,rules[y]);
						if (s != null) sty = s;
					}
					else {
						sheet = rules[y].styleSheet;
						for (var z = 0; z < sheet.cssRules.length; z++) {
							s = getElementStyleFromRule(e,css_attr,sheet.cssRules[z]);
							if (s != null) sty = s;
						}
					}
				}
			}
		}
	}

	if (sty != null) {
		
		return sty;
	}

	

	return null;
}

function getElementStyleFromRule(e, css_attr, rule) {

	var t = rule.selectorText;
	var z = rule.style;
	if (bv.isSafari) {
		if (t.substr(0,1) == '*') {
			t = '#' + t.substr(5,(t.length-7));
		} else {
			t = t.replace((new RegExp("\\[.*?\\]")),"");
		}
	}

	var re = e.className ? new RegExp("\\."+e.className+"$") : null;

	if(z[css_attr] != '' && z[css_attr] != null
	&& ((t == e.nodeName || t.match(re)) || (e.id && t == '#' + e.id))) {
		

		return z[css_attr];
	}
	

	return null;
}

function parseStyleSetting(setting,position) {

	if (! setting) return null;
	if (! position) return setting;
	setting.match(/(\S+)(\s+(\S+)(\s+(\S+)(\s+(\S+))?)?)?/);

	if (position == "top") {
		return RegExp.$1;
	}

	if (position == "right") {
		if (RegExp.$3) return RegExp.$3;
		return RegExp.$1;
	}

	if (position == "bottom") {
		if (RegExp.$5) return RegExp.$5;
		return RegExp.$1;
	}

	if (position == "left") {
		if (RegExp.$7) return RegExp.$7;
		if (RegExp.$3) return RegExp.$3;
		return RegExp.$1;
	}
}

function parseBorderSetting(setting,component) {

	if (! component || component == "width") {
		if (setting.match(/(\d+px)/)) return RegExp.$1;
		return 0;
	}
}

function getBorderWidth(e,position) {

	

	var width;
	
	var dom_gen_prop = "borderWidth";
	var css_gen_attr = "border-width";

	var dom_border_gen_prop = "border";
	var css_border_gen_attr = "border";

	if (! position) {
		width = getElementStyle(e,
			  dom_gen_prop,		css_gen_attr,
			  null,		 	null,			null,
			  dom_border_gen_prop,	css_border_gen_attr,	"width");
	}
	else {
		var Position = position.substr(0,1).toUpperCase()+position.substr(1);

		var dom_prop = "border"  + Position + "Width";
		var css_attr = "border-" + position + "-width";

		var dom_border_prop = "border"  + Position;
		var css_border_attr = "border-" + position;

		width = getElementStyle(e,
			  dom_prop,		css_attr,
			  dom_gen_prop,		css_gen_attr,		position,
			  dom_border_prop,	css_border_attr,	"width",
			  dom_border_gen_prop,	css_border_gen_attr);
	}
	if (width == null || ! width.match(/\d/)) {
		getBorderWidth.found = false;
		
		return 0;
	}
	else {
		getBorderWidth.found = true;
		return parseNum(width);
	}
}

function getPadding(e,position) {

	var p,s = "padding";

	if (! position) {
		p = getElementStyle(e,s,s);
	}
	else {
		var Position = position.substr(0,1).toUpperCase()+position.substr(1);
		p = getElementStyle(e, (s+Position), (s+"-"+position), s, s, position);
	}

	if (p == null) {
		getPadding.found = false;
		
		return 0;
	}
	else {
		getPadding.found = true;
		return parseNum(p);
	}
}

function getMargin(e,position) {

	var m,s = "margin";

	if (! position) {
		m = getElementStyle(e,s,s);
	}
	else {
		var Position = position.substr(0,1).toUpperCase()+position.substr(1);
		m = getElementStyle(e, (s+Position), (s+"-"+position), s, s, position);
	}

	if (m == null) {
		getMargin.found = false;
		
		return 0;
	}
	else {
		getMargin.found = true;
		return parseNum(m);
	}
}

function tableOffset(e) {

	var offset = 0;

	if (e && e.nodeName == "TABLE") {

		

		offset = (e.cellPadding == "" ? 1 : parseNum(e.cellPadding)) +
			 (e.cellSpacing == "" ? 1 : parseNum(e.cellSpacing)) +
			 parseNum(e.border);

		if (e.cellPadding == "" && e.cellSpacing == "") offset++;
	}
	else if (bv.isOpr6 || bv.isOpr5) {

		

		offset = (e.cellPadding == null ? 1 : parseNum(e.cellPadding)) +
			 (e.cellSpacing == null ? 1 : parseNum(e.cellSpacing)) +
			 parseNum(e.border);
	}

	

	return offset;
}

/* Based on "Dynamic HTML The Definitive Reference" 2nd. Ed. by Danny Goodman p92. */

function getElementWidth(e) {

	if (!e) return;

	var result = 0;
	if (e.offsetWidth) {
		result = e.offsetWidth;
		
	}
	else if (e.clip && e.clip.width) {
		result = e.clip.width;
		
	}
	else if (e.style && e.style.pixelWidth) {
		result = e.style.pixelWidth;
		
	}
	return parseInt(result);
}

function getElementHeight(e) {

	if (!e) return;

	var result = 0;
	if (e.offsetHeight) {

		result = e.offsetHeight;
		
	}
	else if (e.clip && e.clip.height) {
		result = e.clip.height;
		
	}
	else if (e.style && e.style.pixelHeight) {
		result = e.style.pixelHeight;
		
	}
	return parseInt(result);
}



