/******************************************************************* 
* 
* File    : xLayer.js 
* 
* Created : 2000/06/08 
* 
* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com 
* 
* Purpose : To create a cross browser dynamic layers. This 
*		library is based on the library defined in the 
*		excellent book. "JavasScript - The Definitive guide" 
*		by David Flanagan. Published by O'Reilly. 
*		ISBN 1-56592-392-8 
* 
* History 
* Date         Version        Description 
* 
* 2000-06-08	1.0		Initial version 
* 2000-06-17	1.1		Changed function name to setzIndex()
* 2000-06-17	1.2		Changed function name to getzIndex()
* 2000-08-07	1.3		Added the event handling functionality
*					from the book.
* 2000-08-15	1.4		Finally! The NS functions are now prototypes.
* 2000-10-14	1.5		Attempting to add NS6 (W3C Standard) functionality
* 2000-11-04	1.6		Added NS6 Event handling
* 2000-11-06	1.7		Added xLayerFromObj - Allows pre existing 
*					layers/divs to gain the functionality of xLayer.
* 2000-11-19	1.8		Changed the event handling to use an event object
*					and make the core properties the same.
*					e.type, e.button
*					e.layerX, e.layerY,  e.clientX, e.clientY, e.pageX, e.pageY
*					e.keyCode, e.altKey, e.ctrlKey, e.shiftKey
***********************************************************************/ 
var xLayerNo=0; 
function xLayer(newLayer, x, y) 
{
	if(x==null)x=0; 
	if(y==null)y=0; 
 	if(document.layers) 
	{
		if(typeof newLayer == "string")
		{
			this.layer=new Layer(100); 
			this.layer.document.open(); 
			this.layer.document.write(newLayer); 
			this.layer.document.close(); 
		}
		else
			this.layer=newLayer;

		this.layer.moveTo(x,y); 
		this.images=this.layer.document.images; 
 	} 
	else 
	if(document.all) 
	{
		var Xname;
		if(typeof newLayer == "string")
		{
			xName="xLayer" + xLayerNo++; 
 			var txt =   "<DIV ID='" + xName 
				+ "' STYLE=\"position:absolute;" 
				+ "left:"  + x + ";" 
				+ "top:"   + y + ";" 
				+ "visibility:hidden\">" 
				+ newLayer 
 				+ "</DIV>"; 

			document.body.insertAdjacentHTML("BeforeEnd",txt); 
		}
		else
			xName=newLayer.id;

		this.content = document.all[xName]; 
		this.layer   = document.all[xName].style; 
		this.images  = document.images; 
	} 
	else 
	if (document.getElementById)
	{
		/*** Add Netscape 6.0 support (NOTE: This may work in I.E. 5+. Will have to test***/

		var newDiv;

		if(typeof newLayer == "string")
		{
			var xName="xLayer" + xLayerNo++;

			var txt = ""
				+ "position:absolute;"
				+ "left:"  + x + "px;"
				+ "top:"   + y + "px;"
				+ "visibility:hidden";

			var newRange   = document.createRange();

			newDiv = document.createElement("DIV");
			newDiv.setAttribute("style",txt);
			newDiv.setAttribute("id", xName);

			document.body.appendChild(newDiv);

			newRange.setStartBefore(newDiv);
			strFrag = newRange.createContextualFragment(newLayer);	
			newDiv.appendChild(strFrag);
		}
		else
			newDiv = newLayer;

		this.content = newDiv;	
		this.layer   = newDiv.style;
		this.images  = document.images;
	}

	return(this); 
} 

function xLayerFromObj(theObj)
{
	if(document.layers)
		return(new xLayer(document.layers[theObj]));
	else 
	if(document.all)
		return(new xLayer(document.all[theObj]));
	else 
	if(document.getElementById)
		return(new xLayer(document.getElementById(theObj)));
}

if(navigator.appName.indexOf("Netscape") != -1 && !document.getElementById)
{
var eventmasks = {
      onabort:Event.ABORT, onblur:Event.BLUR, onchange:Event.CHANGE,
      onclick:Event.CLICK, ondblclick:Event.DBLCLICK, 
      ondragdrop:Event.DRAGDROP, onerror:Event.ERROR, 
      onfocus:Event.FOCUS, onkeydown:Event.KEYDOWN,
      onkeypress:Event.KEYPRESS, onkeyup:Event.KEYUP, onload:Event.LOAD,
      onmousedown:Event.MOUSEDOWN, onmousemove:Event.MOUSEMOVE, 
      onmouseout:Event.MOUSEOUT, onmouseover:Event.MOUSEOVER, 
      onmouseup:Event.MOUSEUP, onmove:Event.MOVE, onreset:Event.RESET,
      onresize:Event.RESIZE, onselect:Event.SELECT, onsubmit:Event.SUBMIT,
      onunload:Event.UNLOAD
};

/**** START prototypes for NS ***/ 
xLayer.prototype.moveTo 	= function(x,y) 	{ this.layer.moveTo(x,y); }
xLayer.prototype.moveBy 	= function(x,y) 	{ this.layer.moveBy(x,y); }
xLayer.prototype.show		= function() 	{ this.layer.visibility = "show"; }
xLayer.prototype.hide 		= function() 	{ this.layer.visibility = "hide"; }
xLayer.prototype.setzIndex	= function(z)	{ this.layer.zIndex = z; }
xLayer.prototype.setBgColor 	= function(color) { this.layer.bgColor = color; if(color==null)this.layer.background.src=null;}
xLayer.prototype.setBgImage 	= function(image) { this.layer.background.src = image; }
xLayer.prototype.getX 		= function() 	{ return this.layer.left; }
xLayer.prototype.getY 		= function() 	{ return this.layer.top; }
xLayer.prototype.getWidth 	= function() 	{ return this.layer.width; }
xLayer.prototype.getHeight 	= function() 	{ return this.layer.height; }
xLayer.prototype.getzIndex	= function()	{ return this.layer.zIndex; }
xLayer.prototype.isVisible 	= function() 	{ return this.layer.visibility == "show"; }
xLayer.prototype.setContent   = function(xHtml)
{
	this.layer.document.open();
	this.layer.document.write(xHtml);
	this.layer.document.close();
}

xLayer.prototype.clip = function(x1,y1, x2,y2)
{
	this.layer.clip.top	=y1;
	this.layer.clip.left	=x1;
	this.layer.clip.bottom	=y2;
	this.layer.clip.right	=x2;
}
xLayer.prototype.addEventHandler = function(eventname, handler) 
{
        this.layer.captureEvents(eventmasks[eventname]);
        var xl = this;
        this.layer[eventname] = function(event) { 
		event.clientX	= event.pageX;
		event.clientY	= event.pageY;
		event.button	= event.which;
		event.keyCode	= event.which;
		event.altKey	=((event.modifiers & Event.ALT_MASK) != 0);
		event.ctrlKey	=((event.modifiers & Event.CONTROL_MASK) != 0);
		event.shiftKey	=((event.modifiers & Event.SHIFT_MASK) != 0);
            return handler(xl, event);
        }
}
xLayer.prototype.removeEventHandler = function(eventName) 
{
	this.layer.releaseEvents(eventmasks[eventName]);
	delete this.layer[eventName];
}

/*** END NS ***/ 
} 
else if(document.all) 
{ 
/*** START prototypes for IE ***/ 
xLayer.prototype.moveTo = function(x,y) 
{ 
	this.layer.pixelLeft = x; 
	this.layer.pixelTop = y; 
} 
xLayer.prototype.moveBy = function(x,y) 
{ 
	this.layer.pixelLeft += x; 
	this.layer.pixelTop += y; 
} 
xLayer.prototype.show		= function() 	{ this.layer.visibility = "visible"; } 
xLayer.prototype.hide		= function() 	{ this.layer.visibility = "hidden"; } 
xLayer.prototype.setzIndex	= function(z)	{ this.layer.zIndex = z; } 
xLayer.prototype.setBgColor	= function(color) { this.layer.backgroundColor = color==null?'transparent':color; } 
xLayer.prototype.setBgImage	= function(image) { this.layer.backgroundImage = "url("+image+")"; } 
xLayer.prototype.setContent   = function(xHtml)	{ this.content.innerHTML=xHtml; } 
xLayer.prototype.getX		= function() 	{ return this.layer.pixelLeft; } 
xLayer.prototype.getY		= function() 	{ return this.layer.pixelTop; } 
xLayer.prototype.getWidth	= function() 	{ return this.layer.pixelWidth; } 
xLayer.prototype.getHeight	= function() 	{ return this.layer.pixelHeight; } 
xLayer.prototype.getzIndex	= function()	{ return this.layer.zIndex; } 
xLayer.prototype.isVisible	= function()	{ return this.layer.visibility == "visible"; } 
xLayer.prototype.clip		= function(x1,y1, x2,y2) 
{ 
	this.layer.clip="rect("+y1+" "+x2+" "+y2+" "+x1+")"; 
	this.layer.pixelWidth=x2; 
	this.layer.pixelHeight=y2; 
	this.layer.overflow="hidden"; 
}
xLayer.prototype.addEventHandler = function(eventName, handler) 
{
	var xl = this;
	this.content[eventName] = function() 
	{ 
            var e = window.event;
		e.layerX = e.offsetX;
		e.layerY = e.offsetY;
            e.cancelBubble = true;
            return handler(xl, e); 
	}
}
xLayer.prototype.removeEventHandler = function(eventName) 
{
	this.content[eventName] = null;
}
 /*** END IE ***/ 
} 
else if (document.getElementById) 
{
/*** W3C (NS 6) ***/ 
xLayer.prototype.moveTo = function(x,y)
{
	this.layer.left = x+"px";
	this.layer.top = y+"px";
}
xLayer.prototype.moveBy 	= function(x,y) 	{ this.moveTo(this.getX()+x, this.getY()+y); } 
xLayer.prototype.show		= function() 	{ this.layer.visibility = "visible"; }
xLayer.prototype.hide		= function() 	{ this.layer.visibility = "hidden"; }
xLayer.prototype.setzIndex	= function(z)	{ this.layer.zIndex = z; }
xLayer.prototype.setBgColor	= function(color) { this.layer.backgroundColor = color==null?'transparent':color; }
xLayer.prototype.setBgImage	= function(image) { this.layer.backgroundImage = "url("+image+")"; }
xLayer.prototype.getX		= function() 	{ return parseInt(this.layer.left); }
xLayer.prototype.getY		= function() 	{ return parseInt(this.layer.top); }
xLayer.prototype.getWidth	= function() 	{ return parseInt(this.layer.width); }
xLayer.prototype.getHeight	= function() 	{ return parseInt(this.layer.height); }
xLayer.prototype.getzIndex	= function()	{ return this.layer.zIndex; }
xLayer.prototype.isVisible	= function()	{ return this.layer.visibility == "visible"; }
xLayer.prototype.clip		= function(x1,y1, x2,y2)
{
	this.layer.clip="rect("+y1+" "+x2+" "+y2+" "+x1+")";
	this.layer.width=x2 + "px";
	this.layer.height=y2+ "px";
	this.layer.overflow="hidden";
}
xLayer.prototype.addEventHandler = function(eventName, handler) 
{
	var xl = this;
	this.content[eventName] = function(e) 
	{ 
            e.cancelBubble = true;
            return handler(xl, e);
	}
}
xLayer.prototype.removeEventHandler = function(eventName) 
{
	delete this.content[eventName];
}
xLayer.prototype.setContent   = function(xHtml)
{
	var newRange   = document.createRange();
	newRange.setStartBefore(this.content);

	while (this.content.hasChildNodes())
		this.content.removeChild(this.content.lastChild);

	var strFrag    = newRange.createContextualFragment(xHtml);	
	this.content.appendChild(strFrag);
}

} else
{
xLayer.prototype.moveTo 	= function(x,y) 	{  }
xLayer.prototype.moveBy 	= function(x,y) 	{  }
xLayer.prototype.show 		= function() 	{  }
xLayer.prototype.hide 		= function() 	{  }
xLayer.prototype.setzIndex	= function(z) {  }
xLayer.prototype.setBgColor 	= function(color) {  }
xLayer.prototype.setBgImage 	= function(image) {  }
xLayer.prototype.getX 		= function() 	{ return 0; }
xLayer.prototype.getY 		= function() 	{ return 0; }
xLayer.prototype.getWidth 	= function() 	{ return 0; }
xLayer.prototype.getHeight 	= function() 	{ return 0; }
xLayer.prototype.getzIndex	= function()	{ return 0; }
xLayer.prototype.isVisible 	= function() 	{ return false; }
xlayer.prototype.setContent   = function(xHtml) { }
}

/*** End  - xLayer - a cross browser layer object by www.Roy.Whittle.com ***/ /*******************************************************************

*

* File    : xBrowser.js

*

* Created : 2000/07/15

*

* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com

*

* Purpose : To create a cross browser "Browser" object.
*		This library will allow scripts to query parameters
*		about the current browser window.
*

* History

* Date         Version        Description

*

* 2000-06-08	1.0		Initial version
* 2000-08-31	1.1		Made all parameters function calls
* 2000-10-14	1.2		Made compatible with NS6
***********************************************************************/


function xBrowser()

{

	if(navigator.appName.indexOf("Netscape") != -1)
	{
		this.getCanvasWidth	= function() {return innerWidth;}
		this.getCanvasHeight	= function() {return innerHeight;}
		this.getWindowWidth 	= function() {return outerWidth;}
		this.getWindowHeight	= function() {return outerHeight;}
		this.getScreenWidth 	= function() {return screen.width;}
		this.getScreenHeight	= function() {return screen.height;}
		this.getMinX		= function() {return(pageXOffset);}
		this.getMinY		= function() {return(pageYOffset);}
		this.getMaxX		= function() {return(pageXOffset+innerWidth);}
		this.getMaxY		= function() {return(pageYOffset+innerHeight);}

	}

	else

	if(document.all)

	{
		this.getCanvasWidth	= function() {return document.body.clientWidth;}
		this.getCanvasHeight	= function() {return document.body.clientHeight;}
		this.getScreenWidth	= function() {return screen.width;}
		this.getScreenHeight	= function() {return screen.height;}
		this.getMinX		= function() {return(document.body.scrollLeft);}
		this.getMinY		= function() {return(document.body.scrollTop);}
		this.getMaxX		= function() {
			return(document.body.scrollLeft
				+document.body.clientWidth);
		}
		this.getMaxY		= function() {
				return(document.body.scrollTop
					+document.body.clientHeight);
		}
	}

	return(this);

}

/*** End  - xBrowser a cross browser "Browser" object by www.Roy.Whittle.com ***/

var myBrowser;
var staticMenu;
var floaterHeight = -1;

function CreateStaticMenu(theObj, x, y)
{
	myBrowser = new xBrowser();
	//this floater height is the height of the floater
	//floaterHeight = 500;
	floaterHeight = 700;
	staticMenu = new xLayerFromObj(theObj);
	staticMenu.baseX = x;
	staticMenu.baseY = y;
	staticMenu.x = x;
	staticMenu.y = y;
	staticMenu.moveTo(x,y);
	staticMenu.show();
	setInterval("ani()", 20);
}

function ani()
{
	var b = staticMenu;
//	var targetX = myBrowser.getMinX() + b.baseX;
//	var targetY = myBrowser.getMinY() + b.baseY;
	var targetY; 
	if (floaterHeight == -1)
	{
		targetY = myBrowser.getMinY() + b.baseY;
	}
	else
	{
		if (myBrowser.getCanvasHeight() <= (floaterHeight + b.baseY))
		{
			if (myBrowser.getMinY() <= b.baseY)
			{
				targetY = myBrowser.getMinY() + b.baseY;
			}
			else
			{
				targetY = myBrowser.getMaxY() - floaterHeight;
			}
		}
		else
		{
			targetY = myBrowser.getMinY() + b.baseY;
		}
	}

//	var dx = (targetX - b.x)/8;
	var dy = (targetY - b.y)/8;
//	b.x += dx;
	b.y += dy;
//alert(' Target y ' + targetY);
	b.moveTo(b.x, b.y);
}

function MM_showHideLayers() { //v6.0
		var i,p,v,obj,args=MM_showHideLayers.arguments;
		for (i=0; i<(args.length-2); i+=3) 
			if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
			if (obj.style) { obj=obj.style; v=(v=='inline')?'inline':(v=='none')?'none':v; }
			obj.display=v; }
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}function start() {
CreateStaticMenu("MenuDiv", 0, 25);
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
        for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

        if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu2(targ,selObj,restore){ //v3.0
    if (selObj.options[selObj.selectedIndex].value == '') {
  		window.open(selObj.options[selObj.selectedIndex].value);
  	} else {
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  	}
    if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


