
/**********************

	ExPop 1.0.1
	On-Page Exit Popup Controller
	(c) Copyright 2007-8 Gecko Tribe, LLC
	All Rights Reserved
	by Antone Roundy

	*** THIS IS NOT FREE SOFTWARE ***

	Unauthorized copying and creating
	derivative code based on parts of this
	code are forbidden by copyright law.
	If you're going to use this script or
	any part of it, please do so legally
	and honestly by buying a copy at:

	http://www.geckotribe.com/expop/

	Resale of this script or derivative
	code is prohibited unless resale rights
	have been purchased from the copyright
	owner.  (Resale rights may not be
	available for purchase at this time).

	Thank you.  Your honesty makes it possible
	for me to take time from other work to
	create and support scripts like this.

**********************/



var exPopLimX=2000;
var exPopLimY=15;
var exPopInLim=50;
var exPopPopId='pop';
var exPopDimId='popdim';
var exPopMaxDisplays=1;

var exPopCheckScroll=2;
var exPopSkips=3;

/*********************/

var exPopWentIn=0;
var exPopped=0;
var exPopTimesShown=0;
var exPopSinceLast=-1;
var exPopX, exPopY,exPopDim,exPopPop;
var exPopTop=-1;
var exPopBrowser=-1;
var exPopDE=false;
var exPopIEMac=(navigator.userAgent.indexOf("Mac_")>-1)&&(navigator.userAgent.indexOf("MSIE")>-1);

function exPopPopIt(checkSkips) {
	var scrolled;
	var popIt=1;
	if (!exPopped) {
		if (checkSkips) {
			if ((exPopSinceLast==exPopSkips)||(exPopSinceLast==-1)) exPopSinceLast=0;
			else {
				exPopSinceLast++;
				exPopWentIn=0;
				popIt=0;
			}
		}
		if (popIt&&((!exPopMaxDisplays)||(exPopTimesShown<exPopMaxDisplays))) {
			exPopDim.style.display='block';
			if (!exPopBrowser)
				exPopDim.style.height=exPopDE.offsetHeight+exPopDE.scrollTop;
			exPopPop.style.display='block';
			if (exPopTop==-1) exPopTop=exPopPop.offsetTop;
			scrolled=exPopBrowser?exPopDE.pageYOffset:exPopDE.scrollTop;
			exPopPop.style.top=((exPopTop+scrolled)+'px');
			exPopped=1;
			exPopTimesShown++;
		}
	}
}
function exPopUnPop() {
	exPopPop.style.display='none';
	exPopDim.style.display='none';
	exPopped=exPopWentIn=0;
	if (exPopIEMac) {
		window.resizeBy(-1,0);
		window.resizeBy(1,0);
	}
}
function exPopGetPos(myE,checkScroll) {
	if (checkScroll) {
		if (exPopBrowser) {
			exPopX=myE.pageX;
			exPopY=myE.pageY;
		} else {
			exPopX=myE.clientX+exPopDE.scrollLeft;
			exPopY=myE.clientY+exPopDE.scrollTop;
		}
	} else {
		if (exPopBrowser) {
			exPopX=myE.pageX-exPopDE.pageXOffset;
			exPopY=myE.pageY-exPopDE.pageYOffset;
		} else {
			exPopX=myE.clientX;
			exPopY=myE.clientY;
		}
	}
}
function exPopCheck(ifMatch,X,Y) {
	return ((exPopY<Y)&&(exPopX<(X*2-(exPopY*X/Y))))?ifMatch:(1-ifMatch);
}
function exPopMonitor(e) {
	var myE;
	if (!exPopped) {
		if (e) myE=e;
		else if (window.event) myE=window.event;
		else myE=null;
		if (myE) {
			if (exPopBrowser==-1) exPopBrowser=(typeof(myE.pageX)=='number');
			if (exPopBrowser&&(/select|option|optiongroup/i.test(myE.target.tagName))) return true;
			if (exPopWentIn) {
				exPopGetPos(myE,exPopCheckScroll);
				if (exPopCheck(1,exPopLimX,exPopLimY)) exPopPopIt((exPopCheckScroll==2)?0:exPopSkips);
				else if (exPopCheckScroll==2) {
					exPopGetPos(myE,0);
					if (exPopCheck(1,exPopLimX,exPopLimY)) exPopPopIt(exPopSkips);
				}
			} else {
				exPopGetPos(myE,0);
				if (exPopCheck(0,exPopLimX+exPopInLim,exPopLimY+exPopInLim)) exPopWentIn=1;
			}
		}
	}
	return true;
}
function exPopInit() {
	if (typeof(window.innerWidth)=='number') exPopDE=window;
	else if (document.documentElement && (typeof(document.documentElement.clientWidth)=='number') &&
		(document.documentElement.clientWidth!=0)) exPopDE=document.documentElement;
	else if (document.body && typeof(document.body.clientWidth=='number')) exPopDE=document.body;
	if (exPopDE) {
		if (document.addEventListener) document.addEventListener('mousemove',exPopMonitor,true);
		else {
			if (typeof(document.all)=='undefined') document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove=exPopMonitor;
		}
	}
	exPopPop=document.getElementById(exPopPopId);
	exPopDim=document.getElementById(exPopDimId);
}
if (document.addEventListener) {
	if (/webkit|safari|khtml/i.test(navigator.userAgent)) {
		function exPopKHTMLInit() {
			/loaded|complete/.test(document.readyState)?exPopInit():setTimeout(exPopKHTMLInit,100);
		}
		exPopKHTMLInit();
	} else document.addEventListener("DOMContentLoaded", exPopInit, false);
} else if (window.attachEvent) window.attachEvent('onload',exPopInit);
else {
	function exPopWinOnLoad(f1,f2) {
		return function() {
			if (f1) f1();
			f2();	
		}
	}
	window.onload=exPopWinOnLoad(window.onload,exPopInit);
}


