//<script type="text/javascript">

//=============================================================================
function debug(txt, bClear)
{
	if ( !debug.div ) {
		debug.div = $('debug');
	}
	if ( bClear || (debug.div.innerHTML.length == 0) ) {
		debug.div.innerHTML = txt;
	} else {
		debug.div.innerHTML += '<br>' + txt;
	}
}
debug.div == null;

function debugObj(o, depth, tab)
{
	if ( !tab ) tab = '';
	var mytab = tab + '&nbsp;&nbsp;&nbsp;'
	debug(tab + '{');
	for ( var i in o )
	{
		if ( !Browser.ie && (typeof(i) == 'string') )
		{
			if ( i.substr(0,4) == 'DOM_' ) continue;
		}
		if ( typeof(o[i]) == 'function' ) continue;
		if (i == 'innerHTML') continue;
		if (i == 'outerHTML') continue;		
		if ( depth && typeof(o[i]) == 'object' ) {
			debug( mytab + i + ':');
			debugObj(o[i], depth - 1, mytab);
		} else {
			debug( mytab + i + ':' + o[i]);
		}
	}
	debug(tab + '}');
}

//=============================================================================
// convenience function to access an HTML element by ID
function $(id)
{
	return document.getElementById(id);
}

//=============================================================================
// Function extensions
Function.prototype.bindEvent = function(object) {
	var method = this;

	return function(evt) { method.call(object, evt ? evt : window.event); }
}

Function.prototype.bind = function(object) {
	var self = this;

	return function() { self.apply(object, arguments); }
}

//=============================================================================
// JavaScript inheritance

var JSX = {
	Class: {
		// root class to all JSFC classes
		Object: null,
		
		// create a new class
		create: function(definition) {
			var i;
			var name = definition.name;
			var c = definition.constructor;
			var base = definition.base;
			var statics = definition.statics;
			var members = definition.members;
			
			if ( !name ) {
				throw "JSX Class must have a name";
			}
			if ( !c ) {
				throw "JSX Class must have a constructor";
			}
				
			// assign prototype for inheritance
			if (!base) { base = this.Object; }
			var f = new Function("return 0;");
			f.prototype = base.prototype;
			f.prototype.constructor = base;
			var p = new f();
			p.baseClass = base;
			p.constructor = c;

			// copy statics to class
			if (statics) {
				for(i in statics) {
					c[i] = statics[i];
				}
			}

			// copy class members to prototype
			if (members) {
				for(i in members) {
					p[i] = members[i];
				}
			}

			// assign 'class' to name
			p[name] = c;

			// assign class name
			p.className = name;

			c.prototype = p;
			return c;
		}
	}
};

JSX.Class.Object = JSX.Class.create({
	name: 'Object',
	constructor: function(){},
	base: Object
});

//=============================================================================
// Browser detection
var Browser = {
	mac: null,
	ie: null,
	macie: null,
	ns4: null,
	op5: null,
	op6: null,

	init: function() {
		var agt = navigator.userAgent.toLowerCase();
		
		this.mac = (agt.indexOf("mac") != -1);
		this.ie = (agt.indexOf("msie") != -1);
		this.macie = this.mac && this.ie;
		this.ns4 = document.layers;
		this.op5 = (navigator.userAgent.indexOf("Opera 5") != -1) || (navigator.userAgent.indexOf("Opera/5") != -1);
		this.op6 = (navigator.userAgent.indexOf("Opera 6") != -1) || (navigator.userAgent.indexOf("Opera/6") != -1);
	}
}

Browser.init();

//=============================================================================
// DHTML based functions

var DHTML = JSX.Class.create({
	name: 'DHTML',
	constructor: function(){},
	members: {
		getElementRight: function() {
			return this.getElementLeft(elt) + this.getElementWidth(elt);
		},
		getElementBottom: function() {
			return this.getElementTop(elt) + this.getElementHeight(elt);
		}
	}
});

DHTML.IE = JSX.Class.create({
	name: 'IE',
	constructor: function(){},
	base: DHTML,
	members: {
		cancelEvent: function(evt) {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		},

		getElementLeft: function(elt) {
			return elt.offsetLeft;
		},

		getElementTop: function(elt) {
			return elt.offsetTop;
		},

		getElementHeight: function(elt) {
			return elt.offsetHeight;
		},

		getElementWidth: function(elt) {
			return elt.offsetWidth;
		},

		getScrollPos: function() {
			return {
				left:document.body.scrollLeft, 
				top:document.body.scrollTop
			};
		},

		getElementPosition: function (elt) {
			var offsetLeft = 0;
			var offsetTop = 0;
			while (elt) {
				offsetLeft += elt.offsetLeft + elt.clientLeft;
				offsetTop += elt.offsetTop + elt.clientTop;
				elt = elt.offsetParent;
			}
			if (navigator.userAgent.indexOf("Mac") != -1 &&
				typeof document.body.leftMargin != "undefined") {
				offsetLeft += document.body.leftMargin;
				offsetTop += document.body.topMargin;
			}
			return {left:offsetLeft, top:offsetTop};
		}
	}
});

DHTML.Moz = JSX.Class.create({
	name: 'Moz',
	constructor: function(){},
	base: DHTML,
	members: {
		cancelEvent: function(evt) {
			if ( evt.stopPropagation ) {
				evt.stopPropagation();
			}
		},

		getElementLeft: function(elt) {
			return (typeof elt.offsetLeft != 'undefined' ? elt.offsetLeft : elt.style.pixelLeft);
		},

		getElementTop: function(elt) {
			return (typeof elt.offsetTop != 'undefined' ? elt.offsetTop : elt.style.pixelTop);
		},

		getElementHeight: function(elt) {
			return (typeof elt.offsetHeight != 'undefined' ? elt.offsetHeight : elt.style.pixelHeight);
		},

		getElementWidth: function(elt) {
			return (typeof elt.offsetWidth != 'undefined' ? elt.offsetWidth : elt.style.pixelWidth);
		},

		getScrollPos: function() {
			return {
				left: (document.documentElement.scrollLeft ?
					document.documentElement.scrollLeft :
					document.body.scrollLeft),
				top: (document.documentElement.scrollTop ?
					document.documentElement.scrollTop :
					document.body.scrollTop)
			};
		},

		parseBorder: function(borderStyle) {
			if ( borderStyle == '' ) return 0;
			var n = parseInt(borderStyle);
			if ( isNaN(n) ) return 0;
			return n;
		},

		getElementPosition: function(elt) {
			var offsetLeft = 0;
			var offsetTop = 0;
			while (elt) {			
				if ( elt.offsetLeft > 0 ) offsetLeft += elt.offsetLeft;
				if ( elt.offsetTop > 0 ) offsetTop += elt.offsetTop;

				offsetLeft += this.parseBorder(elt.style.borderLeft);
				offsetTop += this.parseBorder(elt.style.borderTop);
				elt = elt.offsetParent;
			}
			if (navigator.userAgent.indexOf("Mac") != -1 && 
				typeof document.body.leftMargin != "undefined") {
				offsetLeft += document.body.leftMargin;
				offsetTop += document.body.topMargin;
			}
			return {left:offsetLeft, top:offsetTop};
		}
	}
});


var dhtml = Browser.ie ? new DHTML.IE() : new DHTML.Moz();

//</script>