function init(){
  $A(document.getElementsByTagName('td')).each(function(node){
    node.onmouseover=function(){
      var r=Math.floor(Math.random()*255);
      var g=Math.floor(Math.random()*255);
      var b=Math.floor(Math.random()*255);
      node.style.backgroundColor='rgb('+r+','+g+','+b+')';
      if(node.getElementsByTagName('a').length!=0) node.getElementsByTagName('a')[0].style.color='rgb('+(255-r)+','+(255-g)+','+(255-b)+')';
      if(node.className!='noData') node.style.cursor="pointer";
    }
    node.onmouseout=function(){
      node.style.backgroundColor='rgb(255,255,255)';
      if(node.getElementsByTagName('a').length!=0) node.getElementsByTagName('a')[0].style.color='black';
      node.style.cursor="auto";
    }
  });
  new Effect.Appear('content',{ from:0, to:1 });
}

function rand(min,max){
  return Math.floor(min+Math.random()*(max-min+1));
}

function word(){
  var result='';
  var length=rand(2,10);
  for(var i=0;i<length;++i) result=result+'&#'+rand(0x61,0x79);
  return result;
}

function sentence(){
  var result='&#'+rand(0x41,0x5a);
  var length=rand(5,30);
  for(var i=0;i<length;++i){
    result=result+word();
    if(i!=length-1){
      if(Math.random()<0.1) result=result+', ';
      else result=result+' ';
    }
  }
  if(Math.random()<0.05) return result+'! ';
  if(Math.random()<0.05) return result+'? ';
  return result+'. ';
}

var msgCount=0;

function displayMessage(){
  var cycle=10;
  if(msgCount%cycle==1){
    $('message').innerHTML='';
    new Effect.Appear('message',{ from:0, to:1 });
  }
  if(msgCount%cycle==0){
    new Effect.Fade('message');
    msgCount++;
  }
  else{
    var newMsg=document.createElement('span');
    newMsg.id='message'+msgCount++;
    newMsg.style.opacity='0';
    newMsg.style.filter='alpha(opacity=0)';
    newMsg.innerHTML=sentence();
    $('message').appendChild(newMsg);
    new Effect.Appear(newMsg.id,{ from:0, to:1 });
  }
  setTimeout('displayMessage()',1500);
}

var attackCount=0;

function attack(){
  attackCount++;
  if(attackCount<3) new Effect.Shake('portrait');
  else{
    new Effect.Fade('content');
    //$('message').style.color='white';
    $('body').style.backgroundColor='red';
    //displayMessage();
  }
}
