Ajax.RequestWithTransition = function(args) {
  var opts = {
    url: undefined,
    method: 'get',
    parameters: undefined,
    duration: 2,
    element: undefined,
    redirection: undefined,
    afterFinish: function() {},
    onRequestSuccess: function() {return false;},
    beforeChangeContent: function() {}
  }
 
  Object.extend(opts, args || { });
  
  if(opts.element != undefined && opts.url != undefined) {
    new Ajax.Request(args.url, {
      method: opts.method,
      parameters: opts.parameters,
      onSuccess: function(transport) {
        opts.onRequestSuccess();
        new Effect.Opacity(opts.element, {
          duration: (opts.duration / 2),
          from: 1.0,
          to: 0.0,
          afterFinish: function() {
            opts.beforeChangeContent();
            $(opts.element).innerHTML = transport.responseText;
            new Effect.Opacity(opts.element, {
              duration: (opts.duration / 2),
              from: 0.0,
              to: 1.0,
              afterFinish: opts.afterFinish            
            });
          }
        });
      },
      onFailure: function() {
        if(opts.redirection != undefined) document.location = opts.redirection;
      }
    });
  } else {alert('Utilisation incorrecte de la fonction Ajax.RequestWithTransition()');}
};

Ajax.RWT = Ajax.RequestWithTransition;
