var doc_root = '/';
var loadingContent = '<div class="loading"><div>Loading...</div></div>';

oComments = {

	add: function() {
		var $$ =this;
		name = $('#sendform input[name=auteur]').val();
		email = $('#sendform input[name=email]').val();
		url = $('#sendform input[name=siteweb]').val();
		msg = $('#sendform textarea[name=texte]').val();
		id = $('#sendform input[name=id]').val();
		var data = $("#sendform").serialize();
		oComments.load('comments.php?a=add&id='+id, data);
	},
 
	load: function(url, data) {
		$(".jqmdMSG", "#jqdialog").html(loadingContent);
		
		$.post(doc_root+url, data, function(data) {
			$(".jqmdMSG", "#jqdialog").empty().html(data);	
			$('#send_comment', "#jqdialog").click( oComments.add );
		}, 'html');
	}
}

jQuery(document).ready( function () {
	jQuery("#jqdialog").jqm({
		onShow: function(hash) {
			var h = hash;
			var id = $(h.t).attr('id').substr(9);
			h.w.show().jqDrag('.jqDrag');
			oComments.load('comments.php?&a=view&id='+id, {})/*
			$.get(doc_root+'comments.php?&a=view&id='+id,function (data) {
				//var html = '<div class="jqmdTC jqDrag">Comments</div><div class="jqmdBC"><div class="jqmdMSG">'+data+'</div></div><input type="image" src="dialog/close.gif" class="jqmdX jqmClose" />';
				$(".jqmdMSG", h.w).empty().html(data);			
				
		
				$('#send_comment', h.w).click( oComments.add );
	
			},'html');*/
		},
		modal:true,
		trigger:'a.comment'
	});
	
	
	$(document).keydown( function( e ) {
	
		if( e.which == 27) {  // escape, close box
			$("#jqdialog").jqmHide();
		}
	
	
	});
	
});

