function CMenuTemplate()
{
	this.classType		= "Isometriq Menu Template";
	this.toString		= function() { return( this.classType	); }
	this.valueOf		= function() { return( this				); }
	
	//----------
	
	this.Width			= 0;
	this.Offset			= { Left	: 0			, Top		: 0		};
	this.Frame			= { Width	: 200		, Height	: 250	};
	this.Delay			= { Hide	: 300		, Show		: 150	};
	this.Animation		= { Enabled	: true		, Speed		: 10	};
	
	this.Image			= { Spacer	: "images/pixel.gif",	Expand		: "images/expand.gif"	};
	this.CssClass		= { Item	: "Menu Item",			ItemOver	: "Menu Item Over"		};
	
	if (Browser.OS.Mac)
		this.Animation.Enabled = false;
	
	return( this );
}

CMenuTemplate.prototype.Generate = function()
{
	document.write
	(
		"<div id=\"CMenu" + this.Index + ":Frame\" style=\"overflow:hidden;visibility:hidden;position:absolute;left:" + this.m_intLeft + "px;top:" + this.m_intTop + "px;width:" + this.Template.Frame.Width + "px;height:" + this.Template.Frame.Height + "px\">" +
			"<div id=\"CMenu" + this.Index + ":Container\" style=\"position:absolute;left:0px;top:0px\">" +
				"<table id=\"CMenu" + this.Index + ":Content\" width=\"" + this.Template.Width + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
	);
	
	for (var indItem=0; indItem<this.Items.length; indItem++)
	{
		document.write
		(
					"<tr id=\"CMenu" + this.Index + ":Item" + this.Items[indItem].Index + "\" style=\"cursor:pointer\">" +
						"<td id=\"CMenu" + this.Index + ":Item" + this.Items[indItem].Index + ":Label\" class=\"" + this.Template.CssClass.Item + "\" style=\"cursor:pointer\" nowrap><img src=\"" + this.Template.Image.Spacer + "\" width=\"4\" height=\"19\" align=\"absmiddle\">" + this.Items[indItem].Label + "<br><\/td>" +
						"<td id=\"CMenu" + this.Index + ":Item" + this.Items[indItem].Index + ":Expand\" align=\"right\" class=\"" + this.Template.CssClass.Item + "\" style=\"cursor:pointer\"><img src=\"" + (this.Items[indItem].Child==null ? this.Template.Image.Spacer : this.Template.Image.Expand) + "\" width=\"16\" height=\"15\" align=\"absmiddle\"><\/td>" +
					"<\/tr>"
		);
	}
	
	document.write
	(
				"<\/table>" +
			"<\/div>" +
		"<\/div>"
	);
	
	this.Initialize();
}

var DefaultMenuTemplate = new CMenuTemplate();





//----------





function CMenu( _objParent, _objTemplate, _intX, _intY )
{
	this.classType		= "Isometriq Menu";
	this.toString		= function() { return( this.classType	); }
	this.valueOf		= function() { return( this				); }
	
	//----------
	
	this.Index			= CMenu.Collection.length;
	this.Parent			= _objParent;
	this.Template		= _objTemplate;
	this.Items			= new Array();
	this.Child			= null;
	
	this.Generate		= _objTemplate.Generate;
	this.Frame			= null;
	this.Container		= null;
	this.Content		= null;
	
	this.OnAppear		= new Function();
	this.OnDisappear	= new Function();
	
	this.m_intLeft		= (_intX == null) ? 0 : _intX;
	this.m_intTop		= (_intY == null) ? 0 : _intY;
	this.m_indTimerHide	= null;
	this.m_indTimerShow	= null;
	this.m_intDepth		= 0;
	this.m_nbChilds		= 0;
	
	// ISO : SHOULD BE... //
	// this.Animation = new CAnimation( ... ) //
	this.m_intAnimationSpeed	= null;
	this.m_intAnimationTimer	= null;
	
	if (_objParent != null)
		_objParent.Child = this;
	
	for (var indArgument=4; indArgument<arguments.length; indArgument++)
	{
		var objItem			= arguments[indArgument];
		var indItem			= this.Items.length;
		
		objItem.Menu		= this;
		objItem.Index		= indItem;
		this.Items[indItem]	= objItem;
	}
	
	CMenu.Collection[CMenu.Collection.length] = this;
	return( this );
}



CMenu.Collection	= new Array();
CMenu.Depth			= 0;
CMenu.Hide = function( _blnAnimate )
{
	for (var indMenu=0; indMenu<CMenu.Collection.length; indMenu++)
		CMenu.Collection[indMenu].Hide( _blnAnimate, true );
}
CMenu.Generate = function()
{
	for (var indMenu=0; indMenu<CMenu.Collection.length; indMenu++)
		CMenu.Collection[indMenu].Generate();
}



CMenu.prototype.AddItems = function()
{
	for (var indArgument=0; indArgument<arguments.length; indArgument++)
	{
		var objItem			= arguments[indArgument];
		var indItem			= this.Items.length;
		
		objItem.Menu		= this;
		objItem.Index		= indItem;
		this.Items[indItem]	= objItem;
	}
}



CMenu.prototype.Generate = function()
{
}



CMenu.prototype.Initialize = function()
{
	if (window.document.all)
	{
		this.Frame		= window.document.all["CMenu" + this.Index + ":Frame"];
		this.Container	= this.Frame.Container	= window.document.all["CMenu" + this.Index + ":Container"];
		this.Content	= this.Frame.Content	= this.Container.Content = window.document.all["CMenu" + this.Index + ":Content"];
	}
	else if (window.document.getElementById)
	{
		this.Frame		= window.document.getElementById( "CMenu" + this.Index + ":Frame" );
		this.Container	= this.Frame.Container	= window.document.getElementById( "CMenu" + this.Index + ":Container" );
		this.Content	= this.Frame.Content	= this.Container.Content = window.document.getElementById( "CMenu" + this.Index + ":Content" );
	}
	else
		return( null );
	
	this.Content.Menu		= this.Container.Menu	= this.Frame.Menu	= this;
	this.Content.Frame		= this.Container.Frame	= this.Frame;
	this.Content.Container	= this.Container;
	
	if (Browser.OS.Mac && (Browser.OS.Version == "9"))
	{
		window.setTimeout( "CMenu.Collection[" + this.Index + "].Container.style.width = CMenu.Collection[" + this.Index + "].Content.offsetWidth + \"px\";", 1 );
		window.setTimeout( "CMenu.Collection[" + this.Index + "].Container.style.height = CMenu.Collection[" + this.Index + "].Content.offsetHeight + \"px\";", 1 );
		window.setTimeout( "CMenu.Collection[" + this.Index + "].Frame.style.width = CMenu.Collection[" + this.Index + "].Content.offsetWidth + \"px\";", 1 );
		window.setTimeout( "CMenu.Collection[" + this.Index + "].Frame.style.height = CMenu.Collection[" + this.Index + "].Content.offsetHeight + \"px\";", 1 );
	}
	else
	{
		this.Container.style.width	= this.Content.offsetWidth	+ "px";
		this.Container.style.height	= this.Content.offsetHeight	+ "px";
		this.Frame.style.width		= this.Content.offsetWidth	+ "px";
		this.Frame.style.height		= this.Content.offsetHeight	+ "px";
	}
	
	this.Container.onmouseover	= this.Container_MouseOver;
	this.Container.onmouseout	= this.Container_MouseOut;
	
	for (indItem=0; indItem<this.Items.length; indItem++)
		this.Items[indItem].Initialize();
	
	this.Frame.style.display = "block";
}



CMenu.prototype.Show = function( _blnAnimate, _blnReady )
{
	var blnAppear;
	
	if (_blnAnimate == null)
		_blnAnimate = this.Template.Animation.Enabled;
	
	if (this.m_indTimerHide != null)
	{
		window.clearTimeout( this.m_indTimerHide );
		this.m_indTimerHide = null;
	}
	
	if (_blnReady == false)
	{
		if (this.m_indTimerShow == null)
			this.m_indTimerShow = window.setTimeout( "CMenu.Collection[" + this.Index + "].Show(" + _blnAnimate + ",true)", this.Template.Delay.Show );
		
		return;
	}
	
	if (this.m_indTimerShow != null)
	{
		window.clearTimeout( this.m_indTimerShow );
		this.m_indTimerShow = null;
	}
	
	if (this.m_intDepth <= 0)
	{
		blnAppear = true;
		
		if (this.Parent)
		{
			if (this.Parent.Menu.m_intDepth <= 0)
				this.m_intDepth = 1;
			else
				this.m_intDepth = this.Parent.Menu.m_intDepth + 1;
		}
		else
			this.m_intDepth = 1;
		
		CMenu.Depth++;
		this.Frame.style.zIndex = CMenu.Depth;
		
		if (this.Parent != null)
			this.Parent.Menu.m_nbChilds++;
		
		this.OnAppear();
	}
	else
		blnAppear = false;
	
	if (_blnAnimate)
	{
		this.m_intAnimationSpeed = this.Template.Animation.Speed;
		
		if (blnAppear)
		{
			this.Frame.style.display = "block";
			
			if (this.m_intDepth > 1)
			{
				this.Container.style.left	= -this.Container.offsetWidth + "px";
				this.Container.style.top	= "0px";
			}
			else
			{
				this.Container.style.left	= "0px";
				this.Container.style.top	= -this.Container.offsetHeight + "px";
			}
			
			if (Browser.Netscape)
				window.setTimeout( "CMenu.Collection[" + this.Index + "].Frame.style.visibility=\"visible\";", 1 );
			else
				this.Frame.style.visibility = "visible";
		}
		
		if (this.m_intAnimationTimer == null)
			this.m_intAnimationTimer = window.setInterval( "CMenu.Collection[" + this.Index + "].AnimationFrame();", 11 );
	}
	else
	{
		this.Appear();
		this.Frame.style.display	= "block";
		this.Frame.style.visibility	= "visible";
	}
}



CMenu.prototype.Hide = function( _blnAnimate, _blnReady )
{
	if (_blnAnimate == null)
		_blnAnimate = this.Template.Animation.Enabled;
	
	if (this.m_indTimerShow != null)
	{
		window.clearTimeout( this.m_indTimerShow );
		this.m_indTimerShow = null;
	}
	
	if (!_blnReady)
	{
		if (this.m_indTimerHide == null)
			this.m_indTimerHide = window.setTimeout( "CMenu.Collection[" + this.Index + "].Hide(" + _blnAnimate + ",true);", this.Template.Delay.Hide );
		
		return;
	}
	
	if (this.m_indTimerHide != null)
	{
		window.clearTimeout( this.m_indTimerHide );
		this.m_indTimerHide = null;
	}
	
	if (_blnAnimate)
	{
		if (this.m_nbChilds > 0)
			this.m_indTimerHide = window.setTimeout( "CMenu.Collection[" + this.Index + "].Hide(true,true);", 50 );
		else
		{
			this.m_intAnimationSpeed = -this.Template.Animation.Speed / 1.6;
			
			if ((this.m_intAnimationTimer == null) && (this.m_intDepth > 0))
				this.m_intAnimationTimer = window.setInterval( "CMenu.Collection[" + this.Index + "].AnimationFrame();", 11 );
		}
	}
	else
	{
		this.Disappear();
	}
}



CMenu.prototype.Appear = function()
{
	if (this.m_intAnimationTimer != null)
	{
		window.clearInterval( this.m_intAnimationTimer );
		this.m_intAnimationTimer = null;
	}
	
	this.Container.style.left	= "0px";
	this.Container.style.top	= "0px";
}



CMenu.prototype.Disappear = function()
{
	if (this.m_intAnimationTimer != null)
	{
		window.clearInterval( this.m_intAnimationTimer );
		this.m_intAnimationTimer = null;
	}
	
	if (this.m_intDepth > 1)
	{
		this.Container.style.left		= "0px";
		this.Container.style.top		= -this.Container.offsetHeight + "px";
	}
	else
	{
		this.Container.style.left		= -this.Container.offsetWidth + "px";
		this.Container.style.top		= "0px";
	}
	
	this.Frame.style.visibility	= "hidden";
	this.Frame.style.display	= "none";
	this.Frame.style.zIndex		= 0;
		
	if (this.m_intDepth > 0)
	{
		CMenu.Depth--;
		
		if (this.Parent != null)
			this.Parent.Menu.m_nbChilds--;
		
		this.OnDisappear();
	}
	
	this.m_intDepth = 0;
}



CMenu.prototype.AnimationFrame = function()
{
	if (this.m_intDepth > 1)
	{
		var intCounter = parseInt( this.Container.style.left ) + this.m_intAnimationSpeed;
		
		if (intCounter <= -this.Container.offsetWidth)
			this.Disappear();
		else if  (intCounter >= 0)
			this.Appear();
		else
			this.Container.style.left = intCounter + "px";
	}
	else
	{
		var intCounter = parseInt( this.Container.style.top ) + this.m_intAnimationSpeed;
		
		if (intCounter <= -this.Container.offsetHeight)
			this.Disappear();
		else if  (intCounter >= 0)
			this.Appear();
		else
			this.Container.style.top = intCounter + "px";
	}
}



CMenu.prototype.Move = function( _intLeft, _intTop )
{
	if (_intLeft != null)
		this.Frame.style.left = _intLeft;
	
	if (_intTop != null)
		this.Frame.style.top = _intTop;
}



CMenu.prototype.Container_MouseOver = function( _objEvent )
{
	if (this.Menu.Parent)
	{
		this.Menu.Parent.Content.className	= this.Menu.Parent.Menu.Template.CssClass.ItemOver;
		this.Menu.Parent.Expand.className	= this.Menu.Parent.Menu.Template.CssClass.ItemOver;
		this.Menu.Parent.Menu.Container.onmouseover();
	}
	
	this.Menu.Show( null, true );
}



CMenu.prototype.Container_MouseOut = function( _objEvent )
{
	if (window.event)
	{
		intX = window.document.body.scrollLeft	+ window.event.clientX;
		intY = window.document.body.scrollTop	+ window.event.clientY;
		
		if (Browser.OS.Windows)
		{
			intX -= 2;
			intY -= 2;
		}
	}
	else if (_objEvent)
	{
		intX = window.pageXOffset + _objEvent.clientX;
		intY = window.pageYOffset + _objEvent.clientY;
	}
	
	var intLeft		= parseInt( this.Frame.style.left );
	var intTop		= parseInt( this.Frame.style.top );
	var intRight	= intLeft	+ this.offsetWidth	- parseInt( this.style.left )
	var intBottom	= intTop	+ this.offsetHeight	- parseInt( this.style.top )
	
	if ((intX > intLeft	) && (intX < intRight	) &&
		(intY > intTop	) && (intY < intBottom	))
		return;
	
	this.Menu.Hide( null, false );
	
	if (this.Menu.Parent)
	{
		this.Menu.Parent.Content.className	= this.Menu.Parent.Menu.Template.CssClass.Item;
		this.Menu.Parent.Expand.className	= this.Menu.Parent.Menu.Template.CssClass.Item;
		this.Menu.Parent.Menu.Container.onmouseout( _objEvent );
	}
}










//----------










function CMenuItem( _strLabel, _strHref, _strScript )
{
	this.classType		= "Isometriq Menu Item";
	this.toString		= function() { return( this.classType	); }
	this.valueOf		= function() { return( this				); }
	
	//----------
	
	this.Index		= null
	this.Menu		= null;
	this.Child		= null;
	this.Label		= (_strLabel && _strLabel.length) ? _strLabel : "&nbsp;";
	this.Href		= _strHref;
	
	this.Frame		= null;
	this.Content	= null;
	this.Expand		= null;
	
	this.OnClick	= new Function( _strScript );
	
	return( this );
}



CMenuItem.prototype.Initialize = function()
{
	if (window.document.all)
	{
		this.Frame		= window.document.all["CMenu" + this.Menu.Index + ":Item" + this.Index];
		this.Content	= this.Frame.Content	= window.document.all["CMenu" + this.Menu.Index + ":Item" + this.Index + ":Label"];
		this.Expand		= this.Frame.Expand		= window.document.all["CMenu" + this.Menu.Index + ":Item" + this.Index + ":Expand"];
	}
	else if (window.document.getElementById)
	{
		this.Frame		= window.document.getElementById( "CMenu" + this.Menu.Index + ":Item" + this.Index );
		this.Content	= this.Frame.Content	= window.document.getElementById( "CMenu" + this.Menu.Index + ":Item" + this.Index + ":Label" );
		this.Expand		= this.Frame.Expand		= window.document.getElementById( "CMenu" + this.Menu.Index + ":Item" + this.Index + ":Expand" );
	}
	else
		return( null );
	
	this.Content.Menu	= this.Expand.Menu	= this.Frame.Menu	= this.Menu;
	this.Content.Child	= this.Expand.Child	= this.Frame.Child	= this.Child;
	this.Content.Item	= this.Expand.Item	= this.Frame.Item	= this;
	this.Content.Frame	= this.Expand.Frame	= this.Frame;
	
	this.Frame.onmouseover		= this.Item_MouseOver;
	this.Frame.onmouseout		= this.Item_MouseOut;
	this.Frame.onclick			= this.Item_Click;
}



CMenuItem.prototype.Item_MouseOver = function( _objEvent )
{
	this.Content.className	= this.Menu.Template.CssClass.ItemOver;
	this.Expand.className	= this.Menu.Template.CssClass.ItemOver;
	
	if (this.Child != null)
	{
		this.Child.Move( parseInt( this.Menu.Frame.style.left ) + this.Menu.Container.offsetWidth - 1, parseInt( this.Menu.Frame.style.top ) + (this.offsetHeight * this.Item.Index) );
		this.Child.Show( null, this.Child.m_intAnimationTimer != null );
	}
}



CMenuItem.prototype.Item_MouseOut = function( _objEvent )
{
	if (window.event)
	{
		intX = window.document.body.scrollLeft	+ window.event.clientX;
		intY = window.document.body.scrollTop	+ window.event.clientY;
		
		if (Browser.OS.Windows)
		{
			intX -= 2;
			intY -= 2;
		}
	}
	else if (_objEvent)
	{
		intX = window.pageXOffset + _objEvent.clientX;
		intY = window.pageYOffset + _objEvent.clientY;
	}
	
	var intLeft		= parseInt( this.Menu.Frame.style.left ) + this.Menu.Template.Offset.Left;
	var intTop		= parseInt( this.Menu.Frame.style.top )  + this.Menu.Template.Offset.Top + (this.offsetHeight * this.Item.Index) - parseInt( this.Menu.Container.style.top );
	var intRight	= intLeft	+ this.offsetWidth - parseInt( this.Menu.Container.style.left );
	var intBottom	= intTop	+ this.offsetHeight;
	
	if ((intX > intLeft	) && (intX < intRight	) &&
		(intY > intTop	) && (intY < intBottom	))
		return;
	
	this.Content.className	= this.Menu.Template.CssClass.Item;
	this.Expand.className	= this.Menu.Template.CssClass.Item;
	
	if (this.Child != null)
		this.Child.Hide( null, true );
}



CMenuItem.prototype.Item_Click = function( _objEvent )
{
	if (this.Item.Href != null)
		window.location.href = this.Item.Href;
	
	this.Content.className	= this.Menu.Template.CssClass.Item;
	this.Expand.className	= this.Menu.Template.CssClass.Item;
	
	CMenu.Hide( false );
	
	this.Item.OnClick();
}