/**********************

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=180;
var exPopLimY=60;
var exPopInLim=50;
var exPopMaxDisplays=4;
var exPopCheckScroll=2;
var exPopSkips=3;

/*********************/

var exPopWentIn=0;
var exPopped=0;
var exPopTimesShown=0;
var exPopSinceLast=-1;
var exPopX, exPopY;
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))) {
		$('#subscribe_form_link1').click();
		exPopped=1;
		exPopTimesShown++;
	}
}
}
function exPopUnPop() {
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;
	}
}
}
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);
}

