
/** Event handler for mouse wheel event.
 */
function wheelPreprocessor(event)
{
	window.event = event;
	
	return eval(this.onmousewheel);
}

function translateMouseWheelDelta(event) {
	var delta = 0;
	if (!event) /* For IE. */
			event = window.event;
	if (event.wheelDelta) { /* IE/Opera. */
			delta = event.wheelDelta/120;
			/** In Opera 9, delta differs in sign as compared to IE.                */
			//if (window.opera) // in Opera 10 works exactly the same
			//		delta = -delta;
	} else if (event.detail) { /** Mozilla case. */
			/** In Mozilla, sign of delta is different than in IE.
			 * Also, delta is multiple of 3.
			 */
			delta = -event.detail/3;
	}
	return delta;	
}

/** Initialization code. 
 */
//window.onload = initMouseWheelSupport; // Initialize when page is fully loaded

function initMouseWheelSupport()
{
	try {
		assignWheelListener_rec(document);
	} catch(err) {
		alert("[initMouseWheelSupport] Exception occured:\n\n" + err);
	}
}

function assignWheelListener_rec(node)
{
	if (node.addEventListener) { // we have support for DOM events
		if (node.onmousewheel) return; // browser has native support for mouse wheel. or we already were here :)
		if (node.getAttribute) { // document and text have no this functions
			var code = node.getAttribute("onmousewheel");
			if (code) { // assigned something in HTML
				node.onmousewheel = code; // simple access
				node.addEventListener('DOMMouseScroll', wheelPreprocessor, false);
			}
		}
		for(var child = node.firstChild; child; child = child.nextSibling) {
			// verify children as well
			assignWheelListener_rec(child);
		}
	}
}
