/*
 * jQuery Ajax Link Plugin MODIFIED
 * version: 1.0.2 (10-NOV-2009)
 * @requires jQuery v1.2.2 or later
 * @Author Ernesto Chicas
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
;(function($){

  $(".ajaxlink").live("click", function(){
  
    var link = $(this);
  
    var options = {
        dataType  : "html",
        type      : "get",
        cache     : false,
        async     : true,
        beforeSend: false,
        complete  : false,
        error     : false,
        event     : "click",
        beforeSend: false,
        complete  : false,
        success   : false,
        error     : false
      };
      
      $.ajax({
          type     : options.type,
          url      : link.attr('href'),
          dataType : options.dataType,
          cache    : options.cache,
          async    : options.async,
          beforeSend  : function(){ 
                  if(options.beforeSend) options.beforeSend(); 
          },
          complete  : function(XMLHttpReq, textStatus){
                  if(options.complete) options.complete(XMLHttpReq, textStatus);
          },
          success    : function(data){
                  if(options.success){
                    options.success(data);
                  }
                  else{
                    var target = link.attr('target');
                    if (!target){
                      throw "No target";
                    }
                    target = $("#" + target);
                    if (target.length==0){
                      throw "No target found";
                    }
                    
                    target.html(data);
                  }
          },
          error    : function (event, request, settings){ 
                  if (options.error) options.error(event, request, settings); 
          }
        });
        return false;
  });
      
})(jQuery);
