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

YUKU.floatingImage = {
   timer : null,
   direction : 0,
   numImgs : 5,
   imgs : [],
   x : [],
   y : [],
   v : [],
   s : [],
   cs : [],

   init : function (imgs, direction, num)
   {
      this.imgs = imgs;
      this.direction = direction;
      this.numImgs = num;

      var holder = make_el('DIV', {id : 'move-holder',
                                   style : {position : 'absolute', top : '0px', left : '0px', zIndex : '999'}
                                  }, document.body);

      var inner = make_el('DIV', {id : 'move-inner', style : {position : 'relative'}}, holder);

      for (i = 0; i < this.numImgs; i++)
      {
         src = this.imgs[Math.floor(Math.random() * this.imgs.length)];

         var img = make_el('IMG', {src : src, id : 'si'+i,
                                   style : {position : 'absolute', top : '0px', left : '0px', zIndex : '999'}
                                  }, inner);
      }

      var win = window_size();

      for (i = 0; i < this.numImgs; i++)
      {
         this.y[i] = Math.round(Math.random() * win.y);
         this.x[i] = Math.round(Math.random() * win.x);
         this.v[i] = Math.random() * 5 + 3;
         this.cs[i] = 0;
         this.s[i] = Math.random() * 0.1 + 0.05;
      }

      if (this.direction != 0)
         this.timer = window.setInterval('YUKU.floatingImage.move()', 50);
      else
         this.timer = window.setInterval('YUKU.floatingImage.float()', 50);
   },

   move : function ()
   {
      var win = window_size();
      var scroll = FindScrollOffset();

      for (i = 0; i < this.numImgs; i++)
      {
         var el = get_by_id('si'+i);

         sy = this.v[i] * Math.sin(90 * Math.PI / 180);
         sx = this.v[i] * Math.cos(this.cs[i]);

         this.y[i] += (this.direction * sy);
         this.x[i] += (this.direction * sx);

         if (this.y[i] > win.y && this.direction == 1)
         {
            this.y[i] = -60;
            this.x[i] = Math.round(Math.random() * win.x);
            this.v[i] = Math.random() * 5 + 3;
         }

         if (this.y[i] < -el.offsetHeight && this.direction == -1)
         {
            this.y[i] = win.y;
            this.x[i] = Math.round(Math.random() * win.x);
            this.v[i] = Math.random() * 5 + 3;
         }

         el.style.left = Math.min(win.x, this.x[i]) + 'px';
         el.style.top = this.y[i] + scroll.y + 'px';

         this.cs[i] += this.s[i];
      }
   },

   float : function ()
   {
      var win = window_size();
      var scroll = FindScrollOffset();

      for (i = 0; i < this.numImgs; i++)
      {
         sy = this.v[i] * Math.sin(this.v[i] * this.cs[i] / 10);
         sx = this.v[i] * Math.cos(.33 * this.cs[i] / 2);

         this.y[i] += (1 * sy);
         this.x[i] += (1 * sx);

         if (this.y[i] > win.y || this.y[i] < 0)
         {
            this.y[i] = Math.round(Math.random() * win.y);
            this.x[i] = Math.round(Math.random() * win.x / 2);
            this.v[i] = Math.random() * 5 + 3;
         }

         if (this.x[i] > win.x || this.x[i] < 0)
         {
            this.y[i] = Math.round(Math.random() * win.y);
            this.x[i] = Math.round(Math.random() * win.x);
            this.v[i] = Math.random() * 5 + 2;
         }

         get_by_id('si'+i).style.left = Math.min(win.x, this.x[i]) + 'px';
         get_by_id('si'+i).style.top = this.y[i] + scroll.y + 'px';

         this.cs[i] += this.s[i];
      }
   },

   toggle : function ()
   {
      if (this.timer == null)
      {
         if (this.direction != 0)
            this.timer = window.setInterval('YUKU.floatingImage.move()', 50);
         else
            this.timer = window.setInterval('YUKU.floatingImage.float()', 50);
         get_by_id('move-holder').style.display = '';
      }
      else
      {
         window.clearInterval(this.timer);
         this.timer = null;
         get_by_id('move-holder').style.display = 'none';
      }
   }
}