/*
 *
 * sitewide popup support
 */

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;
}

/*
 * used to trigger popup if the cookie wasn't set, and they click on another link 
 * before the 10 seconds popup timeout happens
 */

/* changing this to a splash page - popup immediately (or .5 seconds) 
 */

var popup_shown = 0;

jQuery(document).ready( function() { 

    if(readCookie('popAlreadyH1N1') != 1 ) {

          // set it to popup if they click on a momsrising link (showing their interest in the site)
	  // 
          jQuery('a').click(function() {
	        if (popup_shown) 
		     return true;
		do_popup();
		return false;
          });

	  // set timeout to show popup in 10 seconds if they are still on this page looking around
	  // and if they haven't clicked a link and done the popup already
          setTimeout(function() { 
     	      if (!popup_shown) 
	           do_popup();
	  }, 15000); 
    }
}); 

function do_popup() {
        //set cookie to expire in 60 days because we are doing the popup now! Don't want to do it again for 60 days.
	var date = new Date();
	var days = 60;
        date.setTime(date.getTime()+(days*24*60*60*1000));
        document.cookie = 'popAlreadyH1N1=1; expires='+date.toGMTString()+'; path=/';

	popup_shown = 1;
	// do the popup
    	tb_show("Stay Informed","http://www.momsrising.org/sitewide_popup/popup_wrapper.html?height=420&width=350", "");
}



