/*
  Javascript for shaking an object

  only one object can be shaken at the same time

  position of the object must be defined
*/


var shake = {

style:null, x:0, y:0, tnext:0, active:false, amplitude:2,

getms:function()
{
  var d = new Date();

  return d.getTime();
},

start:function(ID)
{
  this.style = document.getElementById(ID).style;

  this.x = parseInt(this.style.left);
  this.y = parseInt(this.style.top );

  this.active = true;

  this.amplitude = 2;

  this.tnext = this.getms();

  this.horizontal();
},

horizontal:function()
{
  if( this.active )
  {
    if( this.getms() < this.tnext ) return;

    this.amplitude = -this.amplitude;

    this.style.left = this.x + this.amplitude;

    setTimeout("shake.vertical()",50);

    this.tnext = this.getms() + 100;

    setTimeout("shake.horizontal()",100);
  }
},

vertical:function()
{
  if( this.active )
    this.style.top = this.y + this.amplitude;
},

stop:function()
{
  this.active = false;

  this.style.left = this.x;
  this.style.top  = this.y;
}
}

