//Copyright 2010 www.modstogo.com HS Facebook Style Newsfeed/Wall System
;(function($)
{
	var _sleeptimer;
	$.sleep = function( time2sleep, callback )
	{
		$.sleep._sleeptimer = time2sleep;
		$.sleep._cback = callback;
		$.sleep.timer = setInterval('$.sleep.count()', 1000);
	}
	$.extend ($.sleep, {
		current_i : 1,
		_sleeptimer : 0,
		_cback : null,
		timer : null,
		count : function()
		{
			if ( $.sleep.current_i === $.sleep._sleeptimer )
			{
				clearInterval($.sleep.timer);
				$.sleep._cback.call(this);
			}
			$.sleep.current_i++;
		}
	});
})(jQuery);
 
function update(){
		jQuery("#loading_container").show();
		ajaxpage('index.php?page=w_refresh', 'post_container')		
		jQuery("#loading_container").hide();		
		jQuery('#most_recent').html("Most Recent<span class='update_count' id='refresh' style='display:none'></span>");
}
function updatepro(per_id){
		jQuery("#loading_container").show();
		ajaxpage('/index.php?page=w_prorefresh&per_id='+per_id, 'wall_container')		
		jQuery("#loading_container").hide();				
}
jQuery(document).ready(function(){  
		jQuery(".comment_button").live('click', function(event){
				var element = jQuery(this);
				var I = element.attr("id");
				jQuery("#comment_"+I).show();
				
	});
	
});	
jQuery(document).ready(function(){  
jQuery("a#[id^='domore_']").live('focusin',function(event) { 
			jQuery(this).fancybox(
			 {
			'autoDimensions'	: false,
			'scrolling'			: 'auto',
			'width'         	: 400,
			'height'        	: 'auto'
			});
}); 
}); 
function check_posts(imem_id){ 	
		jQuery("div[id^='statuscontainer_']:first").each(function(){		
		var id = parseInt(this.id.replace("statuscontainer_", "")); 
		var mem_id = imem_id;
		var action = 'get_posts';
		jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "mem_id="+ mem_id +"& id="+ id +"& action="+ action,
				success: function(response){
				if(response == 0){
				jQuery('#most_recent').html("Most Recent<span class='update_count' id='refresh' style='display:none'></span>");
				}else{								
				jQuery('#most_recent').html(response);	
				//alert(id);
				};					
				}			
		});		
		return false;
	});	
}
jQuery(document).ready(function(){  
jQuery("a.geto_posts").live('click', function(event){
	jQuery("span[id^='olderPosts_']").each(function(){		
	var id = parseInt(this.id.replace("olderPosts_", ""));
	nid = id + 1;	
	jQuery("#more_loader").show();
	var total = jQuery("div[id^='statuscontainer_']").length;
	 if(total == 0){
	 jQuery('.no_more').show();				
	 jQuery('.no_more').delay(2000).fadeOut(2000);
	 jQuery("#more_loader").hide();
	 }else{
				jQuery("div[id^='statuscontainer_']:last").each(function(){ 
				var cid = parseInt(this.id.replace("statuscontainer_", ""));
				var action = "c_posts";				
			jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "cid="+ cid +"& action="+ action,
				success: function(response){
				if(response == 0){
				jQuery('.get_more').hide();
				jQuery('.no_more').show();				
				jQuery('.no_more').delay(2000).fadeOut(2000);
				jQuery('.get_more').replaceWith("<div class='get_more'><ul><span id='olderPosts_3' style='display:inline'><a class='geto_posts' href='javascript:void(0)'>Older Posts<img src='/img/pointer.png' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></a><span id='more_loader' style='display:none'><img src='/img/ajax-loader.gif' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></span></span></ul></div>");
									
				}else{
				jQuery('.get_more').html("<ul><span id='olderPosts_"+ nid +"' style='display:inline'><a class='geto_posts' href='javascript:void(0)'>Older Posts<img src='/img/pointer.png' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></a><span id='more_loader' style='display:show'><img src='/img/ajax-loader.gif' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></span></span></ul>");
				ajaxpage('/index.php?page=w_refresh&update='+nid, 'post_container')	
				jQuery("#more_loader").hide();
				};
				}
			  
			  });
		   });	
		 };//if
	  });
   });
});	
jQuery(document).ready(function(){ 
jQuery("a.geto_posts1").live('click', function(event){
	jQuery("span[id^='olderPosts_']").each(function(){		
	var id = parseInt(this.id.replace("olderPosts_", ""));
	var per_id = jQuery(this).attr('id').split('_')[2]; 
	nid = id + 1;	
	jQuery("#more_loader").show();
			jQuery("div[id^='statuscontainer_']:last").each(function(){ 
				var cid = parseInt(this.id.replace("statuscontainer_", ""));
				var action = "c_proposts";
				var total = jQuery("div[id^='statuscontainer_']").length;				
			jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "cid="+ cid +"& action="+ action +"&per_id="+ per_id,
				success: function(response){
				if(response == 0){
				jQuery('.get_more').hide();
				jQuery('.no_more').show();				
				jQuery('.no_more').delay(2000).fadeOut(2000);
				jQuery('.get_more').replaceWith("<div class='get_more'><ul><span id='olderPosts_2_"+per_id+"' style='display:inline'><a class='geto_posts1' href='javascript:void(0)'>Older Posts<img src='/img/pointer.png' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></a><span id='more_loader' style='display:none'><img src='/img/ajax-loader.gif' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></span></span></ul></div>");
				}else{
				jQuery('.get_more').html("<ul><span id='olderPosts_"+ nid +"_"+per_id+"' style='display:inline'><a class='geto_posts1' href='javascript:void(0)'>Older Posts<img src='/img/pointer.png' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></a><span id='more_loader' style='display:show'><img src='/img/ajax-loader.gif' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></span></span></ul>");
				ajaxpage('/index.php?page=w_prorefresh&per_id='+per_id+'&update='+nid, 'wall_container')	
				jQuery("#more_loader").hide();
				};
				}
			  
			  });
		   });	
	  });
   });
});
jQuery(document).ready(function(){  
jQuery("a.geto_posts2").live('click', function(event){
	jQuery("span[id^='olderPosts_']").each(function(){	
	var id = jQuery(this).attr('id').split('_')[1]; 
	var mem_id = jQuery(this).attr('id').split('_')[2]; 
	var per_id = jQuery(this).attr('id').split('_')[3]; 
	id = parseInt(id) + 1;	
	jQuery("#more_loader").show();
			jQuery("div[id^='statuscontainer_']:last").each(function(){ 
				var cid = parseInt(this.id.replace("statuscontainer_", ""));
				var action = "c_w2wposts";
				var total = jQuery("div[id^='statuscontainer_']").length;				
			jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "cid="+ cid +"& action="+ action +"& mem_id="+ mem_id +"& per_id="+ per_id,
				success: function(response){
				if(response == 0){
				jQuery('.get_more').hide();
				jQuery('.no_more').show();				
				jQuery('.no_more').delay(2000).fadeOut(2000);
				jQuery('.get_more').replaceWith("<div class='get_more'><ul><span id='olderPosts_1_"+mem_id+"_"+per_id+"' style='display:inline'><a class='geto_posts2' href='javascript:void(0)'>Older Posts<img src='/img/pointer.png' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></a><span id='more_loader' style='display:none'><img src='/img/ajax-loader.gif' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></span></span></ul></div>");
				}else{
				jQuery('.get_more').html("<ul><span id='olderPosts_"+ id +"_"+mem_id+"_"+per_id+"' style='display:inline'><a class='geto_posts2' href='javascript:void(0)'>Older Posts<img src='/img/pointer.png' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></a><span id='more_loader' style='display:show'><img src='/img/ajax-loader.gif' style='border:0px;margin:5px;' ALIGN=ABSMIDDLE></span></span></ul>");
				ajaxpage('/index.php?page=w2w_refresh&mem_id='+mem_id+'&per_id='+per_id+'&update='+id, 'w2w_container')	
				jQuery("#more_loader").hide();
				};
				}
			  
			  });
		   });	
	  });
   });
});	
jQuery(document).ready(function(){  
		jQuery(".clear_status").live('click', function(event){
			var per_id = parseInt(this.id.replace("clearStatus_", "")); 
			var action = "clear_status";
			jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "per_id="+ per_id +"& action="+ action,
				success: function(response){				
				jQuery('#headline').html(response);
				jQuery("#clearStatus_"+per_id).hide();					
				}			
			});	
			event.preventDefault();
			return false;
				
	});
	
});	
function scrollPost(){
		var total = jQuery("div[id^='statuscontainer_']").length;
		if(total == 16){
		jQuery("#more_loader").show();
		ajaxpage('/index.php?page=w_refresh&update=2', 'post_container')
		jQuery("#more_loader").hide();
		}else if(total == 28){
		jQuery("#more_loader").show();
		ajaxpage('/index.php?page=w_refresh&update=3', 'post_container')
		jQuery("#more_loader").hide();
		}		
}
jQuery(document).ready(function(){
	jQuery('a.refresh_click').live('click', function(event){
		jQuery("#loading_container").show();
		ajaxpage('/index.php?page=w_refresh', 'post_container')
		jQuery("#loading_container").hide();
		jQuery('#refresh').hide();
		
	});
});
jQuery(document).ready(function(){
	jQuery("form[id^='wallupdate_']").live('submit',function(event){	
		var id = parseInt(this.id.replace("wallupdate_", "")); 				
			var mem_id     = jQuery('#mem_id_' + id).attr('value');
			var per_id     = jQuery('#per_id_' + id).attr('value');
			var wal_id    = jQuery('#wal_id_' + id).attr('value');
			var pho_id    = jQuery('#pho_id_' + id).attr('value');
			var alb_id    = jQuery('#alb_id_' + id).attr('value');
			var wall_comment     = jQuery('#wall_comment_' + id).attr('value');
			var action     = jQuery('#action_' + id).attr('value');
			var act_id    = ('1');	
				jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "mem_id="+ mem_id +"& per_id="+ per_id +"& wal_id="+ wal_id +"& wall_comment="+ wall_comment +"& action="+ action +"& act_id="+ act_id +"& pho_id="+ pho_id +"& alb_id="+ alb_id,
				success: function(response){
				  jQuery('#wallupdate_' + id)[0].reset(); 
				 ajaxpage('index.php?page=w_refresh', 'post_container')
				}			
			});
			event.preventDefault();				 	
		}
	  );				
});
jQuery(document).ready(function(){
	jQuery("form[id^='wallupdate1_']").live('submit',function(event){	
		var id = parseInt(this.id.replace("wallupdate1_", "")); 				
			var mem_id     = jQuery('#mem_id_' + id).attr('value');
			var per_id     = jQuery('#per_id_' + id).attr('value');
			var wal_id    = jQuery('#wal_id_' + id).attr('value');
			var pho_id    = jQuery('#pho_id_' + id).attr('value');
			var alb_id    = jQuery('#alb_id_' + id).attr('value');
			var wall_comment     = jQuery('#wall_comment_' + id).attr('value');
			var action     = jQuery('#action_' + id).attr('value');
			var act_id    = ('1');	
				jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "mem_id="+ mem_id +"& per_id="+ per_id +"& wal_id="+ wal_id +"& wall_comment="+ wall_comment +"& action="+ action +"& act_id="+ act_id +"& pho_id="+ pho_id +"& alb_id="+ alb_id,
				success: function(response){
				  jQuery('#wallupdate1_' + id)[0].reset(); 
				 ajaxpage('/index.php?page=w_prorefresh&per_id='+per_id, 'wall_container')
				}			
			});
			event.preventDefault();				 	
		}
	  );				
});
jQuery(document).ready(function(){
	jQuery("form[id^='w2wupdate_']").live('submit',function(event){	
		var id = parseInt(this.id.replace("w2wupdate_", "")); 				
			var mem_id     = jQuery('#mem_id_' + id).attr('value');
			var owner_id     = jQuery('#owner_id_' + id).attr('value');
			var per_id     = jQuery('#per_id_' + id).attr('value');
			var wal_id    = jQuery('#wal_id_' + id).attr('value');			
			var wall_comment     = jQuery('#wall_comment_' + id).attr('value');
			var action     = jQuery('#action_' + id).attr('value');
			var act_id    = ('1');	
				jQuery.ajax({
				type: "POST",
				url: "/ajax/modify.php",
				data: "mem_id="+ mem_id +"& per_id="+ per_id +"& wal_id="+ wal_id +"& wall_comment="+ wall_comment +"& action="+ action +"& act_id="+ act_id,
				success: function(response){
				  jQuery('#w2wupdate_' + id)[0].reset(); 
				 ajaxpage('/index.php?page=w2w_refresh&mem_id='+owner_id+'&per_id='+per_id, 'w2w_container')
				}			
			});
			event.preventDefault();				 	
		}
	  );				
});
jQuery(document).ready(function(){  
		jQuery('a.remove_status').live('click', function(event){
		
		var wal_id = jQuery(this).attr('id').split('_')[1]; 
		var action     = ('remove_status');			
		jQuery.ajax({
			type: "POST",
			url: "/ajax/modify.php",
			data: "wal_id="+ wal_id +"& action="+ action,
			success: function(response){		
				 jQuery('#statuscontainer_' + wal_id).replaceWith(response);				
				 }	
			});	
		});
});	

jQuery(document).ready(function(){  
		jQuery('a.more_comments_link').live('click', function(event){
		
		var moreVal = jQuery(this).attr('id').split('_')[1]; 
		var pro = jQuery(this).attr('id').split('_')[2];
		var owner_id = jQuery(this).attr('id').split('_')[3];
		var other_id = jQuery(this).attr('id').split('_')[4];
		var action     = ('more_wcomments');	
		jQuery("#loading_" + moreVal).show();
		jQuery.ajax({
			type: "POST",
			url: "/ajax/modify.php",
			data: "moreVal="+ moreVal +"& action="+ action +"& pro="+ pro +"& owner_id="+ owner_id +"& other_id="+ other_id,
			success: function(response){				
				 jQuery('#CommentsContainer_' + moreVal).html(response);	
							 
				}	
			});	
		});
});	
jQuery(document).ready(function(){  
		jQuery('a.comment_like').live('click', function(event){
		
		var likeVal = jQuery(this).attr('id').split('_')[1]; 
		var action     = ('dolikes_wall');	
		var mem_id = jQuery(this).attr('id').split('_')[2];
		jQuery("#loadinglike_" + likeVal).show();
		jQuery.ajax({
			type: "POST",
			url: "/ajax/modify.php?action=" + action +new Date().getTime() ,
			data: "likeVal="+ likeVal +"& action="+ action +"& mem_id="+ mem_id,
			success: function(response){
				var s_response = response.split("|");
				jQuery('#like_' + likeVal + '_' + mem_id).text(s_response[0]);
				 jQuery('#LikesContainer_' + likeVal).html(s_response[1]);						
				}	
			});	
		});
});	
jQuery(document).ready(function(){  
jQuery("[id^='wall_comment_']").live('focusin focusout',function(e){ 
    var commentText = "Write a comment...", 
        id = this.id.replace('wall_comment_',''), 
        val = jQuery(this).val();    
    if (e.type == 'focusin'){ 
        val = (val == commentText) ? '' : val;  
        jQuery("#submit_"+id).show(); 
    } else if (e.type == 'focusout') { 
        val = (val == '') ? commentText : val;  
        if( val == commentText){  
            jQuery("#submit_"+id).hide();  
        } 
    } 
    jQuery(this).val(val); 
}).trigger('focusout'); 

});	
jQuery(document).ready(function(){  
jQuery('#comment').live('focusin focusout',function(e){ 
    var commentText = "What\'s on your mind?",         
        val = jQuery(this).val();    
    if (e.type == 'focusin'){ 
        val = (val == commentText) ? '' : val;  
        jQuery("#comment_but").show(); 
    } else if (e.type == 'focusout') { 
        val = (val == '') ? commentText : val;  
        if( val == commentText){  
            jQuery("#comment_but").hide();  
        } 
    } 
    jQuery(this).val(val); 
}).trigger('focusout'); 

}); 

jQuery(document).ready(function(){  
		jQuery('a.subdelete').live('click', function(event){
	
		var com_id = jQuery(this).attr('id').split('_')[1];
		var wal_id = jQuery(this).attr('id').split('_')[2];
		var mem_id = jQuery(this).attr('id').split('_')[3];	
		var action     = ('delete_comment');
		jQuery("#loading_" + wal_id).show();
		jQuery.ajax({
			type: "POST",
			url: "/ajax/modify.php?action=" + action,
			data: "wal_id="+ wal_id +"& mem_id="+ mem_id +"& com_id="+ com_id +"& action="+ action,
			success: function(response){				
				 ajaxpage('index.php?page=w_refresh', 'post_container')
				 							 
				}	
			});	
		}); 
});	
//comment delete for the profiles page
jQuery(document).ready(function(){  
		jQuery('a.subdelete1').live('click', function(event){
	
		var com_id = jQuery(this).attr('id').split('_')[1];
		var wal_id = jQuery(this).attr('id').split('_')[2];
		var mem_id = jQuery(this).attr('id').split('_')[3];
		var per_id = jQuery(this).attr('id').split('_')[4];
		var action     = ('delete_procomment');
		jQuery("#loading_" + wal_id).show();
		jQuery.ajax({
			type: "POST",
			url: "/ajax/modify.php?action=" + action,
			data: "wal_id="+ wal_id +"& mem_id="+ mem_id +"& com_id="+ com_id +"& action="+ action +"& per_id="+ per_id,
			success: function(response){				
				 ajaxpage('/index.php?page=w_prorefresh&per_id='+per_id, 'wall_container')
				 							 
				}	
			});	
		}); 
});	
//comment delete for the walltowall page
jQuery(document).ready(function(){  
		jQuery('a.subdelete2').live('click', function(event){
	
		var com_id = jQuery(this).attr('id').split('_')[1];
		var wal_id = jQuery(this).attr('id').split('_')[2];
		var mem_id = jQuery(this).attr('id').split('_')[3];
		var per_id = jQuery(this).attr('id').split('_')[4];
		var owner_id = jQuery(this).attr('id').split('_')[5];
		var other_id = jQuery(this).attr('id').split('_')[6];
		var action     = ('delete_procomment');
		jQuery("#loading_" + wal_id).show();
		jQuery.ajax({
			type: "POST",
			url: "/ajax/modify.php",
			data: "wal_id="+ wal_id +"& mem_id="+ mem_id +"& com_id="+ com_id +"& action="+ action +"& owner_id="+ owner_id +"& other_id="+ other_id,
			success: function(response){				
				 ajaxpage('/index.php?page=w2w_refresh&mem_id='+owner_id+'&per_id='+other_id, 'w2w_container')
				 							 
				}	
			});	
		}); 
});	
function checkInput()
{
  if ((document.getElementById('comment').value == '') || (document.getElementById('comment').value == 'What\'s on your mind?'))
  {
    alert('You must type a message first before posting.');
    return false;
  }  
}
function checkInputPro()
{
  if ((document.getElementById('procomment').value == '') || (document.getElementById('procomment').value == 'What\'s on your mind?') || (document.getElementById('procomment').value == 'Write something...'))
  {
    alert('You must type a message first before posting.');
    return false;
  }  
}
function checkInput2(wallid)
{
var wallcheck = ('wall_comment_' + wallid);
  if ((document.getElementById(wallcheck).value == 'Write a comment...') || (document.getElementById(wallcheck).value == ''))
  {
    alert('You must type a message first before posting.');
    return false;
  }  
}
function clear_form() {
document.submit_WallPost.reset(); 
}
function clear_form2() {
document.submit_ProPost.reset(); 
}

