/*
  script to turn 9 weapon logos
*/

var weapons = {

image:new Array(), source:new Array("images/epee_new.jpg", "images/fleuret_new.jpg", "images/sabre_new.jpg"),

weaponId:new Array(), sideStyle:new Array(), amplitude:new Array(), pos:new Array(44, 98, 152, 206, 260, 314, 368, 422, 476), 

shift:new Array(0, 0, 0, 0, 0, 0, 0, 0, 0), number:new Array(0, 1, 2, 0, 1, 2, 0, 1, 2),

side:new Array(),


prepare:function()
{
  for(var i = 0; i < 3; i++)
  {
    this.image[i] = new Image();

    this.image[i].src = this.source[i];
  }
},

start:function()
{
  for(var i = 0; i < 26; i++)
  {
    var a = Math.round(25 * Math.cos(i * Math.PI / 50));

    var s = Math.round(3  * Math.sin(i * Math.PI / 50));

    this.amplitude[i] = a;

    this.side[i] = -a - s;
  }

  this.amplitude[26] = 0;
  this.amplitude[27] = 0;

  this.side[26] = -2;
  this.side[27] = -1;

  for(var i = 25, k = 28; i >= 0; i--, k++)
  {
    this.amplitude[k] = this.amplitude[i];

    this.side[k] = -this.side[i] - 3;
  }
  
  for(var i = 0; i < 9; i++)
  {
    this.weaponId[i]  = document.getElementById('weapon' + i); 

    this.sideStyle[i] = document.getElementById('side' + i).style; 
  }

  this.trigger();
},

trigger:function()
{
  for(var k = 0, time = 0; k < 9; k++, time += 150)
    setTimeout('weapons.move('+ k + ')',time);

  setTimeout('weapons.trigger()',3000);
},

move:function(k)
{
  this.shift[k] = ++this.shift[k] % 54;

  var p = this.pos[k];

  var a = this.amplitude[this.shift[k]];

  var s = this.side[this.shift[k]];

  this.weaponId[k].style.left  = p - a; 
  this.weaponId[k].style.width = a<<1; 

  this.sideStyle[k].left = p + s; 

  if(this.shift[k] == 25)
  {
    this.number[k] = ++this.number[k] % 3;

    this.weaponId[k].src = this.image[this.number[k]].src;
  }

  if(this.shift[k] < 53 )
    setTimeout('weapons.move('+ k + ')',20);
}
}

weapons.prepare();

