/*
============================================================
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this  header
*/


var mouseAlertFlag = false;
var mouseAlertInProcess = false;
var mouseAlertInterval = 0;
var mouseAlertIE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!mouseAlertIE) document.captureEvents(Event.MOUSEUP)

// Set-up to use getMouseXY function onMouseMove
document.onmouseup = captureXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function captureXY(e) {
	
	if (mouseAlertFlag){
		mouseAlertFlag = false;
		if (mouseAlertInProcess){
			clearTimeout(mouseAlertInterval);
		}
		mouseAlertInProcess = true;
		if (mouseAlertIE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
		} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
		}  
		// catch possible negative values in NS4
		if (tempX < 0){tempX = 0}
		if (tempY < 0){tempY = 0}

		popIcon = document.getElementById("mouseAlertPop");
		popIcon.className = "visibleMouseAlert";
		popIcon.style.top = Number(tempY-15)+"px";
		popIcon.style.left = Number(tempX-15)+"px";
		
		if (popIcon.filters) {
			try {
				popIcon.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				popIcon.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 100 + ')';
			}
		} else {
			popIcon.style.opacity = 1;
		}
		
		mouseAlertInterval = setTimeout("mouseAlertFadeOut(popIcon,100);",500);
	}
	
	return true;
}

function popMouseAlert(){
	mouseAlertFlag = true;
}

function popMouseAlertFromFlash(coordinates,divName){
	var containingDiv = document.getElementById(divName);
	popIcon = document.getElementById("mouseAlertPop");
	popIcon.className = "visibleMouseAlert";
	popIcon.style.top = (Number(containingDiv.style.top.substr(0,containingDiv.style.top.indexOf("p")))+Number(coordinates.y)-15) +"px";
	popIcon.style.left = "50%";
	popIcon.style.marginLeft = (Number(containingDiv.style.marginLeft.substr(0,containingDiv.style.marginLeft.indexOf("p")))+Number(coordinates.x) -15)+"px";
	debug("(containingDiv.style.top+coordinates.y -15) : "+(Number(containingDiv.style.top.substr(0,containingDiv.style.top.indexOf("p")))+Number(coordinates.y)-15));
	
	if (popIcon.filters) {
		try {
			popIcon.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
		} catch (e) {
			// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
			popIcon.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 100 + ')';
		}
	} else {
		popIcon.style.opacity = 1;
	}
	
	mouseAlertInterval = setTimeout("mouseAlertFadeOut(popIcon,100);",500);
	
	return true;
}

function mouseAlertFadeOut(element, opacity) {
	var reduceOpacityBy = 10;
	var rate = 30;	// 15 fps


	if (opacity > 0) {
		opacity -= reduceOpacityBy;
		if (opacity < 0) {
			opacity = 0;
		}

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity > 0) {
		mouseAlertInterval = setTimeout(function () {
			mouseAlertFadeOut(element, opacity);
		}, rate);
	} else {
		element.className = "hiddenMouseAlert";
		mouseAlertInProcess = false;
	}
}

