
var GeneralEvents = {

	_inited: false,
	_cursor_move_listeners: new Array(),
	_page_scroll_listeners: new Array(),

	/**
	*	Initialization
	*/
	init: function() {
		var self = GeneralEvents;

		if (self._inited) return;
		self._inited = true;

		// Cursor capturing
		if (nav) document.captureEvents(Event.MOUSEMOVE);
		if (n_6) document.addEventListener("mousemove", GeneralEvents._cursorCapture, true);
		if (nav || iex) document.onmousemove = GeneralEvents._cursorCapture;

		// Scroll capturing
		if (!old) setInterval("GeneralEvents._scrollCapture()", 20);
	},

	/**
	*	Cursor moving capturing
	*/
	_cursorCapture: function (e) {
		var self = GeneralEvents;
		var cursor_x, cursor_y;

		e = e || window.event;

		// Get cursor position
		if (e.pageX || e.pageY) {
			cursor_x = e.pageX;
			cursor_y = e.pageY;
		} else {
			var de = document.documentElement;
			var b = document.body;
			cursor_x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
			cursor_y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	    }

	    // Call event listeners
	    for (var i = 0; i < GeneralEvents._cursor_move_listeners.length; i++) {
			GeneralEvents._cursor_move_listeners[i](cursor_x, cursor_y);
	    }
	},

	/**
	*	Page scrolling capturing
	*/
	_scrollCapture: function() {
		var self = GeneralEvents;

		var scroll_x = (document.all) ? document.body.scrollLeft : window.pageXOffset;
		var scroll_y = (document.all) ? document.body.scrollTop : window.pageYOffset;

		// Call event listeners
	    for (var i = 0; i < GeneralEvents._page_scroll_listeners.length; i++) {
			GeneralEvents._page_scroll_listeners[i](scroll_x, scroll_y);
	    }
	},

	/**
	*	Cursor moving event listener adding
	*/
	addCursorMoveEventListener: function(callback_function) {
		var self = GeneralEvents;

		if (!self._inited) return;

		this._cursor_move_listeners.push(callback_function);
	},

	/**
	*	Page scrolling event listener adding
	*/
	addPageScrollEventListener: function(callback_function) {
		var self = GeneralEvents;

		if (!self._inited) return;

		this._page_scroll_listeners.push(callback_function);
	}
};
