/*
$(document).ready(function(){
	$.getJSON("http://www.knuckletown.com/api/loginStatus.php?jsoncall=?",function(data){
		$.each(data.info, function(i,data){
			if(data.islogin){
				$('#Login').css({visibility:'hidden'});
				$('#InsideInfoBar').show();
			}
			else{
				$('#InsideInfoBar').hide();
				$('#Login').css({visibility:'visible'});
			}
		}
	});
});
*/
$(function(){
	$(document).ready(function(){
		$.getJSON("http://www.knuckletown.com/api/loginStatus.php?jsoncall=?",function(data){
			$.each(data.info, function(i,data){				
				if(data.islogin){
					$('#Login').css({visibility:'hidden'});
					$('#InfoBar').show();
				}
				else{
					$('#InfoBar').hide();
					$('#Login').css({visibility:'visible'});
				}
			});
		});
		
		
		$('.tumblr_comment').each(function(i){
			comment_id = $(this).attr('comment_id');
			comment_element = 'tumblr_comment_'+comment_id;
			//num_comment = $('#'+comment_element).html();
			//$('#Footer').append(comment_element+":");

			$.getJSON("http://www.knuckletown.com/api/numOfComment.php?id="+comment_id+"&jsoncall=?",function(data){

				$.each(data.info, function(i,data){			
					//$('#Footer').append(data.numOfComment+":"+data.post_id);
					ele_id = data.post_id;
					ele_index = 'tumblr_comment_'+ele_id;
					if(data.numOfComment > 0){
						if(data.numOfComment > 1)
							addition = "s";
						else{
							addition = "";
						}
						$('#'+ele_index).html(data.numOfComment+" comment"+addition);
					}
					
				});

				//$('#Footer').append(comment_id+":");
			});
			
		});
	//return false;
	});
});

/* Blog Functions */
function addBlogComment(){
	var str = $('#addCommentForm').serialize();
	//alert(str);
	var comment = $('#addComment_textarea').val();
	if(comment){
		$.ajax({
			type: "POST",
		 	url: docRoot+"/blogs/addComment.php",
		 	data: str,
		 	success: function(msg){
		 		//alert( "Data Saved: " + msg );
		 		// If error
		 		if(msg == '0'){
					$('#addCommentFeedback').html('<span class="err">There is an error. Please try again.</span>');
				}
				else{
					//append the comment into DOM
					$("#Album_comment").append("<div id='Album_tempFeedback' class='ajaxFeedback'>Comment has been added</div>");
					$("#Album_comment").append(msg);
					$("#addComment_textarea").val("");
					$("#addCommentFeedback").val("");
				}
			}
	 });
	}
}
function blog_deleteComment(blog_id){
	$.ajax({
		type: "POST",
	 	url: docRoot+"/blogs/deleteComment.php",
	 	data: 'id='+blog_id,
	 	success: function(msg){
	 		//alert( "Data Saved: " + msg );
	 		// If error
	 		if(msg == '0'){
				dialog_main_feedback();
			}
			else{
				$('[id=Message_container_'+blog_id+']').remove();
			}
		}
	});
}
/*########################################*/
