document.hrefArt1 = new Array('Art1/Priest.jpg', 'Art1/cherrypicker.jpg', 'Art1/Cyberbabe.jpg', 'Art1/Anubis Temple.jpg', 'Art1/PointDefense1.jpg', 'Art1/Outposts.jpg', 'Art1/Nylanthrotep.jpg');
document.hrefArt2 = new Array('Art2/fuelcart.jpg', 'Art2/RocketBot.jpg', 'Art2/unsctank.jpg', 'Art2/TheBrick1.jpg', 'Art2/HydroPlant.jpg', 'Art2/TactMissleDefense.jpg', 'Art2/SubHunter1.jpg');
document.hrefAnim = new Array('Anim/muggshot.wmv', 'Anim/MadAbobo3.wmv', 'Anim/gladiator.wmv', 'Anim/centipede.wmv', 'Anim/spdr2A.wmv', 'Anim/slug.wmv', 'Anim/Conifers.wmv');

//////////////////////////////////////////////////////////////////////////////

document.nowSelected="none";
document.nowBlinking=false;
document.orbIsDead = new Array();
document.progressMeterLock=false;
document.bodyComplete=false;

document.orbIsDead['none'] = new Array();
document.orbIsDead['Joystick'] = new Array();
document.orbIsDead['Art1'] = new Array();
document.orbIsDead['Art2'] = new Array();
document.orbIsDead['Anim'] = new Array();

document.criticalImages=new Array('images/BaseCut1-top.jpg', 'images/BaseCut1-left.jpg', 'images/BaseCut1-right.jpg', 'images/BaseCut1-bottom.jpg', 'images/BaseCut1-middle.gif', 'images/BaseCut2.jpg', 'images/BaseCut3.jpg', 'images/BaseCut4.jpg', 'images/3Dartistscreen.jpg', 'images/Joystickupbtn.jpg', 'images/Art1upbtn.jpg', 'images/Art2upbtn.jpg', 'images/Aniupbtn.jpg', 'images/BaseCut5.jpg', 'images/spacer.gif', 'images/deadorb1.gif', 'images/deadorb2.gif', 'images/deadorb3.gif', 'images/deadorb4.gif', 'images/deadorb5.gif', 'images/deadorb6.gif', 'images/deadorb7.gif', 'images/BaseCut6.jpg', 'images/ANIM.jpg', 'images/ANIMCEO.jpg', 'images/ART1.jpg', 'images/ART1CEO.jpg', 'images/ART2.jpg', 'images/ART2CEO.jpg', 'images/Anioverbtn.jpg', 'images/Art1overbtn.jpg', 'images/Animationscreen.jpg', 'images/Art2overbtn.jpg', 'images/Art1screen.jpg', 'images/Art2screen.jpg', 'images/Joystickoverbtn.jpg', 'images/Resumescreen.jpg');
document.gravyImages=new Array();
document.gravyImages=document.gravyImages.concat(document.hrefArt1);
document.gravyImages=document.gravyImages.concat(document.hrefArt2);
// You can't preload animation objects, plus they're so big they force the jpg's out of cache.
//document.gravyImages=document.gravyImages.concat(document.hrefAnim);

for (i=1; i<=7; i++) {
  document.orbIsDead['none'][i] = false;      // None of the orbs should be dead if none is selected.
  document.orbIsDead['Joystick'][i] = true;  // All the orbs should be dead if Joystick is selected.
  document.orbIsDead['Art1'][i] = false;     // All the orbs should be alive (initially) if Art1, Art2, or Anim is selected.
  document.orbIsDead['Art2'][i] = false;     // All the orbs should be alive (initially) if Art1, Art2, or Anim is selected.
  document.orbIsDead['Anim'][i] = false;     // All the orbs should be alive (initially) if Art1, Art2, or Anim is selected.
}

function preloadImages() {
  var d=document; 
  if(d.images) { 
    if(!d.MM_p) {
      d.MM_p=new Array();
    }
    var i,j=d.MM_p.length,a=preloadImages.arguments[0]; 
    for(i=0; i<a.length; i++){
      d.MM_p[j]=new Image; 
      d.MM_p[j].src=a[i]; 
      j++;
    }
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() {
  var x, imgName=swapImage.arguments[0], newSrc=swapImage.arguments[1]; 
  if ((x=MM_findObj(imgName))!=null){ x.src=newSrc}
}
function hideOrb() {
  num=hideOrb.arguments[0];
  var x;
  x=MM_findObj("deadorb"+num);
  // In order to hide the orb, make the deadorb visible.
  if(x!=null) x.style.visibility="visible";
}
function unHideOrb() {
  num=unHideOrb.arguments[0];
  var x;
  x=MM_findObj("deadorb"+num);
  // In order to unhide the orb, make the deadorb invisible.
  if(x!=null) x.style.visibility="hidden";
}
function updateOrbs() {
  var updateTo;
  if ( typeof(updateOrbs.arguments[0]) == 'undefined' ) {
    updateTo=document.nowSelected;
  } else {
    updateTo=updateOrbs.arguments[0];
  }
  for (i=1; i<=7; i++) {
    if ( document.orbIsDead[updateTo][i] ) {
      hideOrb(i);
    } else {
      unHideOrb(i);
    }
  }
}
function newSelect() {
  var i;
  if ( document.nowBlinking ) return false;
  document.nowSelected=newSelect.arguments[0];

  if ( document.nowSelected == "none" ) {
    swapImage('Joystick','images/Joystickupbtn.jpg');
    swapImage('Art1','images/Art1upbtn.jpg');
    swapImage('Art2','images/Art2upbtn.jpg');
    swapImage('Anim','images/Aniupbtn.jpg');
    swapImage('CenterScreen','images/3Dartistscreen.jpg');
    updateOrbs();
  }
  if ( document.nowSelected == "Joystick" ) {
    swapImage('Joystick','images/Joystickoverbtn.jpg');
    swapImage('Art1','images/Art1upbtn.jpg');
    swapImage('Art2','images/Art2upbtn.jpg');
    swapImage('Anim','images/Aniupbtn.jpg');
    swapImage('CenterScreen','images/Resumescreen.jpg');
    updateOrbs();
  }
  if ( document.nowSelected == "Art1" ) {
    swapImage('Joystick','images/Joystickupbtn.jpg');
    swapImage('Art1','images/Art1overbtn.jpg');
    swapImage('Art2','images/Art2upbtn.jpg');
    swapImage('Anim','images/Aniupbtn.jpg');
    swapImage('CenterScreen','images/Art1screen.jpg');
    document.nowBlinking=true;
    for ( i=0 ; i<3000 ; i+=500) {
      setTimeout("swapImage('CenterScreen','images/ART1CEO.jpg');",i);
      setTimeout("swapImage('CenterScreen','images/ART1.jpg');",i+250);
    }
    setTimeout("swapImage('CenterScreen','images/Art1screen.jpg');",i);
    setTimeout("document.nowBlinking=false;",i);
    updateOrbs();
  }
  if ( document.nowSelected == "Art2" ) {
    swapImage('Joystick','images/Joystickupbtn.jpg');
    swapImage('Art1','images/Art1upbtn.jpg');
    swapImage('Art2','images/Art2overbtn.jpg');
    swapImage('Anim','images/Aniupbtn.jpg');
    document.nowBlinking=true;
    for ( i=0 ; i<3000 ; i+=500) {
      setTimeout("swapImage('CenterScreen','images/ART2CEO.jpg');",i);
      setTimeout("swapImage('CenterScreen','images/ART2.jpg');",i+250);
    }
    setTimeout("swapImage('CenterScreen','images/Art2screen.jpg');",i);
    setTimeout("document.nowBlinking=false;",i);
    updateOrbs();
  }
  if ( document.nowSelected == "Anim" ) {
    swapImage('Joystick','images/Joystickupbtn.jpg');
    swapImage('Art1','images/Art1upbtn.jpg');
    swapImage('Art2','images/Art2upbtn.jpg');
    swapImage('Anim','images/Anioverbtn.jpg');
    document.nowBlinking=true;
    for ( i=0 ; i<3000 ; i+=500) {
      setTimeout("swapImage('CenterScreen','images/ANIMCEO.jpg');",i);
      setTimeout("swapImage('CenterScreen','images/ANIM.jpg');",i+250);
    }
    setTimeout("swapImage('CenterScreen','images/Animationscreen.jpg');",i);
    setTimeout("document.nowBlinking=false;",i);
    updateOrbs();
  }
}

function mouseonto() {
  mouseIsOn=mouseonto.arguments[0];
  if ( document.nowBlinking ) return false;

  if ( mouseIsOn == "Joystick" ) {
    swapImage('Joystick','images/Joystickoverbtn.jpg');
    swapImage('CenterScreen','images/Resumescreen.jpg');
    updateOrbs('Joystick');
  }
  if ( mouseIsOn == "Art1" ) {
    swapImage('Art1','images/Art1overbtn.jpg');
    swapImage('CenterScreen','images/Art1screen.jpg');
    updateOrbs('Art1');
  }
  if ( mouseIsOn == "Art2" ) {
    swapImage('Art2','images/Art2overbtn.jpg');
    swapImage('CenterScreen','images/Art2screen.jpg');
    updateOrbs('Art2');
  }
  if ( mouseIsOn == "Anim" ) {
    swapImage('Anim','images/Anioverbtn.jpg');
    swapImage('CenterScreen','images/Animationscreen.jpg');
    updateOrbs('Anim');
  }
}

function mouseout() {
  mouseOutOf=mouseout.arguments[0];
  if ( document.nowBlinking ) return false;

  swapImage('Joystick','images/Joystickupbtn.jpg');
  swapImage('Art1','images/Art1upbtn.jpg');
  swapImage('Art2','images/Art2upbtn.jpg');
  swapImage('Anim','images/Aniupbtn.jpg');
  switch (document.nowSelected) {
    case "none":
      swapImage('CenterScreen','images/3Dartistscreen.jpg');
      updateOrbs();
      break;
    case "Joystick":
      swapImage('CenterScreen','images/Resumescreen.jpg');
      updateOrbs();
      break;
    case "Art1":
      swapImage('CenterScreen','images/Art1screen.jpg');
      swapImage('Art1','images/Art1overbtn.jpg');
      updateOrbs();
      break;
    case "Art2":
      swapImage('CenterScreen','images/Art2screen.jpg');
      swapImage('Art2','images/Art2overbtn.jpg');
      updateOrbs();
      break;
    case "Anim":
      swapImage('CenterScreen','images/Animationscreen.jpg');
      swapImage('Anim','images/Anioverbtn.jpg');
      updateOrbs();
      break;
  }
}

function clickorb() {
  orbnum = clickorb.arguments[0];

  switch ( document.nowSelected ) {
    case 'none':
      return false;

    case 'Joystick':
      return false;

    case 'Art1':
      clickorb.arguments[1].href=document.hrefArt1[orbnum-1];
      document.orbIsDead[document.nowSelected][orbnum]=true;
      hideOrb(orbnum);
      return true;
    case 'Art2':
      clickorb.arguments[1].href=document.hrefArt2[orbnum-1];
      document.orbIsDead[document.nowSelected][orbnum]=true;
      hideOrb(orbnum);
      return true;
    case 'Anim':
      clickorb.arguments[1].href=document.hrefAnim[orbnum-1];
      document.orbIsDead[document.nowSelected][orbnum]=true;
      hideOrb(orbnum);
      return true;
  }
}
function progressMeter() {
  a=progressMeter.arguments[0];
  if ( (!document.progressMeterLock) | (a=='polling') ) {
    document.progressMeterLock=true;
    bodyComplete=document.bodyComplete;
    var count=0;
    var perc;

    if ( typeof(document.MM_p) != "undefined" ) {
      for (i=0; i<document.MM_p.length; i++) {
        if (document.MM_p[i].complete) {
          count++;
        }
      }
      perc = parseInt( 200 * count / document.criticalImages.length );  // That's 200px * count / how many critical images

      if ( perc < 200 ) { // perc is < 200 as long as the criticalImages haven't all loaded yet.
        var x;
        x=MM_findObj("preloader");
        // Update the width of the progressMeter, wait 100ms, and check again.
        if(x != null) x.style.width=perc + 'px';
        setTimeout('progressMeter("polling")',100);
      } else {
        // all the images have finished loading.
        var x;
        // Set the program into its initial state, and hide the progressMeter
        newSelect('none');
        x=MM_findObj("blockerdiv");
        if(x != null) {
          x.style.display="none";
          if ( bodyComplete ) {
            preloadImages(document.gravyImages);
          }
        }
        // If perc >= 200, and x == null, it means all the images have preloaded into cache, yet the blockerdiv doesn't exist.
        // This can only happen if the user has clicked the refresh button.
        // Hence we have the document.progressMeterLock 
        // You see, progressMeter() will be called in the body of the html, and also for body.onload.  I only want one to run at a time.
        // But the last one done *must* disable the blockerdiv.
        document.progressMeterLock=false;
      }
    } else {
      // We only get here if document.MM_p is undefined.
      // This can only mean that progressMeter() was called before preloadImages().  You should never do this.
      // before complaining, we'll try to deal with the problem by waiting a little while and calling ourselves again.
      if ( typeof ( document.blahFlag ) == 'undefined' ) {
        document.blahFlag=true;
        setTimeout('progressMeter("polling")',100);
      } else {
        alert("You shouldn't call progressMeter() before preloadImages()");
        document.progressMeterLock=false;
      }
    }
  }
}
