/* $Id: api_dhtml.js,v 1.3 2003/12/10 11:38:27 olaf Exp $ */

	function class_layer( layerId ) {

		this.name = layerId;

		if ( browser.nav4 ) {
			this.object = eval( "document.layers." + layerId );
			this.css = this.object;
		}
		else if ( browser.ie4 ) {
			this.object = eval( "document.all." + layerId );
			this.css = this.object.style;
		}
		else {
			this.object = document.getElementById( layerId );
			this.css = this.object.style;
		}

		if ( browser.nav4 ) {
			this.css.width  = this.css.clip.width;
			this.css.height = this.css.clip.height;
		}
		else {
			this.css.left   = this.object.offsetLeft;
			this.css.top    = this.object.offsetTop;
			this.css.width  = this.object.offsetWidth;
			this.css.height = this.object.offsetHeight;
		}

		this.setClip = layer_setClip;
		this.hide  = layer_hide;
		this.show  = layer_show;
		this.write = layer_write;
		this.moveTo = layer_moveTo;

		this.appear = true;

//		alert(this.name + " " + this.css.width + " " + this.css.height);
		this.setClip( 0, this.css.width, this.css.height, 0 );

	}

	function layer_setClip( top, right, bottom, left ) {
		this.clipTop    = top;
		this.clipRight  = right;
		this.clipBottom = bottom;
		this.clipLeft   = left;
		if ( browser.nav4 ) {
			this.css.clip.top    = top;
			this.css.clip.right  = right;
			this.css.clip.bottom = bottom;
			this.css.clip.left   = left;
		}
		else this.css.clip = "rect(" + top + " " + right + " " + bottom + " " + left + ")";
	}

	function layer_hide() {
		this.css.visibility = ( browser.nav4 )? "hide" : "hidden";
	}

	function layer_show() {
		this.css.visibility = ( browser.nav4 )? "show" : "visible";
	}

	function layer_write( text ) {
		if ( browser.nav4 ) {
			this.object.document.open( "text/html", "replace" );
			this.object.document.write( text );
			this.object.document.close();
		}
		else this.object.innerHTML = text;
	}

	function layer_moveTo( x, y ) {
		this.css.left = x;
		this.css.top  = y;
	}



	function testCoordinates( object ) {
		if (	( eController.mouseX >= parseInt(object.left) )
			&&	( eController.mouseY >= parseInt(object.top) )
			&&	( eController.mouseX <= ( parseInt(object.left) + parseInt(object.width) ) )
			&&	( eController.mouseY <= ( parseInt(object.top) + parseInt(object.height) ) )
			) return true;
		return false;
	}

	function controlLoop() {
		if ( eController.listenerId != -1 ) {
			var object = eController.eventListeners[eController.listenerId];
			if ( testCoordinates( object ) ) {
				if ( object.mouseOver ) {
					if (	( eController.mouseX != eController.last_mouseX )
						||	( eController.mouseY != eController.last_mouseY )
						) {
						eController.last_mouseX = eController.mouseX;
						eController.last_mouseY = eController.mouseY;
						object.actualize( "rolling", eController.mouseX, eController.mouseY );
						object.tellObject( "rolling", eController.mouseX, eController.mouseY );
					}
					else {
						object.actualize( "still", eController.mouseX, eController.mouseY );
						object.tellObject( "still", eController.mouseX, eController.mouseY );
					}
				}
				else {
					object.mouseOver = true;
					object.actualize( "mouseover", eController.mouseX, eController.mouseY );
					object.tellObject( "mouseover", eController.mouseX, eController.mouseY );
				}
			}
			else {
				if ( object.mouseOver ) {
					object.mouseOver = false;
					object.actualize( "mouseout", eController.mouseX, eController.mouseY );
					object.tellObject( "mouseout", eController.mouseX, eController.mouseY );
				}
				else {
					object.actualize( "out", eController.mouseX, eController.mouseY );
					object.tellObject( "out", eController.mouseX, eController.mouseY );
				}
				if ( !object.mouseDown ) {
					eController.listenerId = -1;
				}
			}
		}
		else {
			if (
					( eController.last_mouseX != eController.mouseX )
				||	( eController.last_mouseY != eController.mouseY )
				) {
				for ( var i=0; i<eController.eventListeners.length && eController.listenerId==-1; i++ ) {
					var object = eController.eventListeners[i];
						eController.last_mouseX = eController.mouseX;
						eController.last_mouseY = eController.mouseY;
					if ( testCoordinates( object ) ) {
						eController.listenerId = i;
						eController.last_mouseX = eController.mouseX;
						eController.last_mouseY = eController.mouseY;
						object.mouseOver = true;
						object.actualize( "mouseover", eController.mouseX, eController.mouseY );
						object.tellObject( "mouseover", eController.mouseX, eController.mouseY );
					}
				}
			}
		}
		eController.controlLoop = setTimeout( "controlLoop();", 25 );
	}

	function class_eController() {

		eController = this;

		this.mouseX       = -1;
		this.mouseY       = -1;
		this.mouseScreenX = -1;
		this.mouseScreenY = -1;
		this.mouseDown    = false;

		this.last_mouseX = -1;
		this.last_mouseY = -1;

		this.eventListeners = new Array();
			this.addListener = eController_addListener;
		this.listenerId = -1;

		if ( browser.nav4 ) document.captureEvents( Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP );
		document.onmousemove = event_mousemove;
		document.onmousedown = event_mousedown;
		document.onmouseup   = event_mouseup;
		document.ondragstart = function() { window.event.returnValue = false; };
		document.onselectstart = doNotSelect;

		controlLoop();
	}

	function doNotSelect() {
//		if ( event.srcElement.type != "text") {
//		if ( o_scrollBar.actionType == "drag" )
			window.event.returnValue = false;
//		}
//		}
	}

	function eController_addListener( objectHandler ) {
		this.eventListeners[this.eventListeners.length] = objectHandler;
	}

	function event_mousemove( e ) {
		if ( !e ) var e = event;
		if ( browser.nav4 ) {
			eController.mouseX = e.pageX;
			eController.mouseY = e.pageY;
		}
		else {
			eController.mouseX = e.clientX + document.body.scrollLeft;
			eController.mouseY = e.clientY + document.body.scrollTop;
		}
		eController.mouseScreenX = e.screenX;
		eController.mouseScreenY = e.screenY;
	}

	function event_mouseup(e) {
		if ( !e ) var e = event;
		if ( e.type == "mouseup" ) {
			eController.mouseDown = false;
			if ( eController.listenerId != -1 ) {
				var object = eController.eventListeners[eController.listenerId];
				if ( object.mouseDown ) {
					object.mouseDown = false;
					object.actualize( "up", eController.mouseX, eController.mouseY );
					object.tellObject( "up", eController.mouseX, eController.mouseY );
				}
			}
		}
	}

	function event_mousedown( e ) {
		if ( !e ) var e = event;
		if ( e.type == "mousedown" ) {
			if ( browser.nav4 ) {
				if ( e.which == 3 ) return false;
			}
			else {
				if ( e.button==2 || e.button==3 ) return false;
			}
			eController.mouseDown = true;
			if ( eController.listenerId != -1 ) {
				var object = eController.eventListeners[eController.listenerId];
					object.mouseDown = true;
					object.actualize( "down", eController.mouseX, eController.mouseY );
					object.tellObject( "down", eController.mouseX, eController.mouseY );
			}
		}
	}

// -----------------------------------------------------------------------------------------------------------------------

	function defaultInitialize( layerId ) {
		this.name = layerId;
		this.obj = this;

		this.layers = new Array();
			this.l_main = new class_layer( layerId );
			this.layers[0] = this.l_main;

		this.left   = parseInt(this.l_main.css.left);
		this.top    = parseInt(this.l_main.css.top);
		this.width  = parseInt(this.l_main.css.width);
		this.height = parseInt(this.l_main.css.height);

		this.moveTo = dynamic_moveTo;
		this.show   = dynamic_show;
		this.hide   = dynamic_hide;
		this.appear  = true;
		this.enabled = true;

		this.addToListeners = function( functionName ) {
			if ( arguments.length != 0 ) this.tellObject = eval( functionName );
			else this.tellObject = function() {};
			eController.addListener( this );
		}

		this.mouseDown = false;
		this.mouseOver = false;
	}

	function dynamic_moveTo( x, y ) {
		x -= this.left;
		y -= this.top;
		this.left += x;
		this.top  += y;
		for ( i=0; i<this.layers.length; i++ ) {
			this.layers[i].css.left = parseInt(this.layers[i].css.left) + x;
			this.layers[i].css.top = parseInt(this.layers[i].css.top) + y;
		}
	}

	function dynamic_show() {
		for ( i=0; i<this.layers.length; i++ ) if ( this.layers[i].appear ) this.layers[i].show();
		this.appear = true;
	}

	function dynamic_hide() {
		for ( i=0; i<this.layers.length; i++ ) this.layers[i].hide();
		this.appear = false;
	}

