$(document).ready(function() {
	$("#newyell").button();
		
	get_yellouts();
	
});


//parse comments
function parse_yells(comments)
{
	var htmlStr="&nbsp;";
	if(comments.length>0)
	{
		for (var i = 0; i < comments.length; i++) {
			  $eclass='';
			  if(comments[i].edit == true) $eclass="comment-row canedit";
			  
			  htmlStr += '<div id="c_'+ comments[i].cid +'"class="span-14 last append-bottom ' + $eclass + '">' +
							'<div class="span-3">'+
							'<a class="profile-link" title="View ' + comments[i].full_name + 
							'\'s Profile" href="/profile/view/'+comments[i].path +
							'"><img alt="'+comments[i].full_name+
							'" src="'+comments[i].pic +'" /></a>'+
							'</div>'+
							'<div class="span-10 last">'+
							  '<div class="span-10">' +
									'<a href="/profile/view/' + 
									comments[i].path +
									'"><strong>' +
									comments[i].full_name +
									'</strong></a>' +
								'</div>' + 
								'<div class="span-1 last hidden deletelink text-right">'+
									'<a href="#" id="'+ comments[i].id + 
									'" title="Delete this comment" class="delete-comment-button">' +
									'<span class="ui-icon ui-icon-circle-close" style="margin-right: 10px;"></span></a>' +
								'</div>' +
								'<div class="span-9 last">'+
									'<p class="comment-date">' + 
									comments[i].date + ' ago</p>' +
									comments[i].msg +
								'</div>' +
						  '</div>' + 		
						'</div> ';
		}
		
	}
	else
	{
		htmlStr = '<em>No comments - why don\'t you be the first to leave a comment.</em>';	
	}
	$('#yellouts').html(htmlStr);
	//set toottips for comments
	$('.profile-link').tipsy({fade: true, gravity: 'n'});	
}


//get yellouts
function get_yellouts()
{
		$.ajax({  
			type: "POST", 
			dataType: 'json',
			url: '/yellouts/get_yellouts/',  
			data: "",  
			success: function(data){ 
				parse_yells(data['message']);
			}, 
			error: function(data){  
				$('#yellouts').html("Loading YellOuts...");
			}, 
			
		}); //$.ajax
	
	setTimeout("get_yellouts()",(1 * 60 * 1000)); //re-check every 1 min 
}

