//###############################################################################
// set up the popup window attributes
//---------------------------------------------------------------------------------------------------------------
// this.contentPath		=		Location of the content to be loaded. Content is loaded in an iFrame, so you can specify anything
// this.width					=		Width of the inside of the window
// this.height					=		Height of the inside of the window
//	this.setCookie			=		If set to TRUE it will generate a cookie which will prevent it from loading next time
// this.cookieId				=		Change this number to generate a new cookie
//###############################################################################
var exitPopup = new function(){ 
	this.contentPath = "http://www.casinospieleonline.eu/exitPop.asp";
	this.width = 740;
	this.height = 390;
	this.setCookie = true;
	this.cookieId = 0;
}

//###############################################################################
// document is ready, bind events
//###############################################################################
var mouse = new function () { this.x = 0, this.y = 0; this.hY = new Array(); this.movingUp = false; this.exitNetHT = false; };
$(document).ready( function(){ bindExitPop(); });

//###############################################################################
// bind the exit popup to the page
//###############################################################################
function bindExitPop(){
if (getExitPopCookie() == "true") return;
$('head').append('<style type="text/css">'+
	'#exitPopBody{font-family:verdana;font-size:10px;width:100%;position:fixed;top:0px;left:0px;z-index:0;}'+
	'#exitPopBody #exitPopWashout{display:none;position:fixed;background:#000;opacity:0.8;height:100%;width:100%;top:0;left:0;z-index:0}' + 
	'#exitPopBody #exitPopNet{height:10px;width:100%;position:fixed;top:0;left:0;z-index:99998}' + 
	'#exitPopBody #exitPopWindowOuter{position:absolute;top:50%;left:50%;z-index:99999}' + 
	'#exitPopBody #exitPopWindow{display:none;width:1;height:1;position:relative;left:-50%;top:-50%;}' +
	'#exitPopBody #exitPopClose{position:absolute;right:-12px;top:-12px;width:24px;height:24px;background:transparent url(/images/closeButton.png) no-repeat 0 0;_background-image:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/closeButton.png\',sizingMethod=\'scale\');cursor:pointer;z-index:2}' + 
	'#exitPopBody #exitPopClose:hover{background-position:0 -24px}' + 
	'#exitPopBody #exitPopClose:active{background-position:0 -48px}#exitPopBody #exitPopContent{position:relative;background:#EEE url(loader.gif) no-repeat center center;border:2px solid #FFF;z-index:1;overflow:hidden}#exitPopBody #exitPopFrame{display:none;border:0;margin:0;padding:0}' + 
	'</style>');
	
$('body').append(
'<div id="exitPopBody">' +
'<div id="exitPopNet"></div>' +
'<div id="exitPopWashout"></div>' +
'<div id="exitPopWindowOuter">' +
'<div id="exitPopWindow">' +
'<div id="exitPopClose"></div>' +
'<div id="exitPopContent">' +
'<iframe id="exitPopFrame" height="' + exitPopup.height + '" width="' + exitPopup.width + '" src="' + exitPopup.contentPath + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe>' +
'</div>' +
'</div>' +
'</div>' +
'</div>'
);
$('#exitPopWindowOuter').height(exitPopup.height);
$('#exitPopWindow').height(exitPopup.height);
$('#exitPopWindow').width(exitPopup.width);
$('#exitPopContent').height(exitPopup.height);
$('#exitPopContent').width(exitPopup.width);
$('#exitPopFrame').load( function(){ $(this).css('display', 'block'); $('#exitPopContent').css('background', '#EEE'); } );
$('#exitPopClose').click( function(){ closeExitPop(); } );
$('#exitPopNet').mouseenter( function(e) { mouse.exitNetHT = true; } );
$('#exitPopNet').mouseleave( function(e) { if (!mouse.movingUp) mouse.exitNetHT = false; } );
$(document).mousemove( function(e){ exitPopMouseMove(e); } );
$(document).mouseleave( function(){ exitPopMouseLeave(); } );
}
//###############################################################################
// unbind the exit popup
//###############################################################################
function unbindExitPop(){
exitPopMouseMove = function () { return null; };
exitPopMouseLeave = function () { return null; };
$('#exitPopNet').unbind();
$('#exitPopNet').remove();
}
//###############################################################################
// fired when the mouse moves on the page
//###############################################################################
function exitPopMouseMove(e){
	mouse.x = e.clientX;
	mouse.y = e.clientY;
	mouse.hY.push(mouse.y);
	if (mouse.hY.length > 10) mouse.hY.shift();
	var upCount = 0; var lastVal = 0;
	for(var i = 0; i < mouse.hY.length; i++){ lastVal = mouse.hY[i]; if (lastVal > mouse.hY[i + 1]) upCount++; }
	if (upCount > (mouse.hY.length / 2)){ mouse.movingUp = true; $('#exitPopNet').css('display', 'block'); } else { mouse.movingUp = false; $('#exitPopNet').css('display', 'block'); }
	$('#washout').css('display', 'none');
	
	var nh = 10;
	if (mouse.movingUp) nh = 10 + Math.abs(mouse.hY[mouse.hY.length - 1] - mouse.hY[0]);
	
	$('#exitPopNet').height(nh); 
	$('#exitPopBody').height(nh);
}
//###############################################################################
// function fired when the mouse leaves the page
//###############################################################################
function exitPopMouseLeave(){
if (!mouse.movingUp) return;
if (!mouse.exitNetHT){ $('#exitPopNet').height(10); return; }
unbindExitPop();
showExitPop();
}
//###############################################################################
// show the exit popup
//###############################################################################
function showExitPop() {
$('#exitPopBody').css('z-index', '999999');
$('#exitPopBody').css('height', '100%');
$('#exitPopWashout').css('display', 'block');
$('#exitPopWindow').fadeIn(500);
}
//###############################################################################
// close the exit popup
//###############################################################################
function closeExitPop(){
if (exitPopup.setCookie == true) setExitPopCookie();
$('#exitPopBody').css('z-index', '0');
$('#exitPopClose').fadeOut(150);
$('#exitPopWindow').slideUp(250);
$('#exitPopBody').delay(100).fadeOut(400, function(){ $(this).remove(); });
}
//###############################################################################
// set the cookie for the exit popup
//###############################################################################
function setExitPopCookie(){
var exdays = 360;
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape("true") + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = 'exitpopfired_' + exitPopup.cookieId +'=' + c_value;
}
//###############################################################################
// get the cookie for the exit popup
//###############################################################################
function getExitPopCookie(){
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == "exitpopfired_" + exitPopup.cookieId) return unescape(y);
}
}
