$(function() {
	
			windowsize = window.innerWidth; //Get browser size for slide overs
			setTimeout(scrollTo, 0, 0, 1); //Hide nav bar in mobile safari

			
			
			$('#selected-item').hide();
			$('#sub-selected-item').hide();
			$('#PrayerFormHolder').hide();
			
			
			$("#header .logo a").live("click", function() { 
				
			});
			
			
			
			$('#PayerRequestBtn').live("click", function() { 
				
				$('#selected-item').append($('#PrayerFormHolder'));
				$('#PrayerFormHolder').show();
				$('#selected-item').show();
				setTimeout(scrollTo, 0, 0, 1);
				$('#prayers-page').animate({left: '-'+windowsize},400);
				return false;
			});
			
			
			$("#nav ul li a").live("click", function() { 
				var url = $(this).attr('href');
				$(this).ajaxSend(function() {
					$('#loading-box').show();
				});
				$(this).ajaxSuccess(function() {
					$('#loading-box').hide();
					$(this).unbind("ajaxSend");
				});
				$('#site-container').load(url);
				return false;
			});
			
			$("#header .times a").live("click", function() {
				var url = $(this).attr('href');
				
				(function() {
					$(this).addClass('loading');
				});
				
				$(this).ajaxStop(function() {
					$(this).removeClass('loading');
					$(this).unbind("ajaxSend");
				});
				$('#selected-item .content').load(url, function() {
					$('#selected-item').show();
					setTimeout(scrollTo, 0, 0, 1);
					$('#main-page').animate({left: '-'+windowsize},400);
				});
				return false;
			});
			
			$('.content ul li a.ajax-link').live("click", function() { 
																   
				var url = $(this).attr('href');
				
				(function() {
					$(this).addClass('loading');
				});
				
				$(this).ajaxStop(function() {
					$(this).removeClass('loading');
					$(this).unbind("ajaxSend");
				});
				$('#selected-item .content').load(url, function() {
					$('#selected-item').show();
					setTimeout(scrollTo, 0, 0, 1);
					$('#main-page').animate({left: '-'+windowsize},400);
				});
				return false;
			});
			
			
			
			
			$("a.prayed").each(
				function(e){
					if($.cookie($(this).attr("id")) == "PrayersPrayed"){
						$(this).addClass("prayedfor");	
					}
			});
				
				
			$("a.prayed").live("click",
				function(e){
					if($(this).hasClass("prayedfor")){
						return false
					}
					
					var url = $(this).attr('href');
					var id = $(this).attr('id').replace("Prayed_", '');
					
					
					
					$.ajax({
					  type: 'POST',
					  url: url,
					  success: function(data) {
									
									$(this).addClass("prayedfor");
									$.cookie($(this).attr("id"),"PrayersPrayed",  { path: '/', expires: 1 });
									var countID = "#count_"+id;
									var prayedID = "#Prayed_"+id + " span";
									var count = parseInt($(countID).html());
									$(countID).html(count + 1);
									$(prayedID).html("Prayed");
									$(prayedID).addClass("prayedfor");
								  },
						complete:function(){return false;}
					});
					
					
					
					return false;
		 
			});
			
			
			
			$('#selected-item a.back').live("click", function() {
				$('#main-page').animate({left: '+='+windowsize},400, function() {
					$('#selected-item').hide();
				});
				$('#prayers-page').animate({left: '+='+windowsize},400, function() {
					$('#selected-item').hide();
				});
				$('#sermons-page').animate({left: '+='+windowsize},400, function() {
					$('#selected-item').hide();
				});
				return false;
			});
			
			$('#sub-selected-item a.back').live("click", function() { // Return to sub page
				$('#selected-item').animate({left: '+='+windowsize},400, function() {
					$('#sub-selected-item').hide();
				});
				return false;
			});
			
			
			
			
			
			$("#main-page .content a.moreprayers").live("click",function(){ // Load more prayers to list
				var a=$(this).attr("href");
				var d=$(this).attr("title");
				$(this).ajaxSend(function(){
					$(this).parent(".more-prayers-link").addClass("loading")
				});
				$("#main-page .content #more-prayers"+d).load(a,function(){});
				return false
			});
			

		

			
});

jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

