var loopInterval = 0;
var splashInterval = 0;
var allowSplash = true;
var ie = false;
var windowX = 0;
var windowY = 0;

if (navigator.appName == "Microsoft Internet Explorer"){
	windowX = window.screenLeft;
	windowY = window.screenTop;
	ie = true;
}
else {
	windowX = window.screenX;
	windowY = window.screenY;
}

$(document).ready(function() {
	$('body').bind('mouseleave', function(){
		loopInterval = setInterval(checkWindowPos, 200);
	});
	$('body').bind('mouseenter', function(){
		clearInterval(loopInterval);
	});
});
function checkWindowPos() {
	if(!ie) var dist = Math.round(Math.sqrt((Math.abs(windowX-window.screenX)*Math.abs(windowX-window.screenX))+(Math.abs(windowY-window.screenY)*Math.abs(windowY-window.screenY))));
	
	else var dist = Math.round(Math.sqrt((Math.abs(windowX-window.screenLeft)*Math.abs(windowX-window.screenLeft))+(Math.abs(windowY-window.screenTop)*Math.abs(windowY-window.screenTop))));
	
	if(dist > 80) splash();
	
	if(!ie) {
		windowX = window.screenX;
		windowY = window.screenY;
	}
	else {
		windowX = window.screenLeft;
		windowY = window.screenTop;
	}
}
function splash() {
	if(allowSplash) {
		var flashMovie = getFlashMovieObject("meter");
		flashMovie.splash();
		splashInterval = setInterval(setAllowSplash, 5000);
		allowSplash = false;
	}
}
function setAllowSplash() {
	clearInterval(splashInterval);
	allowSplash = true;
}
function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
	}
	else {
		return document.getElementById(movieName);
	}
}
