var giIntervalID1;
var gix = 0;
var screenWidth = screen.width;
var screenHeight = screen.height;
var timeoutID;
var walkingDirection = "left";
var mainTimeout;
var alpacaTop;
var alpacaNewTop;
var humSpot;
var hummed = false;
  
function doInit()
{
  AlpacaWalking.style.left = -100;
  AlpacaWalking.style.display="inline";

  mainTimeout = setTimeout("SetEmWalking()",3000);
}

function SetEmWalking()
{
  clearTimeout(mainTimeout);
  clearTimeout(giIntervalID1);
  clearTimeout(timeoutID);
 
  if(walkingDirection == "left")
  {
    AlpacaWalkingImage.src = "images\\rocketeerWalkingLeft.gif";
    if(hummed == true)
    {
      timeoutID = setTimeout("giIntervalID1 = window.setInterval('moveItLeft(AlpacaWalking,humSpot,-100,giIntervalID1)',40)",0);
      setTimeout("hummed = false;walkingDirection = 'right';",20000);
      
      
    }
    else
    {
      alpacaTop = GetRandomInt(0,(screenHeight/20)*9);
      humSpot = GetRandomInt(50,(screenWidth/5)*4);
      AlpacaWalking.style.left = screenWidth;
      AlpacaWalking.style.top = alpacaTop;
      timeoutID = setTimeout("giIntervalID1 = window.setInterval('moveItLeft(AlpacaWalking,screenWidth,humSpot,giIntervalID1)',40)",0);
    }
  }
  else if(walkingDirection == "right")
  {
    AlpacaWalkingImage.src = "images\\rocketeerWalkingRight.gif";
    if(hummed == true)
    {
      timeoutID = setTimeout("giIntervalID1 = window.setInterval('moveItRight(AlpacaWalking,humSpot,screenWidth,giIntervalID1)',40)",0);
      setTimeout("hummed = false;walkingDirection = 'left';",20000);
      
    }
    else
    {
      alpacaTop = GetRandomInt(0,(screenHeight/3)*2);
      AlpacaWalking.style.left = -100;
      humSpot = GetRandomInt(50,(screenWidth/3)*2);
      AlpacaWalking.style.top = alpacaTop;
      timeoutID = setTimeout("giIntervalID1 = window.setInterval('moveItRight(AlpacaWalking,-100,humSpot,giIntervalID1)',40)",0);
    }
  }
  mainTimeout = setTimeout("SetEmWalking()",30000);
}

function movedone(objItem)
{
  //objItem.style.backgroundImage = "url(images/transback.gif)";
  // objItem.rows(0).style.visibility = "visible";
  //objItem.style.borderWidth = "0";
}


/***************
Purpose : Moves DHTML object horizontally from left to right.
Params  : Send object, startposition, endposition, and intervalid.
Example of use :
	giIntervalID = window.setInterval("moveIt(tableItem,-300,2,giIntervalID)",20);
***************/
function moveItRight(objItem,iStart,iEnd,IntervalID)
{	
  iStart = parseInt(iStart);
  iEnd = parseInt(iEnd);
  iCurrent = parseInt(objItem.style.left);
  if (iStart < iEnd)
  {
    objItem.style.display = "inline";
    
    // This next crap is for stopping and humming
    if (iCurrent >= iEnd && hummed == false)
    {
      StopAndHum(objItem,iCurrent,iEnd,IntervalID,"right");
      return;
    }
      
    if (iCurrent < iEnd)
    {
      iCurrent += 6
      objItem.style.left = iCurrent;
    }
    else
    {
      window.clearInterval(IntervalID);
      movedone(objItem)
      objItem.style.left = -100;
    }
  }
  else //if iEnd > iStart
  {
    if (iCurrent > iEnd)
    {
      //iCurrent -= 3;
      objItem.style.left = iCurrent;
    }
    else
    {
      //objItem.style.display = "none";
      Window.clearInterval(IntervalID);
    }
  }
}

/***************
Purpose : Moves DHTML object horizontally from right to left.
Params  : Send object, startposition, endposition, and interval id.
Example of use :
	giIntervalID = window.setInterval("moveIt(tableItem,-300,2,giIntervalID)",20);
***************/
function moveItLeft(objItem,iStart,iEnd,IntervalID)
{	
  iStart = parseInt(iStart);
  iEnd = parseInt(iEnd);
  iCurrent = parseInt(objItem.style.left);
  if (iStart > iEnd)
  {
    objItem.style.display = "inline";
    
    // This next crap is for stopping and humming
    if (iCurrent <= iEnd && hummed == false)
    {
      StopAndHum(objItem,iCurrent,iEnd,IntervalID,"left");
      return;
    }
    
    if (iCurrent > iEnd)
    {
      iCurrent -= 6
      objItem.style.left = iCurrent;
    }
    else
    {
      window.clearInterval(IntervalID);
      movedone(objItem);
    }
  }
  else //if iEnd > iStart
  {
    if (iCurrent < iEnd)
    {
      //iCurrent += 3
      objItem.style.left = iCurrent;
    }
    else
    {
      //objItem.style.display = "none";
      Window.clearInterval(IntervalID);
    }
  }
}

function StopAndHum(objItem,iCurrent,iEnd,IntervalID,direction)
{
  clearTimeout(IntervalID);
  clearTimeout(timeoutID);
  
  if(direction == "right")
  {
    AlpacaWalkingImage.src = "images\\rocketeerStandingRight.gif";
  } 
  else if(direction == "left")
  {
    AlpacaWalkingImage.src = "images\\rocketeerStandingLeft.gif";
  }
  AlpacaHum.Play();
  hummed = true;
  timeoutID = setTimeout("SetEmWalking()",1000);
}	

var now = new Date();
var seed = now.getTime() % 0xffffffff;

function GetRandomInt(low,high)
{
  return Random(high - low) + low;
}
function Random(n) 
{
  seed = (0x015a4e35 * seed) % 0x7fffffff;
  if(n == 0)
    return 0;
  else
    return (seed >> 16) % n;
}

////Fade stuff...
dd=document;
NS=(dd.layers)?1:0;
IE=(dd.all)?1:0;
msge='This site best viewed with\nInternet Explorer in 1024x768';
steps=100;
num=0;
r0=252;g0=200;b0=0;
r1=0;g1=0;b1=128;
stepR=Math.floor((r1-r0)/steps);
stepG=Math.floor((g1-g0)/steps);
stepB=Math.floor((b1-b0)/steps);
if (NS) 
{closeIt="document.fadeText.document.close()";} 
else 
{z1="document.all.fadeText.innerText=msge";}
 
hexa=new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function hex(i){if (i<0)return "00";else if (i>255)return "ff";else return ""+hexa[Math.floor(i/16)]+hexa[i%16]}
function setclr(r,g,b){hr=hex(r);hg=hex(g);hb=hex(b);clr="#"+hr+hg+hb;}
function setob(L){if(NS){obg=dd.layers[L]} else {obg=dd.getElementById(L);obg=obg.style}}
numOfLoops=1;
loopCounter=0;
 
function fadeOut()
{
  num--;
  if(num>=0)
  {
    setclr(r1-stepR*num,g1-stepG*num,b1-stepB*num);
    if (NS)
    {
      document.fadeText.document.write('<p style=\"width:600;font-family:Arial;font-size:14px;color:'+clr+'\">'+msge+'</p>');
      eval(closeIt);
    } 
    else 
    {
      obg.color=clr;
    }
    fadeOutTimer = setTimeout("fadeOut()",50);
  } 
  else 
  {
    clearTimeout(fadeOutTimer);
    loopCounter++;
    if(loopCounter >= numOfLoops)
    {
      clearTimeout(fadeOutTimer);
      clearTimeout(fadeInTimer);
    }
    else
      fadeIn();
  }
}
 
function fadeIn()
{
  num++;
  if(num<=steps)
  {
    setclr(r1-stepR*num,g1-stepG*num,b1-stepB*num);
    if (NS)
    {
      document.fadeText.document.write('<p style=\"width:600;font-family:Arial;font-size:14px;color:'+clr+'\">'+msge+'</p>');
      eval(closeIt);
    } 
    else 
    {
      obg.color=clr;
      if (IE)
        eval(z1);
    }
    fadeInTimer = setTimeout("fadeIn()",50);
  }
  else 
  {
    clearTimeout(fadeInTimer);
    fadeOut();
  }
}
// End fade stuff