$(document).ready(function() 
{
	// delete comment
	function stcommentdelete_trigger()
	{
		$('.stcommentdelete').unbind('click').click(function() 
		{
			var ID = $(this).attr("id").replace('stcommentdelete','');
			var dataString = 'com_id='+ ID+'&lang='+I6.lang;

			if(confirm(I6.msg.sur_supprimer_miseajour))
			{

				$.ajax(
				{
					type: "POST",
					url: "pages/wall/delete_comment_ajax.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
						$("#stcommentbody"+ID).slideUp();
					}
				});
			}
		});
	}
	
	function stdelete_trigger()
	{
		// delete update
		$('.stdelete').unbind('click').click(function() 
		{
			var ID = $(this).attr("id").replace('stdelete','');
			var dataString = 'msg_id='+ ID+'&lang='+I6.lang;

			if(confirm(I6.msg.sur_supprimer_message))
			{
				$.ajax(
				{
					type: "POST",
					url: "pages/wall/delete_message_ajax.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
						$("#stbody"+ID).slideUp();
					}
				});
			}
		});
	}

	function comment_button_trigger()
	{
		//commment Submint

		$('.comment_button').unbind('click').click(function() 
		{
			var ID = $(this).attr("id").replace('submit','');

			var comment= $("#ctextarea"+ID).val();
			var dataString = 'comment='+ comment + '&msg_id=' + ID+'&lang='+I6.lang;

			if(comment=='')
			{
				alert(I6.msg.entrer_texte);
			}
			else
			{
				$.ajax(
				{
					type: "POST",
					url: "pages/wall/comment_ajax.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
						$("#commentload"+ID).append(html);
						$("#ctextarea"+ID).val('');
						$("#ctextarea"+ID).focus();
						stcommentdelete_trigger();
					}
				});
			}
			return false;
		});
	}
	
	function commentopen_trigger()
	{
		// commentopen 
		$('.commentopen').unbind('click').click(function() 
		{
			var ID = $(this).attr("id").replace('commentopen','');
			$("#commentbox"+ID).slideToggle('slow',function()
			{
				comment_button_trigger();
			});
		});
	}
	
	// Update Status
	$(".update_button").click(function() 
	{
		var updateval = $("#update").val();
		var dataString = 'update='+ updateval+'&lang='+I6.lang;
		if(updateval=='')
		{
			alert(I6.msg.entrer_texte);
		}
		else
		{
			$("#flash").show();
			$("#flash").fadeIn(400).html(I6.msg.chargement_maj);
			$.ajax(
			{
				type: "POST",
				url: "pages/wall/message_ajax.php",
				data: dataString,
				cache: false,
				success: function(html)
				{
					$("#flash").fadeOut('slow');
					$("#wallcontent").prepend(html);
					$("#update").val('');	
					$("#update").focus();
					$("#stexpand").oembed(updateval);
					stdelete_trigger();
					commentopen_trigger();
				}
			});
		}
		return false;
	});
	
	stcommentdelete_trigger();
	stdelete_trigger();
	comment_button_trigger();
	commentopen_trigger();
});

(function($){
	$.fn.ReplaceByUploadForm = function()
	{
		return this.each(function()
		{
			$(this).parent().html('<form method="post" enctype="multipart/form-data"><input type="file" class="update_button bg_btn" name="thumb_profil" /><input type="submit" class="update_button bg_btn" value="'+I6.msg.envoyer+'" /></form>');
		});
	}
})(jQuery);
