
$(document).ready(function() {



	var launched=0;
	var max_launch=1;
	var updown=false;
	var dirIndex=0;
	var cYant;
	var mactive=false;

	$(document).mousemove(function(e) {

		if (!cYant) cYant=e.pageY;

		if(cYant > 50) mactive = true;

		cY=e.pageY;
		if (!cY) cY=e.clientY;
		dirIndex = cYant - cY;
		//updown=(dirIndex<=0)?false:true;
		//updown = true;
		
		dif=( (dirIndex>=1)|| (dirIndex<=-1) )?false:true;
		//dif=true;
		
		cYant=cY;

		if ( ( (e.pageY <= 10) || (e.clientY <= 10) )&&(launched < max_launch) && (mactive) )
		{
//			Launch MODAL BOX
			$('#exit_content').modal({onOpen: modalOpen, onClose: simplemodal_close});
//			alert ('prev: '+cYant+' actual:'+cY+' Index:'+dirIndex);
			launched=launched+1;
			updown=false;dif=false;					
		}

	});

});
/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
	dialog.overlay.fadeIn('fast', function () {
		dialog.container.fadeIn('fast', function () {
			dialog.data.hide().slideDown('fast');
		});
	});
	
	//$('iframe#glu').attr('src', '/promos/exit');
	
	$.post("/track", { 'aa':'POP-XM', 'context':'xm-home' },
	   		function(data){
	     		//alert(data);
	   		},
	   		'html'
   		);	
}

/**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * and data.
 */
function simplemodal_close (dialog) {
	dialog.data.fadeOut('fast', function () {
		dialog.container.hide('fast', function () {
			dialog.overlay.slideUp('fast', function () {
				$.modal.close();
			});
		});
	});
}



