
function postComment(videoId) {
	var id = videoId.split("_")[1];
	var div = $( "#" + id);
	
	if ($(div).find(".author").val().length < 3 ) {
		$(div).find(".label_author").css("color","#f88d1f");
		$(div).find(".author").focus();
		return false;
	}
	$(div).find(".label_author").css("color","white");
	
	
	if ($(div).find(".message").val().length < 3 ) {
		$(div).find(".label_message").css("color","#f88d1f");
		$(div).find(".message").focus();
		return false;
	}
	$(div).find(".label_message").css("color","white");
	
	
	
	
	
	$.post("../app/iphone_comments/add", {  
				video_id: id, 
       			author: $(div).find(".author").val(), 
       			url: $(div).find(".url").val(), 
       			message: $(div).find(".message").val(),
			},
	function(data){
		$(div).find('.postBack').append(data);
		$(div).find('.postBack').fadeIn();
		$(div).find("form")[0].reset()
		$(div).find(".label_author").css("color","white");
		$(div).find(".label_message").css("color","white");		
	});	
}



function getThumbnail(postID,image,vid) {
	var id = postID.split("_")[1];
	var div = $( "#" + id);	
	var url = $("<embed width='100%' height='240px' src="+image+" href="+vid+" type='video/x-m4v' target='myself' scale='1' ...><div class='imgborder'><img src='../lib/img/imgborder.png'></div>");

	$(div).find('.thumbnail').empty();	
	$(div).find('.thumbnail').hide();	
	$(div).find('.thumbnail').append(url);
	$(div).find('.thumbnail').fadeIn("slow");								
}


function getComments(postID) {
	var id = postID.split("_")[1];
	var div = $( "#" + id);	
	
	var image = $(div).find(".thumbnail").attr("rel");
	var vid = $(div).find(".thumbnail").attr("vid");
	getThumbnail(postID,image, vid);
	
		
	$(div).find('.comments').hide();
	$.ajax({
	  url: "../app/iphone_comments/get/"+id,
	  cach: false,
	  success: function(html){
		$(div).find('.loadComments').hide();
		$(div).find('.comments').empty();
		$(div).find('.comments').append(html);
		$(div).find('.comments').fadeIn();
		}
	});	
}



$(document).ready(function(){
		
	$(".submit").click(function(){
		postComment($(this).attr("id"));
	});
	
	$("form").submit(function(){
		postComment($(this).attr("id"));
		return false;
	});
		
	$(".single").click(function(){
		getComments($(this).attr("id"));
	});	
	
	$(".url").focus(function(){
		$this.val("http://");
	});
	
});

