/*===========================================
   Ajax Tooltip
=========================================== */ 

   if( typeof FUEL == "undefined"  ) var FUEL = {};
   
   $(document).ready( function()
   {
      
      new FUEL.ajaxtip( 'a.ajaxtip',  { keep: false, sticky: true } );
      new FUEL.ajaxtip( 'a.ajaxtipkeep', { keep: true, hideout: true } );
      
   });
   
   FUEL.ajaxtip = function( classname, options )
   {
      var that = this;
      options = options || {};
      this.sticky = options.sticky || false;
      this.keep = options.keep || false;
      this.hideout = options.hideout || false;
      this.x = options.x || 15;
      this.y = options.y || 5;
      
      $(classname).click( function(){ return false; } );
      $(classname).mouseover( function(e){ that.create( this, e ); } );
      
      if( this.keep == false ) { $(classname).mouseout( function(){ FUEL.ajaxtip.close(); } ); }
      if( this.sticky ) { $(classname).mousemove( function(e){ that.set_position(e); } ); }
   };
   
   FUEL.ajaxtip.prototype =
   {
      create: function( that, e )
      {
         var url = $(that).attr('href');
         var offset = $(that).offset();
         var id = $(that).attr('class') + offset.left + offset.top;
         var box = $('<div id="'+id+'" class="ajax-tip ajax-tip-loading"><div class="ajax-tip-inside"></div></div>');
         
         if( $('#'+id).length == 0 )
         {
            FUEL.ajaxtip.close();
            $(box).appendTo("body");
            this.set_position(e);
            
            if( this.hideout )
            {
               $("div.ajax-tip").mouseover( function(){ $("div.ajax-tip").hover( function(){}, function(){ FUEL.ajaxtip.close(); } ) } );
            }
            
            $(box).load( url, function(r){ $("div.ajax-tip-loading").removeClass('ajax-tip-loading'); } );
         }
      },
      
      set_position: function(e) { $("div.ajax-tip").css( { top: (e.pageY-this.y)+"px", left: (e.pageX+this.x)+"px", position: 'absolute' } ); }
   };
   
   FUEL.ajaxtip.close = function()
   {
      $('div.ajax-tip').remove();
   };
