//===================================================================
// cross-platform event handling for IE5+, NS6+ and Mozilla/Gecko
// By Scott Andrew
function addEvent(elm, evType, fn, useCapture)
{
	if( elm.addEventListener ) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if( elm.attachEvent  ) {
		var r = elm.attachEvent('on' +evType, fn);
		EventCache.add(elm, evType, fn);
		return r;
	}
	else {
		elm['on' +evType] = fn;
	}
}

//===================================================================
function stopEvent(e)
{
	if( window.event ) {
		if( typeof(window.event.cancelBubble) == 'boolean') {
			window.event.cancelBubble = true;
		}
		if( typeof(window.event.returnValue) == 'boolean') {
			window.event.returnValue = false;
		}
		return;
		
	}
	if( e.stopPropagation ) {
		e.stopPropagation();
	}
	if( e.preventDefault ) {
		e.preventDefault();
	}
	return;
}

//===================================================================
function getWindowWidth()
{
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerWidth;
	}
	else if( document.documentElement && document.documentElement.clientWidth ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientWidth;
	} 
	return 0;
}
//===================================================================
function getWindowHeight()
{
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		return window.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientHeight;
	} 
}
//===================================================================
function getEvent(ev)
{
	return window.event ? window.event : ev;
}
//===================================================================
function getTarget(e, targetElement)
{
	return window.event ? targetElement : (e ? e.currentTarget : null);
}
//===================================================================
function mouseX(e)
{
	return e.clientX;
}
//===================================================================
function mouseY(e)
{
	return e.clientY;
}
//===================================================================
// returns true if button value matches specified W3C property
function buttonCheck(e,button)
{
	if( typeof(e.button) != 'number' )
		return false;
	if( window.event ) {
		button += 1;
	}
	return e.button == button;
}
//===================================================================
function debugMsg(txt, append) 
{
	var node = document.getElementById('debug');
	if( ! node ) return;
	node.firstChild.nodeValue = (append ? node.firstChild.nodeValue+' ' : '') + txt;
	node.style.display = 'block';
}
