
jQuery.fn.extend({
  setDatasourceUrl: function(url, options) {
    var defaults = {
        url: url,
        busyClass: "ajaxActivity"
    };

    var opts = $.extend({}, defaults, options);

    //alert(opts.busySelector);
    return this.each(function() {
        this.opts = opts;
        //$(this).bind("onDataReceived", options.onDataReceived); // creates a datareceived event for the data object.
    });
  },
  refresh: function() {
       return this.each(function () {

            if (this.opts.busySelector) {



                $(this.opts.busySelector).removeClass(this.opts.busyClass);
                $(this.opts.busySelector).addClass(this.opts.busyClass);
            }
            $.ajax({
            			type: "GET",
            			url: this.opts.url,
            			options: this.opts,
            			e: this,
            			success: function(data) {
                			if ((this.options) && (this.options.busySelector)){
                			    $(this.options.busySelector).removeClass(this.options.busyClass);
            			    }
                			this.e.data = data;
                			$(this.e).trigger('onDataReceived', [data]);
            			},
            			dataType: 'json'
            		});
       })
  }
});


