﻿function Comments() {
  this.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();
	$(".jqmdMSG", "#jqdialog").html('Loading...');
        $.post('comments.php?a=add&id='+id, data, function(data) {
          $(".jqmdMSG", "#jqdialog").html(data);	
          $('#send_comment', "#jqdialog").click( c.add );
        }, 'html');
  }
}

var c = new Comments();

jQuery(document).ready( function () {
	jQuery("#jqdialog").jqm({ onShow: function(hash) {
		var h = hash;
		var id = $(h.t).attr('id').substr(9);
		$.get('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);			
			h.w.show().jqDrag('.jqDrag');
		
      $('#send_comment', h.w).click( c.add );
	
		},'html');
		
			
	}
	,modal:true,trigger:'a.comment'});
	
	
	$(document).keydown( function( e ) {
	
    if( e.which == 27) {  // escape, close box
      $("#jqdialog").jqmHide();
    }
	
	
});
	
});
