/*----------------------------------------------------------------------------\
|                                XMenu 1.12                                   |
|-----------------------------------------------------------------------------|
|                          Created by Erik Arvidsson                          |
|                  (http://webfx.eae.net/contact.html#erik)                   |
|                      For WebFX (http://webfx.eae.net/)                      |
|-----------------------------------------------------------------------------|
| An object based tree widget,  emulating the one found in microsoft windows, |
| with persistence using cookies. Works in IE 5+, Mozilla and konqueror 3.    |
|-----------------------------------------------------------------------------|
|             Copyright (c) 2001, 2002, 2003, 2006 Erik Arvidsson             |
|-----------------------------------------------------------------------------|
| Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| use this file except in compliance with the License.  You may obtain a copy |
| of the License at http://www.apache.org/licenses/LICENSE-2.0                |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| Unless  required  by  applicable law or  agreed  to  in  writing,  software |
| distributed under the License is distributed on an  "AS IS" BASIS,  WITHOUT |
| WARRANTIES OR  CONDITIONS OF ANY KIND,  either express or implied.  See the |
| License  for the  specific language  governing permissions  and limitations |
| under the License.                                                          |
|-----------------------------------------------------------------------------|
| 2001-01-12 | Original Version Posted.                                       |
| 2001-11-20 | Added hover mode support and removed Opera focus hacks         |
| 2001-12-20 | (1.1) Added auto positioning and some properties to support    |
|            | this.                                                          |
| 2002-08-13 | (1.11) toString used ' for attributes. Changed to " to allow   |
|            | in properties/arguments.                                       |
| 2003-04-27 | (1.12) Added support for target property on menu item/button   |
| 2006-05-28 | Changed license to Apache Software License 2.0.                |
|-----------------------------------------------------------------------------|
| Created 2001-01-12 | All changes are in the log above. | Updated 2006-05-28 |
\----------------------------------------------------------------------------*/

//extended by Mehdi essid to use this as toolbar
//1- add vertical menubarseparator

// check browsers
var ua = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /MSIE/.test(ua);
var ie50 = ie && /MSIE 5\.[01234]/.test(ua);
var ie6 = ie && /MSIE [6789]/.test(ua);
var ieBox = ie && (document.compatMode == null || document.compatMode != "CSS1Compat");
var moz = !opera && /gecko/i.test(ua);
var nn6 = !opera && /netscape.*6\./i.test(ua);
// define the default values
webfxMenuDefaultWidth			= 100;

webfxMenuDefaultBorderLeft		= 1;
webfxMenuDefaultBorderRight		= 1;
webfxMenuDefaultBorderTop		= 1;
webfxMenuDefaultBorderBottom	= 1;
webfxMenuDefaultPaddingLeft		= 2;
webfxMenuDefaultPaddingRight	= 2;
webfxMenuDefaultPaddingTop		= 3;
webfxMenuDefaultPaddingBottom	= 3;

webfxMenuDefaultShadowLeft		= 0;
webfxMenuDefaultShadowRight		= ie && !ie50 && /win32/i.test(navigator.platform) ? 4 :0;
webfxMenuDefaultShadowTop		= 0;
webfxMenuDefaultShadowBottom	= ie && !ie50 && /win32/i.test(navigator.platform) ? 4 : 0;

webfxMenuItemDefaultHeight		= 18;
webfxMenuItemDefaultText		= "Untitled";
webfxMenuItemDefaultHref		= "javascript:void(0)";

webfxMenuSeparatorDefaultHeight	= 6;

webfxMenuDefaultEmptyText		= "Empty";

webfxMenuDefaultUseAutoPosition	= nn6 ? false : true;

// other global constants
webfxMenuImagePath				= "";

webfxMenuUseHover				= opera ? true : false;
webfxMenuHideTime				= 500;
webfxMenuShowTime				= 200;

/***********************************************************************************************************/
/*							webFXMenuHandler							*/
/***********************************************************************************************************/
var webFXMenuHandler = {
	idCounter		:	0,
	idPrefix		:	"webfx-menu-object-",
	all				:	{},
	getId			:	function () {return this.idPrefix + this.idCounter++; },
	overMenuItem	:	function (oItem) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);
		var jsItem = this.all[oItem.id];
		if (webfxMenuShowTime <= 0)
			this._over(jsItem);
		else
			//this.showTimeout = window.setTimeout(function () { webFXMenuHandler._over(jsItem) ; }, webfxMenuShowTime);
			// I hate IE5.0 because the piece of shit crashes when using setTimeout with a function object
			this.showTimeout = window.setTimeout("webFXMenuHandler._over(webFXMenuHandler.all['" + jsItem.id + "'])", webfxMenuShowTime);
	},
	outMenuItem	:	function (oItem) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);
		var jsItem = this.all[oItem.id];
		if (webfxMenuHideTime <= 0)
			this._out(jsItem);
		else
			this.hideTimeout = window.setTimeout("webFXMenuHandler._out(webFXMenuHandler.all['" + jsItem.id + "'])", webfxMenuHideTime);
	},
	blurMenu		:	function (oMenuItem) {
		window.setTimeout("webFXMenuHandler.all[\"" + oMenuItem.id + "\"].subMenu.hide();", webfxMenuHideTime);
	},
	_over	:	function (jsItem) {
		if (jsItem.subMenu) {
			jsItem.parentMenu.hideAllSubs();
			jsItem.subMenu.show();
		}
		else
			jsItem.parentMenu.hideAllSubs();
	},
	_out	:	function (jsItem) {
		// find top most menu
		var root = jsItem;
		var m;
		if (root instanceof WebFXMenuButton)
			m = root.subMenu;
		else {
			m = jsItem.parentMenu;
			while (m.parentMenu != null && !(m.parentMenu instanceof WebFXMenuBar))
				m = m.parentMenu;
		}

		if (m != null)
			m.hide();
        //if(jsItem.parentMenu.relativeObject) jsItem.parentMenu.relativeObject.className = jsItem.parentMenu.relativeObject.className.replace('_over','_out');
	},
	hideMenu	:	function (menu) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);

		this.hideTimeout = window.setTimeout("webFXMenuHandler.all['" + menu.id + "'].hide()", webfxMenuHideTime);
	},
	//added by mehdi essid
	//hides the root menu from a submenu
	hideAll : function (menu) {
		var parent = menu; 
		while (parent._parentMenu != null) {
			parent = parent._parentMenu;
		}
		if (parent != null){
			if (this.showTimeout != null)
				window.clearTimeout(this.showTimeout);
			if (this.hideTimeout != null)
				window.clearTimeout(this.hideTimeout);

			this.hideTimeout = window.setTimeout("webFXMenuHandler.all['" + parent.id + "'].hide()", webfxMenuHideTime);
		}
	},
	//added by mehdi essid
	//hides all menus
	hideAllMenus : function () {
		for(var i = 0; i < webFXMenuHandler.idCounter;i++) {
			s = webFXMenuHandler.idPrefix+ i;
			if (webFXMenuHandler.all[s] instanceof WebFXMenu){
				try{
					webFXMenuHandler.all[s].hide();
				} catch(e){
					//non hidebale menus are processed here
				}
			}
		}
	},
	showMenu	:	function (menu, src, dir) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);
		if (arguments.length < 3)
			dir = "vertical";

		menu.show(src, dir);
	}
};

/***********************************************************************************************************/
/*							WebFXMenu								*/
/***********************************************************************************************************/
function WebFXMenu(relObj) {
	this._menuItems	= [];
	this._subMenus	= [];
	this.id			= webFXMenuHandler.getId();
	this.top		= 0;
	this.left		= 0;
	this.shown		= false;
	this.parentMenu	= null;
    // relativeObject: added by Mehdi Essid to allow highlight/unhilight of an html node when when the menu is shown/hide (same thing than WebFXMenuButton)
    this.relativeObject = (relObj)? relObj : null;
	webFXMenuHandler.all[this.id] = this;
}


WebFXMenu.prototype.width			= webfxMenuDefaultWidth;
WebFXMenu.prototype.emptyText		= webfxMenuDefaultEmptyText;
WebFXMenu.prototype.useAutoPosition	= webfxMenuDefaultUseAutoPosition;

WebFXMenu.prototype.borderLeft		= webfxMenuDefaultBorderLeft;
WebFXMenu.prototype.borderRight		= webfxMenuDefaultBorderRight;
WebFXMenu.prototype.borderTop		= webfxMenuDefaultBorderTop;
WebFXMenu.prototype.borderBottom	= webfxMenuDefaultBorderBottom;

WebFXMenu.prototype.paddingLeft		= webfxMenuDefaultPaddingLeft;
WebFXMenu.prototype.paddingRight	= webfxMenuDefaultPaddingRight;
WebFXMenu.prototype.paddingTop		= webfxMenuDefaultPaddingTop;
WebFXMenu.prototype.paddingBottom	= webfxMenuDefaultPaddingBottom;

WebFXMenu.prototype.shadowLeft		= webfxMenuDefaultShadowLeft;
WebFXMenu.prototype.shadowRight		= webfxMenuDefaultShadowRight;
WebFXMenu.prototype.shadowTop		= webfxMenuDefaultShadowTop;
WebFXMenu.prototype.shadowBottom	= webfxMenuDefaultShadowBottom;

WebFXMenu.prototype.add = function (menuItem) {
	this._menuItems[this._menuItems.length] = menuItem;
	if (menuItem.subMenu) {
		this._subMenus[this._subMenus.length] = menuItem.subMenu;
		menuItem.subMenu.parentMenu = this;
	}

	menuItem.parentMenu = this;
};

WebFXMenu.prototype.show = function (relObj, sDir) {
	if (this.useAutoPosition)
		this.position(relObj, sDir);
	var divElement = document.getElementById(this.id);
	divElement.style.left = opera ? this.left : this.left + "px";
	divElement.style.top = opera ? this.top : this.top + "px";
	divElement.style.visibility = "visible";
    //added by Mehdi Essid to manage relativeObject option
    if(this.relativeObject) this.relativeObject.className = this.relativeObject.className.replace('_over','_selected');
    if(this.relativeObject) this.relativeObject.className = this.relativeObject.className.replace('_out','_selected');
    
    ////added by Mehdi Essid to display the menu foreground
    var elements = document.getElementsByTagName('*'); //get all the elements
    var zi = 0;
    for( var i=0; i < elements.length; i++)
    {
      zi = Math.max(zi,parseInt(elements[i].style.zIndex));
    }
    divElement.style.zIndex = (zi + 1); //set zIndex always superior to the max one
    
	this.shown = true;
	if (this.parentMenu && !this.parentMenu.shown)
		this.parentMenu.show();
};

WebFXMenu.prototype.hide = function () {
	this.hideAllSubs();
	var divElement = document.getElementById(this.id);
	divElement.style.visibility = "hidden";
    //added by Mehdi Essid to manage relativeObject option
    if(this.relativeObject) this.relativeObject.className = this.relativeObject.className.replace('_selected','_out');
	this.shown = false;
};
WebFXMenu.prototype.hideAllSubs = function () {
	for (var i = 0; i < this._subMenus.length; i++) {
		if (this._subMenus[i].shown)
			this._subMenus[i].hide();
	}
};
//added by mehdi essid
//hides the root menu from a submenu
WebFXMenu.prototype.hideAll = function () {
	var parent = this; 
	while (parent._parentMenu != null) {
		parent = parent._parentMenu;
	}
	if (parent != null) parent.hide();
};
//added by mehdi essid
//returns all submenus
WebFXMenu.prototype.getAllSubs = function () {
	return this._subMenus;
};

WebFXMenu.prototype.toString = function () {
	var top = this.top + this.borderTop + this.paddingTop;
    var h=0;
    var w = (!ieBox  ?
		this.width - this.borderLeft - this.paddingLeft - this.borderRight - this.paddingRight  :
		this.width);
	var str = "<div id='" + this.id + "' class='webfx-menu' style='" +
	"width:" + (w+15) + "px;" +
	(this.useAutoPosition ?
		"left:" + this.left + "px;" + "top:" + this.top + "px;" :
		"") +
	(ie50 ? "filter: none;" : "") +
	"'>";
    
    str += "\n<table class='menu_table_container' id='"+this.id+"_main_table'  style='width:"+(w+10)+"px' cellspacing=0 cellpadding=0 border=0>\
    <tr>\
        <td class='col1'></td>\
        <td class='col2'></td>\
        <td class='col3'></td>\
        <td class='col4'></td>\
    </tr>\
    <tr>\
        <td class='top_left'>&nbsp;</td>\
        <td class='top_middle' colspan=2>&nbsp;</td>\
        <td class='top_right' rowspan=2>&nbsp;</td>\
    </tr>\
    <tr>\
        <td class='middle_left second_row' >&nbsp;</td>\
        <td class='middle_middle' colspan=2 rowspan=2>";
        
	if (this._menuItems.length == 0) {
		str +=	"<span class='webfx-menu-empty'>" + this.emptyText + "</span>";
        h = 30;
	}
	else {
		// loop through all menuItems
		//alert(this._menuItems.length);
        
		for (var i = 0; i < this._menuItems.length; i++) {
			var mi = this._menuItems[i];
			str += mi;
			//if((''+mi)=='undefined') alert(mi);
			if (!this.useAutoPosition) {
				if (mi.subMenu && !mi.subMenu.useAutoPosition)
					mi.subMenu.top = top - mi.subMenu.borderTop - mi.subMenu.paddingTop;
				top += mi.height;
			}
            h+= mi.height;
            if(!(mi instanceof WebFXMenuSeparator)) h += this.paddingTop + this.paddingBottom;
		}

	}
    
    str += "\n</td>\
    </tr>\
    <tr>\
        <td class='middle_left' >&nbsp;</td>\
        <td class='middle_right' id='"+this.id+"_mr_cell' style='height:"+(h)+"px;'>&nbsp;</td>\
    </tr>\
    <tr>\
        <td class='bottom_left' colspan=2 >&nbsp;</td>\
        <td class='bottom_middle'  >&nbsp;</td>\
        <td class='bottom_right' >&nbsp;</td>\
    </tr>\
    </table>";
    /*
    str = "\n<table class='menu_table_container' id='"+this.id+"_main_table' style='width:"+(w+20)+"px' cellspacing=0 cellpadding=0 border=0>\
    <tr>\
        <td class='col1'></td>\
        <td class='col2'></td>\
        <td class='col3'></td>\
        <td class='col4'></td>\
    </tr>\
    <tr>\
        <td class='top_left'>&nbsp;</td>\
        <td class='top_middle' colspan=2>&nbsp;</td>\
        <td class='top_right' rowspan=2>&nbsp;</td>\
    </tr>\
    <tr>\
        <td class='middle_left second_row' >&nbsp;</td>\
        <td class='middle_middle' colspan=2 rowspan=2>"+str+
        "</td>\
    </tr>\
    <tr>\
        <td class='middle_left' >&nbsp;</td>\
        <td class='middle_right' id='"+this.id+"_mr_cell' style='"+this.height+"'>&nbsp;</td>\
    </tr>\
    <tr>\
        <td class='bottom_left' colspan=2 >&nbsp;</td>\
        <td class='bottom_middle'  >&nbsp;</td>\
        <td class='bottom_right' >&nbsp;</td>\
    </tr>\
</table>";
*/
	//added by mehdi essid
	/** prototype version **/
	//cancel right click on the menu (using prototype.js)
	str += "<script>Event.observe(document.getElementById('"+this.id+"'), 'contextmenu', function(e){"+
									"Event.stop(e);"+
								"});\n";
	//hide the menu when an item is clicked
	str += "Event.observe(document.getElementById('"+this.id+"'), 'click', webFXMenuHandler.hideAllMenus);</script>";
	
	str += "</div>";
	for (var i = 0; i < this._subMenus.length; i++) {
		this._subMenus[i].left = this.left + this.width - this._subMenus[i].borderLeft;
		str += this._subMenus[i];
	}
	return str;
};

/***********************************************************************************************************/
/*							WebFXMenuItem							*/
/***********************************************************************************************************/
// WebFXMenu.prototype.position defined later
function WebFXMenuItem(sText, sHref, sToolTip, oSubMenu) {
	this.text = sText || webfxMenuItemDefaultText;
	this.href = (sHref == null || sHref == "") ? webfxMenuItemDefaultHref : sHref;
	this.subMenu = oSubMenu;
	if (oSubMenu)
		oSubMenu.parentMenuItem = this;
	this.toolTip = sToolTip;
	this.id = webFXMenuHandler.getId();
	webFXMenuHandler.all[this.id] = this;
};
WebFXMenuItem.prototype.height = webfxMenuItemDefaultHeight;



//this function enables the item (added by Mehdi Essid)
WebFXMenuItem.prototype.enable = function () {
	/** prototype version **/
	/*$(this.id).className = '';
	att = $(this.id).getAttribute('href');
	if (att != null) $(this.id).setAttribute('href',$(this.id).getAttribute('href_bak'));
	else $(this.id).addAttribute('href',$(this.id).getAttribute('href_bak'));*/
	
	/** jsp version **/
	document.getElementById(this.id).className = '';
	att = document.getElementById(this.id).getAttribute('href');
	if (att != null) document.getElementById(this.id).setAttribute('href',document.getElementById(this.id).getAttribute('href_bak'));
	else document.getElementById(this.id).addAttribute('href',document.getElementById(this.id).getAttribute('href_bak'));
};

//this function disables the item (added by Mehdi Essid)
WebFXMenuItem.prototype.disable = function () {
	/** prototype version **/
	/*$(this.id).className = 'webfx-menu-item-disabled';
	if($(this.id).getAttribute('href') != null) $(this.id).removeAttribute('href');*/
	/** jsp version **/
	document.getElementById(this.id).className = 'webfx-menu-item-disabled';
	if(document.getElementById(this.id).getAttribute('href') != null) document.getElementById(this.id).removeAttribute('href');

};

//this function makes an item visible (added by Mehdi Essid)
WebFXMenuItem.prototype.show_item = function () {
	/** prototype version **/
	//$(this.id).show();
     var item = $(this.id);
    if(!(item.visible())) {
        
        
        var el = $(this.parentMenu.id+"_mr_cell");
        var h = Element.getHeight(el);
        //alert(h);
        el.style.height = (h+(this.height+webfxMenuDefaultPaddingTop+webfxMenuDefaultPaddingBottom)) +'px';
        item.show();
        
    }
	/** jsp version **/
	//document.getElementById(this.id).style.visibility = 'visible';

};
//this function makes an item hidden (added by Mehdi Essid)
WebFXMenuItem.prototype.hide_item = function () {
	/** prototype version **/
	//$(this.id).hide();
    var item = $(this.id);
    if(item.visible()) {
        
        
        var el = $(this.parentMenu.id+"_mr_cell");
        var h = Element.getHeight(el);
        el.style.height = (h-(this.height+webfxMenuDefaultPaddingTop+webfxMenuDefaultPaddingBottom)) +'px';
        item.hide();
        
    }
	/** jsp version **/
	//document.getElementById(this.id).style.visibility = 'hidden';

};

//this function updates html code of the item in the document (added by Mehdi Essid)
WebFXMenuItem.prototype.updateHTML = function () {
	document.getElementById(this.id).outerHTML = this.toString();
};

WebFXMenuItem.prototype.toString = function () {
	return	"<a " +
			" id='" + this.id + "'" +
			" href=\"" + this.href + "\"" +
			" href_bak=\"" + this.href + "\"" +
			(this.target ? " target=\"" + this.target + "\"" : "") +
			(this.toolTip ? " title=\"" + this.toolTip + "\"" : "") +
			" onmouseover='webFXMenuHandler.overMenuItem(this)'" +
			(webfxMenuUseHover ? " onmouseout='webFXMenuHandler.outMenuItem(this)'" : "") +
			(this.subMenu ? " unselectable='on' tabindex='-1'" : "") +
			">" +
			(this.subMenu ? "<img class='arrow' src=\"" + webfxMenuImagePath + "arrow.right.png\">" : "") +
			this.text +
			"</a>";
};

/***********************************************************************************************************/
/*							WebFXMenuSeparator						*/
/***********************************************************************************************************/
function WebFXMenuSeparator() {
	this.id = webFXMenuHandler.getId();
	webFXMenuHandler.all[this.id] = this;
};
WebFXMenuSeparator.prototype.height = webfxMenuSeparatorDefaultHeight;

//this function makes an item visible (added by Mehdi Essid)
WebFXMenuSeparator.prototype.show_item = function () {
	/** prototype version **/
	//$(this.id).show();
    var item = $(this.id);
    if(!(item.visible())) {
        
        
        var el = $(this.parentMenu.id+"_mr_cell");
        var h = Element.getHeight(el);
        //alert(h);
        el.style.height = (h+this.height) +'px';
        item.show();
        
    }
	/** jsp version **/
	//document.getElementById(this.id).style.visibility = 'visible';

};
//this function makes an item hidden (added by Mehdi Essid)
WebFXMenuSeparator.prototype.hide_item = function () {
	/** prototype version **/
	//$(this.id).hide();
    
    var item = $(this.id);
    if(item.visible()) {
        
        
        var el = $(this.parentMenu.id+"_mr_cell");
        var h = Element.getHeight(el);
        //alert(h);
        el.style.height = (h-this.height) +'px';
        item.hide();
        
    }
	/** jsp version **/
	//document.getElementById(this.id).style.visibility = 'hidden';

};
WebFXMenuSeparator.prototype.toString = function () {
	return	"<div" +
			" id='" + this.id + "'" +
			(webfxMenuUseHover ?
			" onmouseover='webFXMenuHandler.overMenuItem(this)'" +
			" onmouseout='webFXMenuHandler.outMenuItem(this)'"
			:
			"") +
			"></div>"
};

/***********************************************************************************************************/
/*							WebFXMenuBar							*/
/***********************************************************************************************************/
function WebFXMenuBar() {
	this._parentConstructor = WebFXMenu;
	this._parentConstructor();
}
WebFXMenuBar.prototype = new WebFXMenu;
WebFXMenuBar.prototype.toString = function () {
	var str = "<div id='" + this.id + "' class='webfx-menu-bar'>";

	// loop through all menuButtons
	for (var i = 0; i < this._menuItems.length; i++)
		str += this._menuItems[i];

	str += "</div>";

	for (var i = 0; i < this._subMenus.length; i++)
		str += this._subMenus[i];

	return str;
};

/***********************************************************************************************************/
/*							WebFxPopupMenu							*/
/***********************************************************************************************************/
/***
right menu: mehdi essid
***/
function WebFxPopupMenu() {
	this._parentConstructor = WebFXMenu;
	this._parentConstructor();
}
WebFxPopupMenu.prototype = new WebFXMenu;
WebFxPopupMenu.prototype.toString = function () {
	var str = "<div id='" + this.id + "' class='webfx-popup-menu'>";

	// loop through all menuButtons
	for (var i = 0; i < this._menuItems.length; i++)
		str += this._menuItems[i];

	str += "</div>";

	for (var i = 0; i < this._subMenus.length; i++)
		str += this._subMenus[i];

	return str;
};


/***********************************************************************************************************/
/*							WebFXMenuButton							*/
/***********************************************************************************************************/
function WebFXMenuButton(sText, sHref, sToolTip, oSubMenu) {
	this._parentConstructor = WebFXMenuItem;
	this._parentConstructor(sText, sHref, sToolTip, oSubMenu);
}
WebFXMenuButton.prototype = new WebFXMenuItem;
WebFXMenuButton.prototype.toString = function () {
	return	"<a" +
			" id='" + this.id + "'" +
			" href=\"" + this.href + "\"" +
			(this.target ? " target=\"" + this.target + "\"" : "") +
			(this.toolTip ? " title=\"" + this.toolTip + "\"" : "") +
			(webfxMenuUseHover ?
				(" onmouseover='webFXMenuHandler.overMenuItem(this)'" +
				" onmouseout='webFXMenuHandler.outMenuItem(this)'") :
				(
					" onfocus='webFXMenuHandler.overMenuItem(this)'" +
					(this.subMenu ?
						" onblur='webFXMenuHandler.blurMenu(this)'" :
						""
					)
				)) +
			">" +
			this.text +
			//(this.subMenu ? " <img  class='arrow' src=\"" + webfxMenuImagePath + "arrow.down.png\" align='absmiddle'>" : "")+			
			"</a>";
			
};


/***********************************************************************************************************/
/*							WebFXMenuBarSeparator						*/
/***********************************************************************************************************/
//menu bar separator to create toolbars
function WebFXMenuBarSeparator() {
	this.id = webFXMenuHandler.getId();
	webFXMenuHandler.all[this.id] = this;
};
WebFXMenuBarSeparator.prototype.toString = function () {
	return	"<a><img src=\"" + webfxMenuImagePath + "sep.png\" align='absmiddle'/></a>"
};


/***********************************************************************************************************/
/*							Position functions							*/
/***********************************************************************************************************/
/* Position functions */

function getInnerLeft(el) {
	if (el == null) return 0;
	if (ieBox && el == document.body || !ieBox && el == document.documentElement) return 0;
	//modified by mehdi essid
	//the next condition is added to adapt position to the windows: ie. do not take account of parent elements of a windows
	if((el.id.indexOf('win') >=0 && el.id.indexOf('_') <0)){
		return 0;
	}
	return getLeft(el) + getBorderLeft(el);
}

function getLeft(el) {
	if (el == null) return 0;
	return el.offsetLeft + getInnerLeft(el.offsetParent);
}

function getInnerTop(el) {
	if (el == null) return 0;
	if (ieBox && el == document.body || !ieBox && el == document.documentElement) return 0;
	//modified by mehdi essid
	//the next condition is added to adapt position to the windows: ie. do not take account of parent elements of a windows
	if(el.id.indexOf('win') >=0 && el.id.indexOf('_') <0){
		return 0;
	}
	return getTop(el) + getBorderTop(el);
}

function getTop(el) {
	
	if (el == null) return 0;
	return el.offsetTop + getInnerTop(el.offsetParent);
}

function getBorderLeft(el) {
	return ie ?
		el.clientLeft :
		parseInt(window.getComputedStyle(el, null).getPropertyValue("border-left-width"));
}

function getBorderTop(el) {
	return ie ?
		el.clientTop :
		parseInt(window.getComputedStyle(el, null).getPropertyValue("border-top-width"));
}

function opera_getLeft(el) {
	if (el == null) return 0;
	return el.offsetLeft + opera_getLeft(el.offsetParent);
}

function opera_getTop(el) {
	if (el == null) return 0;
	return el.offsetTop + opera_getTop(el.offsetParent);
}

function getOuterRect(el) {
	return {
		left:	(opera ? opera_getLeft(el) : getLeft(el)),
		top:	(opera ? opera_getTop(el) : getTop(el)),
		width:	el.offsetWidth,
		height:	el.offsetHeight
	};
}

// mozilla bug! scrollbars not included in innerWidth/height
function getDocumentRect(el) {
	return {
		left:	0,
		top:	0,
		width:	(ie ?
					(ieBox ? document.body.clientWidth : document.documentElement.clientWidth) :
					window.innerWidth
				),
		height:	(ie ?
					(ieBox ? document.body.clientHeight : document.documentElement.clientHeight) :
					window.innerHeight
				)
	};
}

function getScrollPos(el) {
	return {
		left:	(ie ?
					(ieBox ? document.body.scrollLeft : document.documentElement.scrollLeft) :
					window.pageXOffset
				),
		top:	(ie ?
					(ieBox ? document.body.scrollTop : document.documentElement.scrollTop) :
					window.pageYOffset
				)
	};
}

/* end position functions */

WebFXMenu.prototype.position = function (relEl, sDir) {
	var dir = sDir;
	// find parent item rectangle, piRect
	var piRect;
	if (!relEl) {
		var pi = this.parentMenuItem;
		if (!this.parentMenuItem)
			return;

		relEl = document.getElementById(pi.id);
		if (dir == null)
			dir = pi instanceof WebFXMenuButton ? "vertical" : "horizontal";

		piRect = getOuterRect(relEl);
	}
	else if (relEl.left != null && relEl.top != null && relEl.width != null && relEl.height != null) {	// got a rect
		piRect = relEl;
	}
	else
		piRect = getOuterRect(relEl);

	var menuEl = document.getElementById(this.id);
	var menuRect = getOuterRect(menuEl);
	var docRect = getDocumentRect();
	var scrollPos = getScrollPos();
	var pMenu = this.parentMenu;

	if (dir == "vertical") {
		if (piRect.left + menuRect.width - scrollPos.left <= docRect.width)
			this.left = piRect.left;
		else if (docRect.width >= menuRect.width)
			this.left = docRect.width + scrollPos.left - menuRect.width;
		else
			this.left = scrollPos.left;

		if (piRect.top + piRect.height + menuRect.height <= docRect.height + scrollPos.top)
			this.top = piRect.top + piRect.height;
		else if (piRect.top - menuRect.height >= scrollPos.top)
			this.top = piRect.top - menuRect.height;
		else if (docRect.height >= menuRect.height)
			this.top = docRect.height + scrollPos.top - menuRect.height;
		else
			this.top = scrollPos.top;
	}
	else {
		if (piRect.top + menuRect.height - this.borderTop - this.paddingTop <= docRect.height + scrollPos.top)
			this.top = piRect.top - this.borderTop - this.paddingTop;
		else if (piRect.top + piRect.height - menuRect.height + this.borderTop + this.paddingTop >= 0)
			this.top = piRect.top + piRect.height - menuRect.height + this.borderBottom + this.paddingBottom + this.shadowBottom;
		else if (docRect.height >= menuRect.height)
			this.top = docRect.height + scrollPos.top - menuRect.height;
		else
			this.top = scrollPos.top;

		var pMenuPaddingLeft = pMenu ? pMenu.paddingLeft : 0;
		var pMenuBorderLeft = pMenu ? pMenu.borderLeft : 0;
		var pMenuPaddingRight = pMenu ? pMenu.paddingRight : 0;
		var pMenuBorderRight = pMenu ? pMenu.borderRight : 0;

		if (piRect.left + piRect.width + menuRect.width + pMenuPaddingRight +
			pMenuBorderRight - this.borderLeft + this.shadowRight <= docRect.width + scrollPos.left)
			this.left = piRect.left + piRect.width + pMenuPaddingRight + pMenuBorderRight - this.borderLeft;
		else if (piRect.left - menuRect.width - pMenuPaddingLeft - pMenuBorderLeft + this.borderRight + this.shadowRight >= 0)
			this.left = piRect.left - menuRect.width - pMenuPaddingLeft - pMenuBorderLeft + this.borderRight + this.shadowRight;
		else if (docRect.width >= menuRect.width)
			this.left = docRect.width  + scrollPos.left - menuRect.width;
		else
			this.left = scrollPos.left;		
	}

};