
var isIE=document.all;
var isNN=!document.all&&document.getElementById;
var isN4=document.layers;

var leftClickHandler = "";
var rightClickHandler = "";
var mouseHandler = "";

// Install Right-Click Handler
function mouseClick(e) {
	var rightClick = false;
	var leftClick = false;
	
	if (!e) {
		// Capture Event If Necessary
		e = window.event;
	}
	
	if (isN4) {
		if (e.which==2||e.which==3) {
			rightClick = true;
		} else if (e.which==1) {
			leftClick = true;
		}
	} else if (isIE) {
		if (e.button==1) {
			leftClick = true;
		} else if (e.button==2) {
			rightClick = true;
		}
	} else if (isNN) {
		if (e.button==0) {
			leftClick=true;
		} else if (e.button==2) {
			rightClick=true;
		}
	}
	
	if ((leftClickHandler != "") && (leftClick)) {
		// Left Click
		eval(leftClickHandler);
		return false;
	} else if ((rightClickHandler != "") && (rightClick)) {
	    // Right Click
	    eval(rightClickHandler);
	    return false;
	}
	
	return true;
}

function mouseMove(e) {
	if (mouseHandler != "") {
		// Only Process If We Have An Action To Perform !
    	if (isN4) {
        	// When the page scrolls in Netscape, the event's mouse position
        	// reflects the absolute position on the screen. innerHight/Width
        	// is the position from the top/left of the screen that the user is
        	// looking at. pageX/YOffset is the amount that the user has
        	// scrolled into the page. So the values will be in relation to
        	// each other as the total offsets into the page, no matter if
        	// the user has scrolled or not.
        	xMousePos = e.pageX;
        	yMousePos = e.pageY;
        	xMousePosMax = window.innerWidth+window.pageXOffset;
	        yMousePosMax = window.innerHeight+window.pageYOffset;
    	} else if (isIE) {
        	// When the page scrolls in IE, the event's mouse position
        	// reflects the position from the top/left of the screen the
        	// user is looking at. scrollLeft/Top is the amount the user
        	// has scrolled into the page. clientWidth/Height is the height/
        	// width of the current page the user is looking at. So, to be
        	// consistent with Netscape (above), add the scroll offsets to
        	// both so we end up with an absolute value on the page, no
        	// matter if the user has scrolled or not.
        	
        	var scrolledx,scrolledy;

        	if (self.pageYOffset) // all except Explorer
        	{
				scrolledx = self.pageXOffset;
				scrolledy = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
			{
				scrolledx = document.documentElement.scrollLeft;
				scrolledy = document.documentElement.scrollTop;
			} else if (document.body) // all other Explorers
			{
				scrolledx = document.body.scrollLeft;
				scrolledy = document.body.scrollTop;
			}
        	
        	xMousePos = window.event.x+scrolledx;
        	yMousePos = window.event.y+scrolledy;
        	
        	xMousePosMax = document.body.clientWidth+scrolledx;
	        yMousePosMax = document.body.clientHeight+scrolledy;
    	} else if (isNN) {
        	// Netscape 6 behaves the same as Netscape 4 in this regard
        	xMousePos = e.pageX;
        	yMousePos = e.pageY;
        	xMousePosMax = window.innerWidth+window.pageXOffset;
    	    yMousePosMax = window.innerHeight+window.pageYOffset;
	    }
    	eval(mouseHandler);
    }
}


function registerLeftClickHandler(handler) {
	leftClickHandler = handler;
}

function registerRightClickHandler(handler) {
	rightClickHandler = handler;
}

function registerMouseHandler(handler) {
	mouseHandler = handler;
}



if (isIE||isNN) {
	document.oncontextmenu=mouseClick;
} else {
	document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP || Event.MOUSEMOVE);
}

document.onmousedown=mouseClick;
document.onmousemove=mouseMove;
