    //requires jquery.ui core and jquery.ui.position


(function($){

	//Attach this new method to jQuery
 	$.fn.extend({

 		//This is where you write your plugin's name
 		ajaxicator: function(options) {
                     var defaults = {
                            indicatorPosition:'center center',
                            thisPosition:'center right',
                            extraClass: ''
                      };

                      var options = $.extend(defaults, options);

                      var uniqueId = '';
                      var $this = this;


                    this.getRandomNumber = function(range)
                    {
                            return Math.floor(Math.random() * range);
                    }

                    this.getRandomChar = function()
                    {
                            var chars = "0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
                            return chars.substr(this.getRandomNumber(62), 1 );
                    }

                    this.randomID = function()
                    {
                            var str = "";
                            for(var i = 0; i < 12; i++)
                            {
                                    str += this.getRandomChar();
                            }
                            return str;
                    }

                      return this.each(function() {
                          if($(this).attr('ajaxicator') == null)
                          {
                              
                              uniqueId = $this.randomID();
                              $(this).attr('ajaxicator',uniqueId);
                              $("body").append('<div class="ajaxicatorLoading '+options.extraClass+'" id="ajaxicatorLoad_'+uniqueId+'">asdasdadds</div>');
                              $("#ajaxicatorLoad_"+uniqueId).position({ my: options.indicatorPosition, at: options.thisPosition, of: this });
                              console.log($("#ajaxicatorLoad_"+uniqueId).css('top')+":"+$("#ajaxicatorLoad_"+uniqueId).css('left'))
                          }
                          else
                          {
                              var uniqueId = $(this).attr('ajaxicator');
                              $("#ajaxicatorLoad_"+uniqueId).remove();
                          }

                       });

                }
        });
})(jQuery);


