// when the DOM is ready...
jQuery(document).ready(function () {

	launchPop();
});

function launchPop() {
	
	var maskHeight = jQuery(document).height();
	var maskWidth = jQuery(window).width();
	
	jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
	
	jQuery('#mask').fadeIn(500);
	jQuery('#mask').fadeTo("slow",0.6);
	
	var winH = jQuery(window).height();  
     var winW = jQuery(window).width();
     
	//Set the popup window to center  
	jQuery('#popup').css('top',  winH/2-jQuery('#popup').height()/2);  
	jQuery('#popup').css('left', winW/2-jQuery('#popup').width()/2);


	var a = [
        self.pageXOffset ||
        document.documentElement.scrollLeft ||
        document.body.scrollLeft
        ,
        self.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop
        ];
    jQuery(window).bind('scroll',{pos: a},scrollLock);

	
	jQuery('#popup').fadeIn(2000);
	
	jQuery('#popclose a').click(function() { jQuery(window).unbind('scroll',scrollLock); jQuery('#mask, #popup').fadeOut(250); });
	
}

function scrollLock(e) {
    var a=e.data.pos;
    window.scrollTo(a[0],a[1]);
    return false;
}

function popSubmit() {
	var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
	if (!email_re.test(jQuery('#pop_signup_email').val())) {
		alert("Please enter your email address.");
		jQuery('#pop_signup_email').focus();
		return false;
	}
	else {
		jQuery(window).unbind('scroll',scrollLock); jQuery('#mask, #popup').fadeOut(250);
		return true;
	}
}
