// MATRIX BACKGROUND ANIMATION
// By: BRIAN GOSSELIN OF http://scriptasylum.com
// V1.0
// Permission granted to use this script in your webpage provided the
// credit remain intact.

// Modified by R2-D2 to use text and layout differently


if(anim==animOff)
{
  document.write('<div style="position:absolute; right:5; bottom:5"><tt><a href="javascript:animate(1)">run</a></tt></div>');
}
else
{
  document.write('<div style="position:absolute; right:5; bottom:5;"><tt><a href="javascript:animate(0)">nop</a></tt></div>');

  //GLYPH IMAGE FILE NAMES.
  var glyphs=['addiu', 'addu ', 'and  ', 'andi ', 'beq  ', 'beql ', 'bgez ', 'bgezl', 'bgtz ', 'bgtzl', 'blez ', 'blezl', 'bltz ', 'bltzl', 'bne  ', 'bnel ', 'div  ', 'divu ', 'jal  ', 'jalr ', 'jr   ', 'lb   ', 'lbu  ', 'lh   ', 'lhu  ', 'lui  ', 'lw   ', 'mfhi ', 'mflo ', 'move ', 'mthi ', 'mtlo ', 'mult ', 'multu', 'nor  ', 'or   ', 'ori  ', 'sb   ', 'sh   ', 'sll  ', 'sllv ', 'slt  ', 'slti ', 'sltiu', 'sltu ', 'sra  ', 'srav ', 'srl  ', 'srlv ', 'subu ', 'sw   ', 'xor  ', 'xori ', 'nop  '];
  //var glyphs=['nop  '];

  var glyphCount=250;      // TOTAL NUMBER OF GLYPHS.
  var scrollSpeed=60;      // SPEED OF ANIMATION
  var glyphH=18;           // GLYPH IMAGE WIDTH AND HEIGHT.
  var glyphW=75;           // GLYPH IMAGE WIDTH AND HEIGHT.
  var disableColors=false; // SET TO true TO DISABLE THE "BRIGHTER" IMAGES (BETTER PREFORMANCE). SET TO false TO ENABLE THEM.

  //************ DO NOT EDIT BEYOND HERE *************\\

  var w3c=(document.getElementById)?true:false;
  var ns4=(document.layers)?true:false;
  var ie4=(document.all && !w3c)?true:false;
  var ie5=(document.all && w3c)?true:false;
  var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;
  var ids=new Array();
  var wWidth, wHeight, colHeight;
  var t='';
  var counter=0;
  var gx=new Array();

  var RandSeed = 2732615, rnge = Math.pow(2, 32);
  function SeedRand() {return Math.random() % 1; }
  //function SeedRand() {return (RandSeed = (134775813 * RandSeed + 1) % rnge) / rnge;}

  function rtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); }

  for(i=0;i<glyphCount;i++){
    gx[i]=Math.floor(SeedRand()*glyphs.length);
    t+=(ns4)?'<layer name="glyph'+i+'" top="5" left="5" width="'+glyphW+'" height="'+glyphH+'" z-index="1">'
      :'<div id="glyph'+i+'" style="position:absolute; top:-'+3*glyphH+'px; left:5px; width:'+glyphW+'px; height:'+glyphH+'px; z-index:1">';
    t+= '<pre><a class="mnemlink'+(i?'':'b')+'" href="hidden.html" id="g'+i+'">'+glyphs[gx[i]]+'</a></pre>'
    t+=(ns4)?'</layer>':'</div>';
  }
  document.write(t);

  function matrixInit(){
    getWindowDims();
    for(i=0;i<glyphCount;i++){
      ids[i]=(ns4)?document.layers['glyph'+i]:(ie4)?document.all['glyph'+i]:document.getElementById('glyph'+i);
      ids[i].gx=gx[i];
    }
    gx='';
    //setInterval('scrollGlyphs()',10*scrollSpeed);
    scrollGlyphs();
  }

  if(getGrn()==grnOn)
  {
    clr='green';
    clrb='lime';
  }
  else
  {
    clr='palegoldenrod';
    clrb='darkgoldenrod';
  }

  function brighten(idnum,b){
    if(document.getElementById) {
      document.getElementById('g'+idnum).style.color=(b)?clrb:clr;
    }
    else {
      document.all['g'+idnum].className=(b)?'mnemlinkb':'mnemlink';
    }
  }

  function moveID(idnum,x,y){
    var id=ids[idnum];
    if(ns4)id.moveTo(x,y);
    else{
      id.style.left=x+'px';
      id.style.top=y+'px';
    }
    if(!disableColors){
      brighten(idnum,true);
      setTimeout('brighten('+idnum+',false)',scrollSpeed*7);
    }
  }

  function getWindowDims(){
    wWidth=(ie4||ie5)? document.body.clientWidth:window.innerWidth;
    wHeight=(ie4||ie5)? document.body.clientHeight:window.innerHeight;
    //colHeight=Math.min(Math.floor(wHeight/1.5/glyphH)-1,25);
    colHeight=Math.min(Math.floor(wHeight/1.5/glyphH)-1,9);
  }

  function scrollGlyphs(){
    var sx=(ie4||ie5)? document.body.scrollLeft:window.pageXOffset;
    var sy=(ie4||ie5)? document.body.scrollTop-3:window.pageYOffset;
    var pixx=Math.floor(SeedRand()*(wWidth)/glyphW-1)*glyphW+sx+5;
    var pixy=Math.floor(SeedRand()*(wHeight-(colHeight*glyphH)-4)/glyphH-1)*glyphH+sy+5;
    //var pixy=sy;
    for(i=0; i<colHeight; i++){
      setTimeout('moveID('+counter+','+pixx+','+(pixy+glyphH*i)+')', scrollSpeed*(i+5));
      counter=((counter+colHeight)>glyphCount)?0:counter+1;
    }
    setTimeout('scrollGlyphs()', scrollSpeed*7);
  }

  window.onload=matrixInit;
  window.onresize=getWindowDims;
}