/******************************************************************* 
* 
* File    : JSMenu2.js 
* 
* Created : 2001/10/17 
* 
* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com 
* 
* Purpose : To create a cross browser menu (just like all the others)
* 
* History 
* Date         Version        Description 
* 2001-10-20	0.1		Still in development
***********************************************************************/
if(!window.JSFX)
	window.JSFX=new Object();

JSFX.MenuBars = new Array();

JSFX.greyLAF = function()
{
	this.bgColor	= "#777777";
	this.bgColorOn	= "#BBBBBB";
	this.borderColorH	= "#BBBBBB";
	this.borderColorL	= "#333333";
	this.fontColor	= "#000000";
	this.fontColorOn	= "#CC0000";
	this.fontFace	= "Arial";
	this.fontSize	= "3";

	//Turn off hi color for NS (until I find a better way)
	if(ns4)
		this.fontColorOn	= null;
	this.borderSize=4;
}

JSFX.greyLAF2 = function()
{
	this.bgColor	= "#999999";
	this.bgColorOn	= "#DDDDDD";
	this.borderColorH	= "#BBBBBB";
	this.borderColorL	= "#333333";
	this.fontColor	= "#000000";
	this.fontColorOn	= "#CC0000";
	this.fontFace	= "Arial";
	this.fontSize	= "3";
	//Turn off hi color for NS (until I find a better way)
	if(ns4)
		this.fontColorOn	= null;
	this.borderSize=4;
}
JSFX.util = new Object();
JSFX.util.setDefaultLAF = function(theLAF)
{
	JSFX.util.defaultLAF = theLAF;
}
JSFX.util.getDefaultLAF = function()
{
	return JSFX.util.defaultLAF;
}

JSFX.util.setDefaultLAF( new JSFX.greyLAF() );

JSFX.theMenuTimer = null;
JSFX.startMenuCheck = function()
{
	if(JSFX.theMenuTimer == null)
		JSFX.theMenuTimer = setInterval("JSFX.menuCheck()", 500);
}
JSFX.menuCheck = function()
{
	var i;
	for(i=0 ; i<JSFX.MenuBars.length ; i++)
	{
		mb = JSFX.MenuBars[i];
		if(mb.currOn != null && !mb.isActive)
		{
			mb.currOn.close();
			mb.currOn = null;
		}
	}

}

/**********************************************************************/
/*
 * JSMenuItem - extends object
 */
JSFX.JSMenuItem = function (theText, theLink, theTarget, theLAF)
{

	if(!theText)
		return;

	if(theLAF == null)
		theLAF = JSFX.util.getDefaultLAF()

	this.elemType 	= "JSMenuItem";

	this.theText	= theText;
	this.theLink 	= theLink;
	this.theTarget 	= theTarget;
	this.LAF		= theLAF;
	this.currOn		= null;
	this.parentElem   = null;
	this.isVerticle 	= false;
	this.textPane	= null;
	this.glasspane	= null;

}

JSFX.JSMenuItem.prototype.build = function (theParent)
{
	this.textPane = new JSFX.BorderedLayer("<FONT FACE='"+this.LAF.fontFace+"' SIZE='"+this.LAF.fontSize+"'>&nbsp;"+this.theText+"&nbsp;</FONT>", this.LAF.borderSize, theParent);
	this.textPane.setzIndex(4);
	this.textPane.setBgColor(this.LAF.bgColor);
	this.textPane.setColor(this.LAF.fontColor);
	this.textPane.setBorderHighColor(this.LAF.borderColorH);
	this.textPane.setBorderLowColor(this.LAF.borderColorL);
	this.textPane.show();

	this.glassPane = new JSFX.Layer(" ", theParent);
	this.glassPane.setzIndex(100);
	this.glassPane.meniItem = this;
	this.glassPane.addEventHandler("onmouseover", JSFX.JSMenuItemOver);
	this.glassPane.addEventHandler("onmouseout",  JSFX.JSMenuItemOut);
	this.glassPane.addEventHandler("onmouseup",   JSFX.JSMenuItemUp);
	this.glassPane.show();

	this.originalWidth  = this.textPane.getWidth();
	this.originalHeight = this.textPane.getHeight();
}
JSFX.JSMenuItem.prototype.setBounds = function (x,y,w,h)
{
	this.textPane.resizeTo(w,h);
	this.textPane.moveTo(x, y);
	this.glassPane.resizeTo(w,h);
	this.glassPane.moveTo(x, y);

	var glassPaneStr = "<IMG SRC='javascript/jsmenu.gif' WIDTH='"+w+"' HEIGHT='"+h+"' BORDER='0'>"
	var contentStr   = glassPaneStr;
	if(this.theLink != null)
	{
		contentStr = "<A HREF='"+this.theLink+"'";
		if(this.theTarget != null)
			contentStr += " TARGET='"+this.theTarget+"'";
		contentStr += ">"+glassPaneStr+"</A>";
	}
	this.glassPane.setContent(contentStr);
}
JSFX.JSMenuItem.prototype.activate = function ()
{
	if(this.LAF.fontColorOn)
		this.textPane.setColor(this.LAF.fontColorOn);
	this.textPane.setBgColor(this.LAF.bgColorOn);
}
JSFX.JSMenuItem.prototype.deactivate = function ()
{
	if(this.LAF.fontColorOn)
		this.textPane.setColor(this.LAF.fontColor);
	this.textPane.setBgColor(this.LAF.bgColor);
}

JSFX.JSMenuItemOver = function(layer, ev)
{
	layer.meniItem.activate();
}
JSFX.JSMenuItemOut = function(layer, ev)
{
	layer.meniItem.deactivate();
}
JSFX.JSMenuItemUp = function(layer, ev)
{
}
