 $(function(){
  $(document).ready(function($){
    // Intialize PrettyPhoto
    $("a[rel^='prettyPhoto']").prettyPhoto({overlay_gallery:true, show_title:false, deeplinking:false, social_tools:false});
    
    //Popup Subscribe
    var subscribe=getCookie('subscribe');
    if (subscribe == "" || subscribe == null) {
      setCookie('subscribe','1',1);
      $.prettyPhoto.open('http://www.childrensministry.com/subscribe-popup?iframe=true&width=320&height=230','','');
    };

    
    // Lazy Load Images
    $("img").lazyload({
      placeholder : "/images/lazyload.gif",
      effect : "fadeIn",
      threshold : 5
    });

  });  
}); 


function setCookie(c_name,value,exdays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

