/**
*	Layer Javascript Class
*
*	Creates an object that represents a layer. Layer can be an existing layer in the 
*	specified container, or it can be a new layer definition that can be defined
*	by setting properties and created by calling the build function of this object.
*	This object then provides methods for manipulating the layer, like 
*	specifying content, moving, sizing, etc., or returns the current properties
*	like width, height, etc.
*/


/**
*	Layer class constructor
*	Creates the layer object that represents the existing layer passed in the
*	layer parameter (string or object reference), or a new layer that will be
*	created in the container object specified when the build function is called.<b> 
*	If it is an existing layer, the properties specified will be applied to the 
*	layer in the constructor, if not existing yet, the properties will be applied
*	to the layer when it is created with the build() method.
*/
function Layer(container, layer, properties){
	//	Establish superclass and inherit methods, StageElement contains 
	//	helper methods for objects that work with the screen
	this.inheritFrom = StageElement;
	this.inheritFrom(container);
	this.id="Layer";
	
	//
	//	Properties of this object
	
	//	Reference to the actual div that this object controls,
	//	div is passed to constructor, or created in build() method 
	this.div = null;
	
	//	Indicates whether this object has been built successfully
	this.built = false;
	
	//	Content stored here when passed before layer has been created
	this.initContent = null;
	
	this.divName = null;
	this.divBaseName = "autoDiv";
	
	//	Properties are stored here when passed before layer has been
	//	created, then applied to div in build() method
	this.initProps = null;
	
	
	
	//	If layer is specified, get that layer and use as 
	//	base layer of this object. The findLayer function will 
	//	find the layer if only the div id is specified, or if 
	//	a reference to the div is passed, it returns the reference
	if(layer) {
		this.div = this.findObj(layer);
		this.built = true;
		}
	
	//
	//	Add methods to this object
	
	this.build = layer_build;
	this.setLayer = layer_setLayer;
	this.setProperties = layer_setProperties;
	this.setProperty = layer_setProperty;
	this.addInitProp = layer_addInitProp;
	this.getInitProp=layer_getInitProp;
	
	this.setContent = layer_setContent;
	this.addContent=layer_addContent;
	this.prependContent=layer_prependContent;
	this.getContent = layer_getContent;
	
	this.position = layer_position;
	
	this.setDivName = layer_setDivName;
	this.getDivName = layer_getDivName;
	this.getDiv=layer_getDiv;
	this.setBaseName = layer_setBaseName;
	this.getBaseName = layer_getBaseName;
	this.setDisplay = layer_setDisplay;
	this.getDisplay=layer_getDisplay;
	
	this.show = layer_show;
	this.hide = layer_hide;
	this.inheritVisibility = layer_inheritVisibility;
	
	this.createDomLayer = layer_createDomLayer;
	
	this.getAbsPosition = layer_getAbsPosition;
	
	this.setTop = layer_setTop;
	this.getTop = layer_getTop;
	this.getAbsTop = layer_getAbsTop;
	
	this.setLeft = layer_setLeft;
	this.getLeft = layer_getLeft;
	this.getAbsLeft = layer_getAbsLeft;
	
	this.setWidth = layer_setWidth;
	this.getWidth = layer_getWidth;
	this.setHeight = layer_setHeight;
	this.getHeight = layer_getHeight;
	
	this.setBackgroundColor=layer_setBackgroundColor;
	this.getBackgroundColor=layer_getBackgroundColor;
	this.setBackgroundImage=layer_setBackgroundImage;
	this.setBorder=layer_setBorder;
	this.setOpacity=layer_setOpacity;
	this.setPosition=layer_setPosition;
	this.getPositioning=layer_getPositioning;
	
	this.createDomLayer=layer_createDomLayer;
	
	this.addEventHandler=layer_addEventHandler;
	this.setEventHandlerWrapper=layer_setEventHandlerWrapper;
	this.propagateEvent=layer_propagateEvent;
	
	this.printProperties = layer_printProperties;
	
	//	If properties passed, call function that will apply any properties 
	//	specified if a layer passed, or if no layer, saves properties as initProps.
	if(properties){this.setProperties(properties);}
	}



/**
*	build
*
*	Creates the needed div tag in the document passed if the div
*	in this.div does not already exist, if force parameter is true
*	the div is re-created even if it exists.
*/
function layer_build(force) {

	//	Don't build the div if the div exists already,
	//	unless force tag is true
	if(!force && this.built && this.div && (typeof this.div == "object")){return;}
	
	if(this.dom) this.createDomLayer();
	else if(this.ie) this.createIeLayer();
	else if(this.net) this.createNetLayer();
	
	this.built = true;
	
}	//	build



/**
*	setLayer
*
*	Sets the layer that will be positioned by default by this object, can be
*	passed as layer reference or string.
*/
function layer_setLayer(layer){
	this.setDivName(layer);
	this.div = this.findObj(layer);
	this.built = true;
}	//	setLayer



/**
*	setProperties
*	
*	Convienence function, sets the values in an associative array as 
*	properties for this layer.  Properties can be passed as associative
*	array of name/value pairs for each property.  If called before this object 
*	is initialized, property values are stored in the this.initProps collection 
*	variable and applied once the object is created with the build() function, 
*	otherwise properties are applied directly.
*/
function layer_setProperties(properties){
	
	//	If properties passed but this hasn't been built, save properties and return
	if(properties && !this.div){
		if(!this.initProps)	{
			this.initProps = new Array();
			}
		//	Copy properties into initProps array
		for(key in properties){this.initProps.push({key:key,value:properties[key]});}
		
		return;
		}
	else if(!this.div) {
		return;
		}
	
	//	If initProps variable exists, set values in the init props array
	if(this.initProps){
		for(var i=0; i<this.initProps.length; i++){
			try{this.setProperty(this.initProps[i].key, this.initProps[i].value);}
			catch(e){
				this.log.warn("Layer.setProperties() Error occurred while setting the initial property " + this.initProps[i].key + " to " + this.initProps[i].value + ", error=" + e.toString());
				}
			}
		}
	
	if(!properties){
		return;
		}
	
	for(key in properties){
		var value = properties[key];
		try{this.setProperty(key, value);}
		catch(e){
			this.log.warn("Layer.setProperties() Error occurred while setting the property " + key + " to " + value + ", error=" + e.toString());
			}
		}
	this.initProps = null;
}	//	setProperties



/**
*	setProperty
*	
*	Sets a property on this object's div tag, called by other methods.
*/
function layer_setProperty(key, value){
	
	//	If not initialized, add property to the initProps collection,
	//	will be set when div object is being created or just after
	if(!this.div){
		this.addInitProp(key,value);
		return;
		}
	//this.log.debug("setting prop " + key + " to " + value);
	//	If a setter function exists for the property, call it
	var setterName = "set" + key.charAt(0).toUpperCase() + key.substring(1);
	if(this[setterName]){
		this[setterName](value);
		return;
		}
	
	//	Try to set style property
	if(this.div.style){
		this.div.style[key]=value;
		}
	else if(this.div.setAttribute){
		//this.log.debug("Setting dom attribute " + key + " to " + value);
		//	Set value using dom
		this.div.setAttribute(key, value);
		}
	
}	//	setProperty



/**
*	addInitProp
*	
*	Helper function, adds a key:value object to the initProps array, if 
*	array does not exist, it creates it before adding.
*/
function layer_addInitProp(key,value){
	if(!this.initProps){this.initProps = new Array();}
	this.initProps.push({key:key,value:value});
}	//	addInitProp


/**
*	getInitProp
*	Returns the value of an init property if the div has not been set yet.
*/
function layer_getInitProp(key){
	if(!this.initProps){return null;}
	for(var i=0; i<this.initProps.length; i++){
		if(this.initProps[i].key == key){
			return this.initProps[i].value;
			}
		}
	return null;
}	//	getInitProp


/**
*	setContent
*
*	Sets the content of the layer as a string.
*/
function layer_setContent(content){
	
	if(!this.div){
		this.initContent = content;
		return;
		}
	
	if(!content && this.initContent){
		content = this.initContent;
		this.initContent = null;
		}
	
	if(typeof content == "string"){
		this.div.innerHTML = content;
	}
	
}	//	setContent


/**
*	addContent
*
*	Adds the passed content to the bottom of the layer.
*/
function layer_addContent(content){
	if(this.div&&this.div.innerHTML)this.div.innerHTML+=content;
}	//	addContent

/**
*	prependContent
*	
*	Prepends passed content to the content of the layer.
*/
function layer_prependContent(content){
	if(this.div&&this.div.innerHTML)this.div.innerHTML=content+this.div.innerHTML;
}	//	prependContent
	

/**
*	getContent
*
*	Gets the content of this layer, doesn't work with Netscape 4.x.
*/
function layer_getContent(layerObj){
	if(net4) return "";
	if(layerObj)return layerObj.innerHTML;
}	//	getContent

/**
*	position
*
*	Uses the Position class and a position definition (passed) to 
*	position this layer on screen
*/
function layer_position(alignFrom, alignTo, offset){
	var posObj = new Positioner(this.container, this, alignFrom, alignTo, offset);
	posObj.position();
}	//	position



/**
*	setDivName
*
*	Sets the name that will be used for the div created by this object,
*	default is "autoDiv_XX" where XX is an integer to make the name unique. 
*	This method must be called before the build() function is called.
*/
function layer_setDivName(name){if(this.div)return; this.divName = name;}

/**
*	getDivName
*
*	Returns the id of the div tag used by this object, null if div not created yet.
*/
function layer_getDivName(){
	if(this.divName)return this.divName;
	else return this.div.id;
	}

/**
*	getDiv
*	Gets reference to this object's div.
*/
function layer_getDiv(){return this.div;}

/**
*	setBaseName
*	
*	Sets the base layer name for layers names that are generated by this object,
*	default base name is "autoDiv_", a unique two digit number is appended to the
*	base name.  This method must be called before the build() function is called.
*/
function layer_setBaseName(name){if(this.div)return; this.divBaseName = name;}

/**
*	getBaseName
*	
*	Returns the base name used to name layers. When the div for this object is 
*	created, the div id is set to either the base name plus a two digit number
*	to make the name unique on the page, or to the divName (if it is manually
*	specified). 
*/
function layer_getBaseName(){return this.divBaseName;}


//	Functions to show/hide layer

/**
*	show
*
*	Sets the visibility of the layer to 'visible' to show the layer
*/
function layer_show(){
	if(!this.built){
		//	Save visibility in initProps if not built yet
		this.addInitProp("visibility","visible");
		}
	//	Use parent class function to show
	else this.showObj(this.div);
}	//	show

/**
*	hide 
*
*	Sets the visibility of the layer to 'hidden' to hide the layer
*/
function layer_hide(){
	if(!this.built){
		//	Save visibility in initProps if not built yet
		this.addInitProp("visibility","hidden");
		}
	//	Use parent class function to hide
	else this.hideObj(this.div);
}	//	hide

/**
*	inheritVisibility
*
*	Sets the visibility of the layer to 'inherit' to cause the layer
*	to inherit the visibilty of its parent object.
*/
function layer_inheritVisibility(){
	if(!this.built){
		//	Save visibility in initProps if not built yet
		this.addInitProp("visibility","inherit");
		}
	else if(this.net4)this.div.visibility="inherit";
	else if(this.ie4||this.dom)this.div.style.visibility="inherit";
}	//	inheritVisibility



/**
*	getAbsPosition
*
*	Gets the absolute position of any screen object on screen, if no
*	object passed, returns the absolute position of this object's div.
*/
function layer_getAbsPosition(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	// For netscape, get page position
	if(this.net4 && obj){
		if(obj.pageX || obj.pageY){	//Layer
			var posX=obj.pageX; var posY=obj.pageY;
		}
		else if(obj.x || obj.y){	//Graphic
			//	x and y are relative for img tags, so check to see if the
			//	custom property offsetParent was set by findObj function, if so, 
			//	check to see if this has pageX and pageY, if so, add this in to get
			//	absolute position, otherwise this will return relative position
			var posX = ((obj.offsetParent&&obj.offsetParent.pageX) ? obj.x + obj.offsetParent.pageX : obj.x);
			var posY = ((obj.offsetParent&&obj.offsetParent.pageY) ? obj.y + obj.offsetParent.pageY : obj.y);
		}
		else{
			var posX = null;
			var posY = null;
		}
	}
	else if(obj){
		var windowDX =0;
		var windowDY =0;
		if ((obj.offsetParent)&&(obj.offsetParent.tagName!="BODY")){
			//	Cycle through container layers, add up the offsets
			curObj=obj;
			while((curObj.offsetParent)&&(curObj.offsetParent.tagName!="BODY")){
				windowDX+=curObj.offsetParent.offsetLeft;
				windowDY+=curObj.offsetParent.offsetTop;
				curObj=curObj.offsetParent;
				}
			}
		else{
			windowDX = 0;
			windowDY = 0;
			}
		var posX=(obj.offsetLeft + windowDX);
		var posY=(obj.offsetTop + windowDY);
		}
	return new Array(posX, posY);
	
}	//	getAbsPosition


/**
*	setTop
*
*	Sets the distance from top of document for div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setTop(top){
	if(!this.div){this.addInitProp("top",top);}
	else {
		if(this.ie4||this.dom){
			if((typeof top=="number")||(top.indexOf("px")<0)){
				top=""+top+"px";
				}		
			this.div.style.top=top;
			}
		else if(this.net4)this.div.top=top;
		}
}	//	setTop

/**
*	getTop
*	
*	Gets the top position of obj RELATIVE to the obj's parent object.
*	Use getAbsTop to get the absolute position of the obj on screen.
*	If obj not passed, returns position of this object's div.
*/
function layer_getTop(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	
	if(this.ie4||this.dom)return obj.offsetTop;
	if(this.net4)return obj.top;
	return null;
}	//	getTop

/**
*	getAbsTop
*	
*	Gets the absolute top position of obj, by using getPosition() method
*	which steps through all parent objects to calculate absolute position.
*	If obj not passed, returns position of this object's div.
*/
function layer_getAbsTop(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	
	var posArray=this.getAbsPosition(obj);
	if((typeof posArray=="object")&&(posArray.length>0))return posArray[1];
}	//	getAbsTop



/**
*	setLeft
*
*	Sets the distance from left of document for div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setLeft(left){
	if(!this.div){this.addInitProp("left",left);}
	else {
		if(this.ie4||this.dom){
			if((typeof left=="number")||(left.indexOf("px")<0)){
				left=""+left+"px";
				}
			this.div.style.left=left;
			}
		else if(this.net4)this.div.left=left;
		}
}	//	setLeft

/**
*	getLeft
*	
*	Gets the left position of obj RELATIVE to the obj's parent object.
*	Use getAbsLeft to get the absolute position of an obj on screen.
*	If obj not passed, returns position of this object's div.
*/
function layer_getLeft(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	
	if(this.ie4||this.dom)return obj.offsetLeft;
	if(this.net4)return obj.left;
	return null;
}	//	getWidth

/**
*	getAbsLeft
*	
*	Gets the absolute left position of obj, by using getPosition() method
*	which steps through all parent objects to calculate absolute position.
*	If obj not passed, returns position of this object's div.
*/
function layer_getAbsLeft(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	var posArray=this.getAbsPosition(obj);
	if((typeof posArray=="object")&&(posArray.length>0)) return posArray[0];
}	//	getAbsLeft



/**
*	setRight
*
*	Sets the distance from right of container layer for div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setRight(right){
	if(!this.div){this.addInitProp("right",right);}
	else {
		if(this.ie4||this.dom){
			if((typeof right=="number")||(right.indexOf("px")<0)){
				right=""+right+"px";
				}
			this.div.style.right=right;
			}
		else if(this.net4)this.div.right=right;
		}
}	//	setRight

/**
*	getRight
*	
*	Gets the right position of obj RELATIVE to the obj's parent object.
*	If obj not passed, returns right position of this object's div.
*/
function layer_getRight(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	
	if(this.ie4||this.dom)return obj.offsetRight;
	if(this.net4)return obj.right;
	return null;
}	//	getRight

/**
*	setBottom
*
*	Sets the distance from bottom of container layer for div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setBottom(left){
	if(!this.div){this.addInitProp("bottom",bottom);}
	else {
		if(this.ie4||this.dom){
			if((typeof bottom=="number")||(bottom.indexOf("px")<0)){
				bottom=""+bottom+"px";
				}
			this.div.style.bottom=bottom;
			}
		else if(this.net4)this.div.bottom=bottom;
		}
}	//	setBottom

/**
*	getBottom
*	
*	Gets the bottom position of obj RELATIVE to the obj's parent object.
*	If obj not passed, returns position of this object's div.
*/
function layer_getBottom(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	
	if(this.ie4||this.dom)return obj.offsetBottom;
	if(this.net4)return obj.bottom;
	return null;
}	//	getBottom


/**
*	setWidth
*	
*	Sets the width of this object's div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setWidth(width){
	if(!this.div){this.addInitProp("width",width);}
	else {
	if(this.ie4)this.div.style.pixelWidth=width;
		else if(this.dom){
			if((typeof width=="number")||((typeof width=="string")&&(width.indexOf("px")<0))){
				width=""+width+"px";
				}
			this.div.style.width=width;
			}
		else if(this.net4){
			this.div.clip.width=width;
			this.div.width=width;
			}
	}
}	//	setWidth

/**
*	getWidth
*	
*	Gets the width of obj, if no object passed, returns the width
*	of this object's div.
*/
function layer_getWidth(obj){
	//	If another object was not passed, use this object's div
	if(!obj){if(!this.div){return;}else {obj = this.div;}}
	if(this.dom){return obj.offsetWidth;}
	if(this.ie4)return obj.clientWidth;
	if(this.net4){
		if(obj.clip)return obj.clip.width;
		else if(obj.width)return obj.width;
		}
	return 0;
}	//	getWidth


/**
*	setHeight
*
*	Sets the height of div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setHeight(height){
	if(!this.div){this.addInitProp("height",height);}
	else {
		if(this.ie4)this.div.style.pixelHeight=height;
		else if(this.dom){
			if((typeof height=="number")||((typeof height=="string")&&(height.indexOf("px")<0))){
				height=""+height+"px";
				}
			this.div.style.height=height;
			}
		else if(this.net4){
			this.div.clip.height=height;
			this.div.height=height;
			}
	}
}	//	setHeight

/**
*	getHeight
*	
*	Gets the height of obj, if no object passed, returns the height
*	of this object's div.
*/
function layer_getHeight(obj){
	//	If another object was not passed, use this object's div
	if(!obj)obj = this.div;
	if(this.dom)return obj.offsetHeight;
	if(this.ie4)return obj.clientHeight;
	if(this.net4){
		if(obj.clip)return obj.clip.height;
		else if(obj.height)return obj.height;
		}
	return 0;
}	//	getHeight



/**
*	setBackgroundColor
*
*	Sets the background color of the div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setBackgroundColor(backgroundColor){
	if(!this.div){this.addInitProp("backgroundColor",backgroundColor);}
	else {
		if(this.ie4||this.dom)this.div.style.backgroundColor=backgroundColor;
		else if(this.net4)this.div.bgColor=backgroundColor;
		}
}	//	setBackgroundColor

function layer_getBackgroundColor(){
	if(this.ie4||this.dom)return this.div.style.backgroundColor;
	else if(this.net4)return this.div.bgColor;
	}

/**
*	setBackgroundImage
*
*	Sets a background image for the div.
*/
function layer_setBackgroundImage(image){
	if(!this.div){this.addInitProp("backgroundImage",image);}
	else {
		this.div.style.backgroundImage=image;
		}
}	//	setBackgroundImage

/**
*	setBorder
*/
function layer_setBorder(border){
	if(!this.div){this.addInitProp("border",border);}
	else {
		this.div.style.border=border;
		}
}	//	setBorder

/**
*	setOpacity
*
*	Sets the opacity (or inversly transparency) of the div and its contentx, 
*	this function converts the value to correct css property for ie
*	and moz based browsers.  Pass opacity as value between 0 and 1, with 1 
*	being fully opaque, or no transaparency.
*	For opacity to work item must have a placement specified (float:left, or 
*	position:absolute) 
*/
function layer_setOpacity(value){
	if(!this.div){this.addInitProp("opacity",value);}
	else {
		if(this.ie4){
			//	set ie version
			value=value*100;
			//this.log.debug("Setting filter to " +"alpha(opacity="+value+")");
			this.div.style.filter="alpha(opacity="+value+")";
			}
		else if(this.dom){
			this.div.style.opacity=value;
			}
		}
}	//	setOpacity


/**
*	setPosition
*
*	Sets the type of positioning to use with the div (absolute, relative, static, etc).
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setPosition(position){
	if(!this.div){this.addInitProp("position",position);}
	else {
		if(this.ie4||this.dom)this.div.style.position=position;
		}
}	//	setPosition

/**
*	getPositioning
*	Returns the positioning style attribute if present, indicating whether the div is
*	absolute, relative, static, etc, positioned.
*/
function layer_getPositioning(){
	if(!this.div){return this.getInitProp("position");}
	else {
		if(this.ie4||this.dom){return this.div.style.position};
		}
	return null;
}	//	getPositioning

/**
*	setCssFloat
*	Sets the value of the "float" property, which is referred to as "cssFloat" in
*	javascript because float a reserved word, so we use property "cssFloat".
*/
function layer_setCssFloat(value){
	if(!this.div){this.addInitProp("cssFloat",value);}
	else {this.div.style.cssFloat=value;}
}	//	setCssFloat

/**
*	setDisplay
*
*	Sets the display attribute of div.
*	Can be called directly, or through setProperties and setProperty methods.
*/
function layer_setDisplay(display){
	if(!this.div){this.addInitProp("display",display);}
	else this.div.style.display = display;
}	//	setDisplay

/** 
*	getDisplay
*	Returns value of display style property, if display is not set in object's style,
*	tries to get display value from style sheet.
*/
function layer_getDisplay(){
	if(!this.div){return null;}
	if(this.ie4||this.dom){
		if((this.div.style.display=="")&&this.container.defaultView){
			//	No local display set, see if there is a display in stylesheet
			var dispStyle=this.container.defaultView.getComputedStyle(this.div,null).getPropertyValue("display");
			if(dispStyle!=""){this.div.style.display=dispStyle;}
			else {this.div.style.display="block";}
			}
		return this.div.style.display;
		}
	return null;
}	//	getDisplay

/**
*	createDomLayer
*
*	Creates a new div for this element in the container element using
* 	DOM methods.
*/
function layer_createDomLayer(){
	var tDiv=this.container;
	
	this.div = document.createElement('div');
	
	if(!this.divName){
		var numb = 0;
		this.divName = this.divBaseName + this.getTwoDigitNumber(numb);
		//	See if div with this id exists, increment numb until false
		while (document.getElementById(this.divName))this.divName = this.divBaseName + this.getTwoDigitNumber(++numb);
		}
	this.div.id = this.divName;
	
	//	If container has a body element, container is  
	//	document so add layer to the body element
	if(this.container.body){
		tDiv=this.container.body;
		}
	else if(this.container.getDiv){
		//	Container is another layer class, try to get div from
		//	class and add this div to it 
		if(!this.container.built){
			//	This container is not built, can't add layer to it...
			this.log.error("Tried to add a layer to a layer class that has not been built.");
			return;
			}
		var tDiv=this.container.getDiv();
		if(!tDiv)return;
		}
	//	Set any defined properties on the div
	this.setProperties();
	this.setContent();
	
	tDiv.appendChild(this.div);
	
	this.div.layerObj=this;
}	//	createDomLayer


/**
*	addEventHandler
*	
*	Method to associate a function with an event type, handles adding event handers using the
*	browser specific event handler code.  
*		eventType is string name of event type without associated "on" prefix, 
*			for example "mouseover" and not "onmouseover".  
*		scopeObj is optional parameter for object reference that contains a method, "handler". 
*			Scope object is optional, if obmitted, the handler function is called as a global function.
*		handler parameter can be reference to a function object or string name of a method of the 
*			Scope object.  
*	The handler function will be passed the event object (both ie and dom) as the first parameter.
*	A reference to this Layer object will be passed to the handler function as the second parameter.
*	This method wraps the handler function, and enables two behavior types, first, if no scope
*	object is passed, the handler function runs as a stand alone function, and is passed the event
*	object reference and a reference to this layer object, if a scope object is passed, and the
*	handler is a string, it is called as a method of the scope object, and passed the same paramters.
*	
*/
function layer_addEventHandler(eventType,handler,scopeObj){
	//	Will cause the event handler to be added once layer is created
	this.setEventHandlerWrapper(eventType);
	
	//	Now save event handler in this object's event handlers collection
	
	if(!this.eventHandlers){
		this.eventHandlers=new Object();
		}
	if(!this.eventHandlers[eventType]){
		this.eventHandlers[eventType]=new Array();
		}
	//	Save handler and scope object
	this.eventHandlers[eventType].push({handler:handler,scopeObj:scopeObj});
	
}	//	addEventHandler


/**
*	setEventHandlerWrapper
*
*	Internal function used to register at least one event handler for 
*	each type of event added.
*/
function layer_setEventHandlerWrapper(type){
	
	if(!this.div){this.addInitProp("eventHandlerWrapper",type);return;}
	
	if(!this.eventHandlersRegistered){
		this.eventHandlersRegistered=new Object();
		}
	if(!this.eventHandlersRegistered[type]){
		if(this.ie4){
			this.div.attachEvent("on"+type,layer_receiveEvent);
			}
		else{
			this.div.addEventListener(type,layer_receiveEvent,false);
		}
		this.eventHandlersRegistered[type]=true;
		}
}	//	setEventHandlerWrapper


/**
*	propagateEvent
*
*	Internal function called by event handler if one is registered, 
*	used to wrap event handlers added.
*/
function layer_receiveEvent(event){
	//	Get reference to event object if ie and it wasn't passed
	if(!event){event=window.event};
	
	var target=(event.target?event.target:event.srcElement);
	
	if(target.tagName != "DIV"){
		//	target is object inside of this layer object, step up to find 
		//	parent div that is represented by this object.
		 target=stageelement_getParent(target,"DIV");
		}
	if(target.layerObj){target.layerObj.propagateEvent(event);}
	}
	
function layer_propagateEvent(event){
	var type=event.type;
	
	if(!this.eventHandlers||!this.eventHandlers[type]){
		this.log.error("The event " + type + " does not have event handlers registered in this layer.");
		return;
		}
	
	//	Call event handlers registered, pass reference to this layer
	var hand = this.eventHandlers[type];
	for(var i=0; i<hand.length; i++){
		if(hand[i].scopeObj&&(typeof hand[i].handler=="string")){
			hand[i].scopeObj[hand[i].handler](event,this);
			}
		else{hand[i].handler(event,this);}
		}
}	//	propagateEvent
	

/**
*	printProperties
*
*	Returns a string containting the current style and other properties of this 
*	object, if layer exists it gets the properties right from the layer, if not,
*	it creates a string of the current initProps.
*/
function layer_printProperties(){
	var showStr = "";
	
	if(!this.div){
		if(this.initProps){
			showStr = "(div not created) Properties:\n";
			for(var i=0; i<this.initProps.length; i++){showStr += this.initProps[i].key + "=" + this.initProps[i].value + "\n";}
			}
		}
	else {
		showStr = "div is " + this.div + " Properties:\n";
		for( var x = 0; x < this.div.attributes.length; x++ ) {
			if(!this.div.attributes[x].specified)continue;
			showStr += this.div.attributes[x].nodeName + "=" + this.div.attributes[x].nodeValue + "\n";
			}
		}
	return showStr;
	
}	//	printProperties

