if (!window.YUKU) var YUKU = {}

YUKU.graphicTrail = {
   num : 15,
   cur : 0,
   delay : 1000,
   space : 50,
   imgs : [],
   timeouts : [],
   x : 0,
   y : 0,

   init : function (imgs, delay, num, space)
   {
      this.imgs = imgs;
      this.delay = delay * 1000;
      this.num = num;
      this.space = space;

      for (i = 0; i < this.num; i++)
      {
         var src = this.imgs[i % this.imgs.length];
         var img = make_el('IMG', {src : src, id : 'trail-' + i, className : 'trail',
                           style : {position : 'absolute', zIndex : '999', display : 'none'}}, document.body);
         this.timeouts[i] = false;
      }

      addEvent(document, 'mousemove', YUKU.graphicTrail.move, false);
   },

   move : function (e)
   {
      var mouse = FindMouseXY(e);
      var me = YUKU.graphicTrail;

      if (mouse.x > (me.x + me.space) || mouse.x < (me.x - me.space) || mouse.y > (me.y + me.space) || mouse.y < (me.y - me.space))
      {
         me.show(mouse.x, mouse.y)
         me.x = mouse.x;
         me.y = mouse.y;
      }
   },

   show : function (x, y)
   {
      if (this.cur >= this.num)
         this.cur = 0;

      var trail = get_by_id('trail-' + this.cur);
      trail.style.left = x + 'px';
      trail.style.top = y + 'px';
      trail.style.display = 'inline';

      if (this.delay > 0)
      {
         if (this.timeouts[this.cur] != false)
            window.clearTimeout(this.timeouts[this.cur]);

         this.timeouts[this.cur] = window.setTimeout('YUKU.graphicTrail.hide(' + this.cur + ')', this.delay);
      }

      this.cur++;
   },

   hide : function (i)
   {
      get_by_id('trail-' + i).style.display = 'none';
      this.timeouts[i] = false;
   }
}