$(document).ready(function() {
// var exp=readCookie('signup'); 		Error: Do not use 'exp' as a variable, since it is a reserved word in javascript.

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

//if((e.pageY <= 15)&&(!exp)) Error: the variable 'exp' is read only once, and 'exp' will always be null, since it only reads when loading the window, and although the cookie is created, not re-read.
if((e.pageY <= 15))
{
	var exp3=readCookie('signup'); //It reads the cookie to check the condition
	if (!exp3){	 //Shows the popup when the cookie is not set
		// Launch MODAL BOX
		$('#exit_content').modal({onOpen: modalOpen, onClose: simplemodal_close});
	}
}
});

});

/**
 * 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');
		});
	});
}

   /**
 * 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) {
//	saveIt('signup');
	dialog.data.fadeOut('fast', function () {
		dialog.container.hide('fast', function () {
			dialog.overlay.slideUp('fast', function () {				
                createCookie('signup','21',120);
				$.modal.close();
				
			});
		});
	});	
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else {var expires = "";}
			document.cookie = name+"="+value+expires+"; path=/";
}
