/*
	DHTML Menu script.
	Copyright © 2003, XHEO. All Rights Reserved.
	http://www.xheo.com/
	
	This script may not be used for any purpose without prior consent from XHEO.
	Please visit http://www.xheo.com for more details.
*/

/// GLOBAL OBJECTS
///////////////////////////////

var EL_CONTAINER		= 0;
var EL_CONTAINER_TILE	= 9;
var EL_CONTAINER_LEFT	= 10;
var EL_CONTAINER_RIGHT	= 11;
var EL_ICON				= 1;
var EL_ICONAREA			= 2;
var EL_TEXT				= 3;
var EL_CHILD			= 4;
var EL_CHILD_BACK		= 12;
var EL_CHEVRON			= 6;
var EL_CHECK			= 7;
var EL_CUSTOM			= 13;

// __tbi class Code adapted from 
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type_oo.html
function _BrowserIs ()
{
    var agt=navigator.userAgent.toLowerCase();

    this._Major = parseInt(navigator.appVersion);
    this._Minor = parseFloat(navigator.appVersion);

    this._Netscape  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this._Netscape6Up = (this._Netscape && (this._Major >= 5));

    this._IE     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this._IE3    = (this._IE && (this._Major < 4));
    this._IE4    = (this._IE && (this._Major == 4) && (agt.indexOf("msie 4")!=-1) );
    this._IE5Up  = (this._IE  && !this._IE3 && !this._IE4);
    
    this._W3cDom1 = this._IE5Up || this._Netscape6Up || document.getEltementById;
};

var _browserIs	= new _BrowserIs();
var __menus		= new Array();

/// HELPER METHODS
///////////////////////////////

function _getElement( elt ) 
{
	var doc = document;
	if( arguments.length > 1 && arguments[ 1 ] )
		doc = arguments[ 1 ];
	if( _browserIs._W3cDom1 )
	{
		var obj = doc.getElementById( elt );
		if( obj != null )
			return obj;
		if( doc.getElementByName )
			return doc.getElementByName( elt );
		return null;
	}
	else if( _browserIs._IE4Up )
	{
		return doc.all.item( elt );
	}
};

function MenuStyle()
{
	this.separatorSpansIcon	= true;
//	this.usesIcons			= false;
	this.hoverSuffix		= "Hover";
	this.separatorSuffix	= "Sep";
	this.downSuffix			= "Down";
	this.checkedSuffix		= "Checked";

	this.iconWidth		= 16;
	this.iconHeight		= 16;
	
	this.barCss			= "MBar";
	this.barItemCss		= "MBarItem";		// MBarItemHover, MBarItemDown
	this.popUpCss		= "MPopUp";
	this.itemCss		= "MItem";			// MItemHover, MItemDown
	this.iconAreaCss	= "MIconArea";		// MIconAreaHover, MIconAreaDown, MIconAreaSep
	this.iconCss		= "MIcon";			// MIconHover, MIconDown
	this.textCss		= "MText";			// MTextHover, MTextDown, MTextSep
	this.chevronAreaCss	= "MChevron";		// MChevronHover, MChevronDown, MChevronSep
	this.separatorCss	= "MSeparator";
	this.menuAlignment	= "lefttop";
	
	this.shadowColor	= "#AAAAAA";
	this.shadowSize		= 4;
	
//	this.chevronIcon	= "images/chevron.gif";
//	this.checkedIcon	= "images/menuchecked.gif";
	
}

function Menu( id )
{
	if( __menus[ id ] != null )
	{
		alert( "Menu '" + id + "' already exists." );
		return;
	}
	
	this.id	= id;
	__menus[ this.id ] = this;
	
	this.iconBaseUrl	= "";
	
	this.orientation	= "horizontal";
	this.items			= new Array();
	this.filter			= "fade";
	this.filterChildren	= true;
	this.filterSpeed	= 0.3;
	//this.width			= "100%";
	
	this.__allItems	= new Array();
	this._nextId	= 0;
	this._capturing	= false;
	this._lastOver	= null;

	// Methods
	
	// Gets the next available auto client id.
	this._getNextId	= function()
	{
		return this.id + "_mi_" + this._nextId++;
	}
	
	// Renders the menu to the document.
	this.create		= function( visible )
	{
		if( ! this.creator )
			this.creator = new CssMenuCreator();
		this.creator.create( this, visible );
		document.write( "<a href=\"#\" id=" + this.id + "_link style=\"display:none;\"></a>" );
		this._link = _getElement( this.id + "_link" );
	}
	
	this.addItem	= function( text )
	{
		var id	= arguments.length > 1 ? arguments[ 1 ] : null;
		if( id == null || id.length == 0 )
			id = this._getNextId();
	
		var item = new MenuItem( text, id );
		item._parent	= this;
		item._menu		= this;
		this.items[ this.items.length ] = item;
		this.__allItems[ id ] = item;
		return item;
	}
	
	this.collapse	= function()
	{
		this._setCapture( false );
		for( var index = 0; index < this.items.length; index++ )
			this.items[ index ].collapse();
	}
	
	this.onclick	= function()
	{
		var item = this._getEventItem( arguments[ 0 ] );

		if( item == null )
		{
			this.collapse();
			return;
		}
		else
		{
			if( this._delayClose )
			{
				this._setCapture( true );
				if( arguments.length > 0 && arguments[ 0 ] )
					arguments[ 0 ].preventDefault();
				return;
			}
			
			if( item._onclick() )
			{
				this._setCapture( true );
			}
			else
			{
				this._delayClose = true;
				this._setCapture( false );
				if( arguments.length > 0 || arguments[ 0 ] )
				{
					arguments[ 0 ].cancelBubble = false;
					if( arguments[ 0 ].target.click )
						arguments[ 0 ].target.click();
					arguments[ 0 ].target.onblur	= new Function( "__menus['" + this.id + "']._controlClick( arguments[ 0 ] );" );
				}
				else
				{
					event.cancelBubble = false;
					event.srcElement.click();
					event.srcElement.onblur	= new Function( "__menus['" + this.id + "']._controlClick();" );
				}
			}
		}
	}
	
	this._controlClick = function()
	{
		if( arguments.length == 0 || ! arguments[ 0 ] )
		{
			event.cancelBubble = true;
			event.returnValue = false;
		}
		else
		{
			arguments[ 0 ].cancelBubble = true;
			arguments[ 0 ].preventDefault();
		}			
		this._setCapture( true );
	}
	
	this._getEventItem	= function()
	{
		var element	= null;
		if( _browserIs._W3cDom1 && _browserIs._Netscape )
		{
			if( arguments.length == 0 || ! arguments[ 0 ] )
				return;
			element = ( arguments.length > 1 && arguments[ 1 ] ) ? arguments[ 1 ] : arguments[ 0 ].target;
			while( element != null && ( element.id == null || element.id.length == 0 || element.id.indexOf( "_container" ) == -1 ) )
				element = element.parentNode;
			arguments[ 0 ].cancelBubble = true;
		}
		else
		{
			element = ( arguments.length  > 0 && arguments[ 0 ] ) ? arguments[ 0 ] : event.srcElement;
			while( element != null && ( element.id == null || element.id.length == 0 || element.id.indexOf( "_container" ) == -1 ) )
				element = element.parentElement;
			event.cancelBubble = true;
		}
		
		if( element == null )
			return null;
		
		var id = element.id.substring( 0, element.id.indexOf( "_container" ) );
		var item = this.__allItems[ id ];		
		if( item == null )
			return null;
		if( item._isSeparator )
		{
			return null;
		}
		else
		{
			return item;
		}
	}
	
	
	this.onmouseover	= function()
	{
		var item = this._getEventItem( arguments[ 0 ] );
		if( _browserIs._IE && item && item._mouseOver )
			return;
		
		if( item != null )
		{
			item._onmouseover();
			if( this._capturing )
			{
				this._lastOver = item;
				if( ! item._expanded )
				{
					if( item._menu == item._parent )
						item.expand();
					else
					{
						if( this._delayOverTimerId )
							window.clearTimeout( this._delayOverTimerId );
						this._delayOverTimerId = window.setTimeout( "__menus['" + this.id + "']._delayonmouseover( '" + item.id + "' )", 300 );
					}
				}
			}
		}
	}
	this._delayOverTimerId = null;
	
	this._delayonmouseover = function( id )
	{
		this._delayOverTimerId = null;
		if( this._lastOver && this._lastOver.id == id )
		{
			this._lastOver.expand();
			this._lastOver = null;
		}
	}
	
	this.onmouseout		= function()
	{
		var item = this._getEventItem( arguments[ 0 ] );
		if( _browserIs._IE )
		{
			if( item == this._getEventItem( event.toElement ) )
				return;
		}
		else
		{
			if( item == this._getEventItem( null, arguments[ 0 ].relatedTarget ) )
				return;
		}
		if( item != null )
			item._onmouseout();
	}

	this._mouseDown		= false;
	this.onmousedown	= function()
	{
		var item = this._getEventItem( arguments[ 0 ] );
		this._mouseDown	= true;
		if( item != null )
			item._onmousedown();
	}
	
	this.onmouseup		= function()
	{
		var item = this._getEventItem( arguments[ 0 ] );
		this._mouseDown = false;
		if( item != null )
			item._onmouseup();
	}
	
	this._oldOnClick		= null;
	this._oldOnMouseOver	= null;
	this._oldOnMouseOut		= null;
	this._oldOnMouseDown	= null;
	this._oldOnMouseUp		= null;
	this._setCapture	= function( capture )
	{
		if( capture == this._capturing )
			return;
		this._capturing = capture;
		this._delayClose = false;

		if( _browserIs._Netscape )
		{
			if( ! capture )
			{
				document.onclick		= this._oldOnClick;
				document.onmouseover	= this._oldOnMouseOver;
				document.onmouseout		= this._oldOnMouseOut;
				document.onmousedown	= this._oldOnMouseDown;
				document.onmouseup		= this._oldOnMouseUp;
				document.releaseEvents( Event.CLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONMOUSEDOWN | Event.ONMOUSEUP );
			}
			else
			{
				this._oldOnClick		= document.onclick;
				this._oldOnMouseOver	= document.onmouseover;
				this._oldOnMouseOut		= document.onmouseout;
				this._oldOnMouseDown	= document.onmousedown;
				this._oldOnMouseUp		= document.onmouseup;
				document.onclick		= new Function( "__menus['" + this.id + "'].onclick( arguments[ 0 ] );" );
				document.onmouseover	= new Function( "__menus['" + this.id + "'].onmouseover( arguments[ 0 ] );" );
				document.onmouseout		= new Function( "__menus['" + this.id + "'].onmouseout( arguments[ 0 ] );" );
				document.onmousedown	= new Function( "__menus['" + this.id + "'].onmousedown( arguments[ 0 ] );" );
				document.onmouseup		= new Function( "__menus['" + this.id + "'].onmouseup( arguments[ 0 ] );" );
				document.captureEvents( Event.CLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONMOUSEDOWN | Event.ONMOUSEUP );
			}
		}
		else
		{
			if( ! capture )
			{
				document.body.onclick		= this._oldOnClick;
				document.body.onmouseout	= this._oldOnMouseOut;
				document.body.onmouseover	= this._oldOnMouseOver;
				document.body.onmousedown	= this._oldOnMouseDown;
				document.body.onmouseup		= this._oldOnMouseUp;
				document.body.releaseCapture();
			}
			else
			{
				this._oldOnClick		= document.body.onclick;
				this._oldOnMouseOver	= document.body.onmouseover;
				this._oldOnMouseOut		= document.body.onmouseout;
				this._oldOnMouseDown	= document.body.onmousedown;
				this._oldOnMouseUp		= document.body.onmouseup;
				document.body.onclick		= new Function( "__menus['" + this.id + "'].onclick();" );
				document.body.onmouseover	= new Function( "__menus['" + this.id + "'].onmouseover();" );
				document.body.onmouseout	= new Function( "__menus['" + this.id + "'].onmouseout();" );
				document.body.onmousedown	= new Function( "__menus['" + this.id + "'].onmousedown();" );
				document.body.onmouseup		= new Function( "__menus['" + this.id + "'].onmouseup();" );
				document.body.setCapture();			
			}
		}
	}
	
	
	this._resolveMenuStyle	= function( ms )
	{
		if( ms._resolved )
			return;
		ms._resolved = true;
		
		ms._barItemHoverCss		= this._resolveClass( ms.barItemCss + ms.hoverSuffix, ms.barItemCss );
		ms._barItemDownCss		= this._resolveClass( ms.barItemCss + ms.downSuffix, ms.barItemCss + ms.hoverSuffix, ms.barItemCss );
		
		ms._itemHoverCss		= this._resolveClass( ms.itemCss + ms.hoverSuffix, ms.itemCss );
		ms._itemDownCss			= this._resolveClass( ms.itemCss + ms.downSuffix, ms.itemCss + ms.hoverSuffix, ms.itemCss );
		
		ms._iconAreaHoverCss	= this._resolveClass( ms.iconAreaCss + ms.hoverSuffix, ms.iconAreaCss, ms.itemCss );
		ms._iconAreaDownCss		= this._resolveClass( ms.iconAreaCss + ms.downSuffix, ms._iconAreaHoverCss );
		ms._iconAreaSepCss		= this._resolveClass( ms.iconAreaCss + ms.separatorSuffix, ms.iconAreaCss, ms.itemCss );
		ms._iconAreaCheckedCss	= this._resolveClass( ms.iconAreaCss + ms.checkedSuffix, ms.iconAreaCss, ms.itemCss );
		
		ms._iconHoverCss		= this._resolveClass( ms.iconCss + ms.hoverSuffix, ms.iconCss );
		ms._iconDownCss			= this._resolveClass( ms.iconCss + ms.downSuffix, ms._iconHoverCss );
		
		ms._textHoverCss		= this._resolveClass( ms.textCss + ms.hoverSuffix, ms.textCss, ms.itemCss );
		ms._textDownCss			= this._resolveClass( ms.textCss + ms.downSuffix, ms._textHoverCss );
		ms._textSepCss			= this._resolveClass( ms.textCss + ms.separatorSuffix, ms.textCss, ms.itemCss );		
		ms._textCheckedCss		= this._resolveClass( ms.textCss + ms.checkedSuffix, ms.textCss );
		
		ms._chevronAreaHoverCss	= this._resolveClass( ms.chevronAreaCss + ms.hoverSuffix, ms.chevronAreaCss, ms.itemCss );
		ms._chevronAreaDownCss	= this._resolveClass( ms.chevronAreaCss + ms.downSuffix, ms._chevronAreaHoverCss );
		ms._chevronAreaSepCss	= this._resolveClass( ms.chevronAreaCss + ms.separatorSuffix, ms.chevronAreaCss, ms.itemCss );
		
	}
	
	this._resolveClass	= function( style )
	{
		for( var index = 0; index < document.styleSheets.length; index++ )
		{
			var rules;
			if( _browserIs._Netscape )
			{
				rules = document.styleSheets[ index ].cssRules;
			}
			else
			{
				rules = document.styleSheets[ index ].rules;
			}
			for( var ruleIndex = 0; ruleIndex < rules.length; ruleIndex++ )
			{
				if( rules[ ruleIndex ].selectorText == "." + style )
					return style;
			}
		}
		
		for( var index = 1; index < arguments.length; index++ )
		{
			var rule = this._resolveClass( arguments[ index ] );
			if( rule )
				return rule;
		}
		
		return null;
	}	
	
};

function MenuItem( text )
{
	this.id			= arguments.length > 1 ? arguments[ 1 ] : null;
	this.text		= text;
//	this.icon		= null;
//	this.url		= null;
	this.target		= "_top";
//	this.tip		= null;
//	this.menuStyle	= null;
//	this.checked	= false;
//	this.checkable	= false;
//	this.filter		= null;
//	this.filterChildren	= null;
//	this.filterSpeed	= null;
//	this._isSeparator	= false;
//	this._isControlHost		= false;
//	this._controlSpansIcon	= false;
//	this._controlHtml		= null;
//	this._parent	= null;
//	this._menu		= null;
	this.items		= new Array();
//	this._expanded	= false;
	
//	this._elements	= null;
		//	0		- Container 
		//	1		- Icon
		//	2		- Text
		//	4		- Child Container
	
	this.addItem	= function( text )
	{
		var id	= arguments.length > 1 ? arguments[ 1 ] : null;
		if( id == null || id.length == 0 )
			id = this._menu._getNextId();
	
		var item = new MenuItem( text, id );
		item._parent	= this;
		item._menu		= this._menu;
		
		this.items[ this.items.length ] = item;
		this._menu.__allItems[ id ] = item;
		
		return item;
	}
	
	this.addSeparator	= function()
	{
		var item = this.addItem();
		item._isSeparator = true;
	}
	
	this.addControlHost	= function( html, spanIcon )
	{
		var item = this.addItem();
		item._controlSpansIcon = spanIcon;
		item._controlHtml = html;
	}
	
	this._assertElements = function()
	{
		if( ! this._elements )
		{
			alert( "Menu not created yet." );
			return false;
		}
		return true;
	}
	
	this._getFilterSpeed = function()
	{
		for( var m = this; m != null; m = m._parent )
			if( m.filterSpeed != null )
				return m.filterSpeed;
	}
	
	this._getFilter		= function()
	{
		if( this._expanded )
			return null;
		var filter			= null;
		for( var m = this; m != null; m = m._parent )
		{	
			if( m.filter )
			{
				filter =  m.filter;
				break;
			}
		}
		if( filter )
		{
			for( var m = this; m != null && m._menu != m._parent ; m = m._parent )
			{
				if( m.filterChildren != null )
				{
					if( m.filterChildren )
					{
						return filter;
					}
					else
					{
						return null;
					}
				}
			}
			
			if( this._menu == this._parent || this._menu.filterChildren )
			{
				return filter;
			}
			else
			{
				return null;
			}
		}
		return filter;
	}
	
	this.expand		= function()
	{	
		this.collapseAllTo();
		
		var child	= this._elements[ EL_CHILD ];
		
		if( ! this._assertElements() )
			return;
		if( ! child )
			return;

		this._fixPosition( false );
	
		if( this._parent != null && this._parent != this._menu && ! this._parent._expanded )
			return;

		this._expand();
	}
	
	this.showContext	= function()
	{
		var x;
		var y;
		
		if( arguments.length > 0 && arguments[ 0 ] )
		{
			x = arguments[ 0 ].clientX;
			y = arguments[ 0 ].clientY;
			arguments[ 0 ].cancelBubble = true;
			arguments[ 0 ].preventDefault();
		}
		else
		{
			x = event.x;
			y = event.y;
			event.cancelBubble = true;
			event.returnValue = false;
		}
		
		x += document.body.scrollLeft;
		y += document.body.scrollTop;
		
		
		this.showContextAt( x, y );		
	}
	
	this.showContextAt	= function( x, y )
	{
		this._fixPosition( false, x, y );
		this._menu.collapse();
		this._expand();
		if( _browserIs._IE )
			event.cancelBubble = true;
	}
	
	this._expand	= function()
	{
		if( this._expanded )
			return;
			
		var child	= this._elements[ EL_CHILD ];
	
		var filterSpeed = this._getFilterSpeed();
		if( _browserIs._IE )
		{
			var filter = this._getFilter();
			child.style.filter = "";
			if( filter && filter.substring( 0, 7 ) == "progid:" )
			{
				child.style.filter = filter;
			}
			else
			{
				switch( filter )
				{
					case "fade":
						child.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=" + filterSpeed + ")";
						break;
					case "barn":
						child.style.filter = "progid:DXImageTransform.Microsoft.Barn(duration=" + filterSpeed + ", orientation=vertical)";
						break;
					case "wipe":
						child.style.filter = "progid:DXImageTransform.Microsoft.GradientWipe(duration=" + filterSpeed + ", gradientSize=50)";
						filterSpeed *= 2.3;
						break;
					case "pixelate":
						child.style.filter = "progid:DXImageTransform.Microsoft.Pixelate(duration=" + filterSpeed + ",maxSquare=10)";
						break;
					case "disolve":
						child.style.filter = "progid:DXImageTransform.Microsoft.RandomDissolve(duration=" + filterSpeed + ")";
						break;
					case "slide":
						child.style.filter = "progid:DXImageTransform.Microsoft.Slide(duration=" + filterSpeed + ",slideStyle=push, direction=down, bands=" + ( this.items.length == 1 ? 2 : this.items.length ) + ")";
						break;
					case "stretch":
						child.style.filter = "progid:DXImageTransform.Microsoft.Stretch(duration=" + filterSpeed + ")";
						break;						
					default:
						child.style.filter = "";
						break;		
				}
				
				
			}
			
			child.style.filter += "progid:DXImageTransform.Microsoft.Shadow(color=" + this.menuStyle.shadowColor + ",direction=135,strength=" + this.menuStyle.shadowSize + " )";
			
			if( child.filters && child.filters.length > 0 )
				child.filters[ 0 ].Apply();
			
		}
		
		child.style.visibility = "";
		
		if( _browserIs._IE && child.filters.length > 0 )
			child.filters[ 0 ].Play();
	
		if( this._menu == this._parent )
			this._onmousedown();
		
		
		this._expanded = true;
		this._menu._setCapture( true );
		this._menu._lastOver = null;	
	}
	
	this.collapseAllTo	= function()
	{
		var valid = new Array();
		for( var p = this; p != null; p = p._parent )
			valid[ p.id ] = true;
		
		for( var id in this._menu.__allItems )
		{
			var hide = true;
			var item = this._menu.__allItems[ id ];
			if( item._expanded )
			{
				if( ! valid[ item.id ] )
					item.collapse();				
			}
		}
	}
	
	this.collapse		= function()
	{
		if( ! this._assertElements() )
			return;
	
		for( var index = 0; index < this.items.length; index++ )
		{
			this.items[ index ].collapse();
		}		
	
		if( this._elements[ EL_CHILD ] )
		{				
			this._elements[ EL_CHILD ].style.visibility = "hidden";

			this._expanded = false;
		}
		
		if( this._menu == this._parent )
			this._onmouseup();
		
		if( this._menu.creator.oncollapse )
			this._menu.creator.oncollapse( this );
	}
	
	this.setChecked	= function( checked )
	{
		this.checked = checked;
		if( this.menuStyle.usesIcons )
		{
			if( checked )
			{
				this._elements[ EL_ICONAREA ].className = this.menuStyle._iconAreaCheckedCss;
			}
			else
			{
				this._elements[ EL_ICONAREA ].className = this.menuStyle.iconAreaCss;
			}
			
		}
		else
		{
			if( checked )
			{
				this._elements[ EL_CHECK ].style.visibility = "";
			}
			else
			{
				this._elements[ EL_CHECK ].style.visibility = "hidden";
			}
		}
		
		if( checked )
		{
			this._elements[ EL_TEXT ].classNAme = this.menuStyle._textCheckedCss;
		}
		else
		{
			this._elements[ EL_TEXT ].classNAme = this.menuStyle.textCss;
		}
	}	
	
	this._onclick = function()
	{
		if( this.onclick )
		{
			if( typeof( this.onclick ) == "string" )
				this.onclick = new Function( this.onclick );
			if( this.onclick() == false )
				return false;
		}
		
		if( this._controlHtml )
		{
			return false;
		}
		else if( this.items.length == 0 )
		{
			
			this._menu.collapse();
			this._menu._setCapture( false );
			if( this.checkable )
			{
				this.setChecked( ! this.checked );
			}
			if( this.url == null || this.url.length == 0 )
				return true;
			if( this.target != null && this.target != "" && this.target != "_self" )
			{
				window.open( this.url, this.target );
			}
			else
			{
				if( _browserIs._IE )
				{
					this._menu._link.href = this.url;
					this._menu._link.click();				
				}
				else
				{
					window.open( this.url, "_self" );
				}
				
			}
				
		}
		else
		{
			this.expand();
		}
		
		return true;
	}
	
	this._showState = function( state )
	{
		if( state == "down" )
		{
			if( this._menu == this._parent )
			{
//				if( ! this._expanded )
				{
					if( this._elements[ EL_CONTAINER_LEFT ] )
						this._elements[ EL_CONTAINER_LEFT ].src = this.menuStyle.barItemLeftDown; // "MItemDown";
					if( this._elements[ EL_CONTAINER_RIGHT ] )
						this._elements[ EL_CONTAINER_RIGHT ].src = this.menuStyle.barItemRightDown; // "MItemDown";				
					this._elements[ EL_CONTAINER ].className = this.menuStyle._barItemDownCss; // "MBarItemDown";
					this._elements[ EL_CONTAINER ].style.backgroundImage = "url(" + this.menuStyle.barItemTileDown + ")"; // "MBarItemDown";
				}
			}
			else
			{
				if( this._elements[ EL_CONTAINER ] )
					this._elements[ EL_CONTAINER ].className = this.menuStyle._itemDownCss; // "MItemDown";
				if( this._elements[ EL_TEXT ] )
				{
					this._elements[ EL_TEXT ].className = this.menuStyle._textDownCss; // "MTextDown";
					this._elements[ EL_TEXT ].style.backgroundImage = "url(" + this.menuStyle.itemTileDown + ")"; // "MTextDown";
				}
				if( this._elements[ EL_ICONAREA ] )
				{
					this._elements[ EL_ICONAREA ].className = this.menuStyle._iconAreaDownCss; // "MIconAreaDown";
					this._elements[ EL_ICONAREA ].style.backgroundImage = "url(" + this.menuStyle.iconAreaDown + ")"; // "MIconAreaDown";
				}
				if( this._elements[ EL_CHEVRON ] )
				{
					this._elements[ EL_CHEVRON ].className = this.menuStyle._chevronAreaDownCss; // "MChevronDown";
					this._elements[ EL_CHEVRON ].style.backgroundImage = "url(" + this.menuStyle.chevronAreaDown + ")"; // "MChevronDown";
				}
				if( this._elements[ EL_ICON ] && this.iconDown )
				{
					this._elements[ EL_ICON ].src = this.iconDown;
				}

			}
		}
		else if( state == "over" )
		{
			if( this._menu == this._parent )
			{
				if( ! this._expanded )
				{
					if( this._elements[ EL_CONTAINER_LEFT ] )
						this._elements[ EL_CONTAINER_LEFT ].src = this.menuStyle.barItemLeftHover; // "MItemHover";
					if( this._elements[ EL_CONTAINER_RIGHT ] )
						this._elements[ EL_CONTAINER_RIGHT ].src = this.menuStyle.barItemRightHover; // "MItemHover";					
					this._elements[ EL_CONTAINER ].className = this.menuStyle._barItemHoverCss; // "MBarItemHover";
					this._elements[ EL_CONTAINER ].style.backgroundImage = "url(" + this.menuStyle.barItemTileHover + ")"; // "MBarItemHover";
				}
			}
			else
			{
				if( this._elements[ EL_CONTAINER ] )
					this._elements[ EL_CONTAINER ].className = this.menuStyle._itemHoverCss; // "MItemHover";

				
				if( this._elements[ EL_TEXT ] )
				{
					this._elements[ EL_TEXT ].className = this.menuStyle._textHoverCss; // "MTextHover";
					this._elements[ EL_TEXT ].style.backgroundImage = "url(" + this.menuStyle.itemTileHover + ")"; // "MTextHover";
				}
				if( this._elements[ EL_ICONAREA ] )
				{
					this._elements[ EL_ICONAREA ].className = this.menuStyle._iconAreaHoverCss; // "MIconAreaHover";
					this._elements[ EL_ICONAREA ].style.backgroundImage = "url(" + this.menuStyle.iconAreaHover + ")"; // "MIconAreaHover";
				}
				if( this._elements[ EL_CHEVRON ] )
				{
					this._elements[ EL_CHEVRON ].className = this.menuStyle._chevronAreaHoverCss; // "MChevronHover";
					this._elements[ EL_CHEVRON ].style.backgroundImage = "url(" + this.menuStyle.chevronAreaHover + ")"; // "MChevronHover";
				}
				if( this._elements[ EL_ICON ] && this.iconHover )
				{
					this._elements[ EL_ICON ].src = this.iconHover;
				}
			
			}		
		}
		else
		{
			if( this._menu == this._parent )
			{
				if( ! this._expanded )
				{
					if( this._elements[ EL_CONTAINER_LEFT ] )
						this._elements[ EL_CONTAINER_LEFT ].src = this.menuStyle.barItemLeft; // "MItemHover";
					if( this._elements[ EL_CONTAINER_RIGHT ] )
						this._elements[ EL_CONTAINER_RIGHT ].src = this.menuStyle.barItemRight; // "MItemHover";					
					this._elements[ EL_CONTAINER ].className = this.menuStyle.barItemCss; // "MBarItem";
					this._elements[ EL_CONTAINER ].style.backgroundImage = "url(" + this.menuStyle.barItemTile + ")"; 
				}
			}
			else
			{
				if( this._elements[ EL_CONTAINER ] )
					this._elements[ EL_CONTAINER ].className = this.menuStyle.itemCss; // "MItem";
				
				if( this.menuStyle.usesIcons && this.checked )
				{
					if( this._elements[ EL_TEXT ] )
						this._elements[ EL_TEXT ].className = this.menuStyle._textCheckedCss; // "MText";
					if( this._elements[ EL_ICONAREA ] )
						this._elements[ EL_ICONAREA ].className = this.menuStyle._iconAreaCheckedCss; // "MIconArea";
				}
				else
				{
					if( this._elements[ EL_TEXT ] )
						this._elements[ EL_TEXT ].className = this.menuStyle.textCss; // "MText";
					if( this._elements[ EL_ICONAREA ] )
						this._elements[ EL_ICONAREA ].className = this.menuStyle.iconAreaCss; // "MIconArea";
				}
				if( this._elements[ EL_ICONAREA ] )
					this._elements[ EL_ICONAREA ].style.backgroundImage = "url(" + this.menuStyle.iconArea + ")";
				if( this._elements[ EL_TEXT ] )
					this._elements[ EL_TEXT ].style.backgroundImage = "url(" + this.menuStyle.itemTile + ")";
					
				if( this._elements[ EL_CHEVRON ] )
				{
					this._elements[ EL_CHEVRON ].className = this.menuStyle.chevronAreaCss; // "MChevron";
					this._elements[ EL_CHEVRON ].style.backgroundImage = "url(" + this.menuStyle.chevronArea + ")"; // "MChevron";
				}
				if( this._elements[ EL_ICON ] && this.icon )
				{
					this._elements[ EL_ICON ].src = this.icon;
				}
			}		
		}
	}
	
	
//	this._mouseOver	= false;
	
	this._onmousedown = function()
	{
		if( this._isSeparator )
			return;
		this._showState( "down" );		
	}
	
	this._onmouseup = function()
	{
		if( this._isSeparator )
			return;

		if( this._mouseOver )
		{
			this._onmouseover();
		}
		else
		{
			this._onmouseout();
		}
	}
	
	this._onmouseover = function()
	{
		if( this._isSeparator )
			return;
		this._mouseOver = true;
		
		if( this._menu._mouseDown )
		{
			this._onmousedown();
			return;
		}

		this._showState( "over" );
		
		window.status = this.tip == null ? this.text : this.tip;
	}
	
	this._onmouseout = function()
	{
		if( this._isSeparator )
			return;
		this._mouseOver = false;
		this._showState( "out" );		
		window.status = "";
	}	
	

	this._fixPosition = function( children )
	{
		var child		= this._elements[ EL_CHILD ];
		var self		= this._elements[ EL_CONTAINER ];
		
		if( ! child )
			return;

		if( arguments.length > 1 )
		{
			child.style.left	= arguments[ 1 ];
			child.style.top		= arguments[ 2 ];
		}
		else
		{
			var bounds	= _getBounds( self );
			var cb		= _getBounds( child );
			if( this._menu == this._parent && this._menu.orientation == "horizontal" )
			{
				child.style.left	= bounds.left;
				child.style.top		= bounds.bottom - 1;
				if( cb.width < bounds.width )
					child.style.width = bounds.width;
			}
			else
			{
				child.style.left	= bounds.right + 1;
				child.style.top		= bounds.top;
			}
		}
				
		if( this._parent != this._menu )
		{
			if( this.menuStyle.menuAlignment.substring( this.menuStyle.menuAlignment.length - 6 ) == "center" )
			{
				var childbounds		= _getBounds( child );
				child.style.top		= childbounds.top + ( ( bounds.height - childbounds.height ) / 2 );
			}
			else if( this.menuStyle.menuAlignment.substring( this.menuStyle.menuAlignment.length - 6 ) == "bottom" )
			{
				var childbounds		= _getBounds( child );
				child.style.top		= bounds.bottom - childbounds.height + ( _browserIs._IE ? 4 : 0 );
			}
		}
		
		if( this._parent == this._menu )
		{
			if( this.menuStyle.menuAlignment.substring( 0, 6 ) == "center" )
			{
				var childbounds		= _getBounds( child );
				child.style.left	= childbounds.left - ( ( bounds.width ) / 2 ) + ( bounds.left - childbounds.left );
			}
			else if( this.menuStyle.menuAlignment.substring( 0, 5 ) == "right" )
			{
				var childbounds		= _getBounds( child );
				child.style.left	= bounds.left - ( childbounds.width - bounds.width ) + ( _browserIs._IE ? 4 : 0 );
			}
		}		
		else if( this._parent._parent == this._menu )
		{
			if( this.menuStyle.firstLevelMenuOffsetX )
				child.style.left	= child.offsetLeft + this.menuStyle.firstLevelMenuOffsetX;
			if( this.menuStyle.firstLevelMenuOffsetY )
				child.style.top		= child.offsetTop + this.menuStyle.firstLevelMenuOffsetY;
		}
		else
		{
			if( this.menuStyle.menuOffsetX )
				child.style.left	= child.offsetLeft + this.menuStyle.menuOffsetX;
			if( this.menuStyle.menuOffsetY )
				child.style.top		= child.offsetTop + this.menuStyle.menuOffsetY;
		}
		
		if( this._menu.creator.fixPosition )
			this._menu.creator.fixPosition( this );
				
		if( children && this.items.length > 0 )
		{
			for( var index = 0; index < this.items.length; index++ )
			{
				this.items[ index ]._fixPosition( true );
			}
		}
	}
	
};

function _Rectangle( t, l, w, h )
{
	this.top = t;
	this.left = l;
	this.width = w;
	this.height = h;
	this.bottom	= t + h;
	this.right	= l + w;
};

function _getBounds( element )
{
	//if( element == null )
	//	return new _Rectangle( 0, 0, 0, 0 );
	var top		= element.offsetTop;
	var left	= element.offsetLeft;
	if( element.offsetParent )
	{
		var parent	= element.offsetParent;
		var client	= parent;
		while( true )
		{
			top		+= parent.offsetTop;
			left	+= parent.offsetLeft;
			
			if( _browserIs._IE )
			{
				top		+= client.clientTop;
				left	+= client.clientLeft;
				client	= parent;				
			}
			
			if( parent.offsetParent )
			{
				parent = parent.offsetParent;
			}
			else
			{
				break;
			}
		}
	}
	
	return new _Rectangle( top, left, element.offsetWidth, element.offsetHeight );
};

var _scripts	= new Array();
function registerScript( tag, script )
{
	if( ! _scripts[ tag ] )
	{
		_scripts[ tag ] = true;
		document.write( script );
	}
}

function registerCssMenuScript()
{
	registerScript( "CSSMENU", '<script language="javascript" src="/inc/cssmenucreator.js"></script>' );
}

function registerImageMenuScript()
{
	registerScript( "IMAGEMENU", '<script language="javascript" src="/inc/imagemenucreator.js"></script>' );
}