var exitpop_active = true;

function expandCollapse() 
{
	for (var i=0; i<expandCollapse.arguments.length; i++) 
	{
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

function exitpop_trigger(event) {
	
	if( exitpop_active ) {
		if( event.target == document || event.target == undefined) {
			//--- This was a window event; we can't STOP the user from
			//		leaving, but can open another window or the like.
			
			window.open("/offers/lyrisform.cfm?rswindow=0","mywindow","menubar=1,resizable=1,width=530,height=300");
		}else{
			//--- This was a link or form submission; we can stop it.
			//	...but we're not.
			
			//mywin = window.open("/offers/openclose.html","trackingwindow","menubar=0,resizable=0,width=1,height=1");
			//mywin.close();
			
			//-- disableoldga
			//urchinTracker('/metrics/offers/exitpop/view/inline/');
			
			expandCollapse('open','over');
			
			exitpop_active = false;
			return false;
		}
	}
}
function exitpop_clear() {
	exitpop_active = false;
}

/* --- Update all links/forms on the page to call the exitpop function --- */
$(function(){
	$(window).bind( "unload", exitpop_trigger );
	$("a[href]:not(.noexitpop):not([target])").bind( "click", exitpop_trigger );
	$("form").bind( "submit", exitpop_trigger );
});
