function ZEvent(evt) {
	this.evt = evt ? evt : (window.event ?window.event:null); 
	if(this.evt!=null){
		this.source = this.evt.target ? this.evt.target : this.evt.srcElement;
		if (this.source.nodeType == 3 || this.source.nodeType == 4) // Safari bug
			this.source = this.source.parentNode;
		this.type = this.evt.type;
		if(this.type == 'mouseover')
			this.relatedTarget = this.evt.relatedTarget || this.evt.fromElement;
		else if(this.type == 'mouseout')
			this.relatedTarget = this.evt.relatedTarget || this.evt.toElement;
		else
			this.relatedTarget = null;
	}
}

ZEvent.prototype=ZEvent;

ZEvent.prototype.toString = function () {
	return "Evt [ source = " + this.source + ", type = " + this.type + " ]";
}

ZEvent.prototype.getMouseCoords= function(){
	return {x:this.evt.pageX ? this.evt.pageX : (this.evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft),
			y:this.evt.pageY ? this.evt.pageY : (this.evt.clientY + document.body.scrollTop + document.documentElement.scrollTop)};
}

ZEvent.prototype.getKeyCode = function(){
	return this.evt.keyCode?this.evt.keyCode:this.evt.which;
}

ZEvent.prototype.stopPropagation = function(){
	if(this.evt.stopPropagation)
		this.evt.stopPropagation();
	else
		this.evt.cancelBubble = true;
}

ZEvent.prototype.preventDefault = function(){
	if(this.evt.preventDefault)
		this.evt.preventDefault();
	else
		this.evt.returnValue  = false;
}

ZEvent.prototype.consume = function () {
	this.stopPropagation();
	this.preventDefault();
}

ZEvent.prototype.addEventListener = function (target,type,func,bubbles) {
	if (document.addEventListener) {
		target.addEventListener(type,func,bubbles);
	} else if (document.attachEvent) {
		target.attachEvent("on"+type,func,bubbles);
	} else {
		target["on"+type] = func;
	}
	return func;
}

ZEvent.prototype.removeEventListener = function (target,type,func,bubbles) {
	if (document.removeEventListener) {
		target.removeEventListener(type,func,bubbles);
	} else if (document.detachEvent) {
		target.detachEvent("on"+type,func,bubbles);
	} else {
		target["on"+type] = null;
	}
}

ZEvent.prototype.dispatchEvent = function(source,event_type,event){
	if(document.createEvent){
		var evtObj = document.createEvent(event_type);
		evtObj.initEvent( event, true, true );
	}
	else if(document.createEventObject) {
		var evtObj = document.createEventObject();
	}
	
	if(document.dispatchEvent)
		source.dispatchEvent(evtObj);
	else if(document.fireEvent)
		source.fireEvent("on"+event, evtObj);
}