
//When Mouse Y coord is approach leaving the window (to go away)
$().mousemove(function(e){ 

	if (e.pageY<=10){
	
		var id = '#modal-dialog';
		var cookieName = 'fc-offer';

		
		//alert($.cookie(cookieName));

		//Launch on Window load (ready) if user hasn't seen it yet
		if($.cookie(cookieName)!=cookieName){
			launchWindow(id);
			$.cookie(cookieName, cookieName,{ path: '/' });
		}

		//Close if Close btn clicked
		$('.modal-window .modal-close').click(
			function () {
				hideWindow(id);
			}
		);		

	}

});


//Thank you the window
function thankyou(id){
	hideWindow(id);
	alert("CONGRATULATIONS!\nYou have been signed up for the offers requested and will recieve info shortly. Signup is now completed.");
}

//Hide the window
function hideWindow(id){
	$('#modal-mask').fadeOut(500);	
	$('.modal-window').hide();
}

//Launch (animate) the window
function launchWindow(id){
	
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set height and width to mask to fill up the whole screen
	$('#modal-mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#modal-mask').fadeIn(500);	
	$('#modal-mask').fadeTo("slow",0.85);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	//Dialog Dimensions
	var dialogH = $(id).height();
	var dialogW = $(id).width();
		  
	//Set the popup window to center
	$(id).css('top',  winH/2-dialogH/2);
	$(id).css('left', winW/2-dialogW/2);

	//transition effect
	$(id).fadeIn(2000); 
}