// Moving Yacht Script for Fisher Surveys Website
// © 2005 Flipside Web Design
// Author: Richard Adams

// Globar varibles
if (document.all) { var w = document.body.clientWidth }
else if (document.layers) { var w = window.innerWidth }
else { var w = 800 }

var yachtPos = w;
var width = 43;
var speed = 2;
var diff = speed;
var boats = 4;

function placeYacht() {
document.write('<DIV ID="yacht" style="position: absolute; top: 5px; left: -158px; z-index: 2">');
document.write('<img alt="" src="images/yacht1.png" width=43 height=37 border=0 id="yachtImage" class=clear>');
document.write('</div>\n\n');
newBoat('1');
diff = speed;
}

function moveYacht(useImage) {
  if (useImage=='') { useImage='yacht' }
  if (document.getElementById) {
    var yacht = document.getElementById('yacht')
  }
  else if (document.all) {
    var yacht = document.all['yacht']
  }
  else if (document.layers) {
  var yacht = document.layers['yacht']
  }

  if (document.all) {
    var h = document.body.clientHeight;
    var w = document.body.clientWidth;
  }
  else if (document.layers) {
    var h = window.innerHeight;
    var w = window.innerWidth;
  }

  yacht.style.left = yachtPos;
//  yacht.style.top = document.body.scrollTop + h - imgHeight;
  yachtPos = yachtPos - diff;
  if (yachtPos < -75) { newBoat('2'); diff = -speed; }
  if (yachtPos > w + 25) { newBoat('1'); diff = speed; }
}

function newBoat(dirn) {
var newBoat = '';
  if (document.getElementById) { var yacht = document.getElementById('yacht') }
  else if (document.all) { var yacht = document.all['yacht'] }
  else if (document.layers) { var yacht = document.layers['yacht'] }

rand = Math.floor(boats * Math.random());
if (rand==0) {
  newBoat = 'yacht';
  speed = 0.5;
  width = 43;
}
else if (rand==1) {
  newBoat = 'dingy';
  speed = 0.2;
  width = 37;
}
else if (rand==2) {
  newBoat = 'barge';
  speed = 0.5;
  width = 76;
}
else {
  newBoat = 'semi';
  speed = 5;
  width = 73;
}
yachtImage.src="images/" + newBoat + dirn + ".png";
yachtImage.style.width=width;
yachtImage.style.className='clear';
}