window.copyProperties = function(u,v)
{
	for (var k in v)
	{
		u[k] = v[k];
	}
	if (v.hasOwnProperty && v.hasOwnProperty('toString') && (v.toString !== undefined) && (u.toString !== v.toString))
	{
		u.toString = v.toString;
	}
	return u;
}

gt = function(id)
{
	var element = document.getElementById(id);
	return element;
}
window.bind = window.bind || function(obj,method)
{
	var args = [];
	for (var ii = 2; ii < arguments.length; ii++)
	{
		args.push(arguments[ii]);
	}
	return function()
	{
		var _obj = obj || this;
		var _args = args.slice();
		for (var jj = 0; jj < arguments.length; jj++)
		{
			_args.push(arguments[jj]);
		}
		if (typeof(method) == "string")
		{
			if (_obj[method])
			{
				return _obj[method].apply(_obj,_args);
			}
		}
		else
		{
			return method.apply(_obj,_args);
		}
	}
};


function EventController(eventResponderObject)
{
	copyProperties(this,{queue:[],ready:false,responder:eventResponderObject});
}

copyProperties(EventController.prototype,
{
	startQueue:function()
	{
		this.ready = true;
		this.dispatchEvents();
		return this;
	},
	pauseQueue:function()
	{
		this.ready = false;
		return this;
	},
	addEvent:function(event)
	{
		if (event.toLowerCase() !== event)
		{
			//		Util.warn('Event name %q contains uppercase letters; events should be lowercase.',event);
		}
		var args = [];
		for (var ii = 1; ii < arguments.length; ii++)
		{
			args.push(arguments[ii]);
		}
		this.queue.push({type:event,args:args});

		if (this.ready)
		{
			this.dispatchEvents();
		}
		return false;
	},
	dispatchEvents:function()
	{
		/*if (!this.responder)
	 {
		 Util.error('Event controller attempting to dispatch events with no responder! ' + 'Provide a responder when constructing the controller.');
	 }*/
		for (var ii = 0; ii < this.queue.length; ii++)
		{
			var evtName = 'on' + this.queue[ii].type;
			if (typeof(this.responder[evtName]) != 'function' && typeof(this.responder[evtName]) != 'null')
			{
				/*Util.warn('Event responder is unable to respond to %q event! Implement a %q ' + 'method. Note that method names are case sensitive; use lower case '
								+ 'when defining events and event handlers.',this.queue[ii].type,evtName);*/
			}
			else
			{
				if (this.responder[evtName])
				{
					this.responder[evtName].apply(this.responder,this.queue[ii].args);
				}
			}
		}
		this.queue = [];
	}
}
	);


var Util = {
	debug:function(template,obj)
	{
		var debugSection = null;
		if (debugSection = document.getElementById('debugSection'))
		{
			var processOutput = TrimPath.parseTemplate(template).process(obj);
			var div = document.createElement("div");
			div.innerHTML = processOutput;
			debugSection.appendChild(div);
		}
	},
	getEvent:function(e)
	{
		var targ;
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
		return targ;
	},
	isNull:function(e)
	{
		return e != null;
	},
	toString:function(e) {
		if(!e) return "";
		
		var string = '{';
		for(m in e) {
			string = string + m + '=' + e[m] + ',<br>';
		}
		return string + "}";
	}
};

function extend(child,superClass)
{
	for (var property in superClass.prototype)
	{
		if (typeof child.prototype[property] == "undefined")
			child.prototype[property] = superClass.prototype[property];
	}
	return child;
}
