function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
  if (!elem.style.top) {
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (xpos == final_x && ypos == final_y) {
    return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}

function prepareSlideshow() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("maison")) return false;
  var intro = document.getElementById("maison");
  var slideshow = document.createElement("div");
  slideshow.setAttribute("id","slideshow");   
  var preview = document.createElement("img");
  preview.setAttribute("src","images/pano.jpg");
  preview.setAttribute("alt","Powerwatts :: Performance indoor cycling training");
  preview.setAttribute("id","preview");
  slideshow.appendChild(preview);
  insertAfter(slideshow,intro);
  var links = document.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    links[i].onmouseover = function() {
      var destination = this.getAttribute("href");
      if (destination.indexOf(" ") != -1) {
        moveElement("preview",0,-100,5);
      }
      if (destination.indexOf("training.html") != -1) {
        moveElement("preview",-80,-161,5);
      }
	  if (destination.indexOf("trainingFr.html") != -1) {
        moveElement("preview",-80,-161,5);
      }
      if (destination.indexOf("coaches.html") != -1) {
        moveElement("preview",-180,-161,5);
      }
	  if (destination.indexOf("coachesFr.html") != -1) {
        moveElement("preview",-180,-161,5);
      }
      if (destination.indexOf("services.html") != -1) {
        moveElement("preview",-280,-161,5);
      }
	  if (destination.indexOf("servicesFr.html") != -1) {
        moveElement("preview",-280,-161,5);
      }
      if (destination.indexOf("locations.html") != -1) {
        moveElement("preview",-380,-61,5);
      }
	  if (destination.indexOf("locationsFr.html") != -1) {
        moveElement("preview",-380,-61,5);
      }
	   if (destination.indexOf("team.html") != -1) {
        moveElement("preview",-280,-0,5);
      }
	  if (destination.indexOf("teamFr.html") != -1) {
        moveElement("preview",-280,-0,5);
      }
	   if (destination.indexOf("links.html") != -1) {
        moveElement("preview",-100,-0,5);
      }
	  	   if (destination.indexOf("linksFr.html") != -1) {
        moveElement("preview",-100,-0,5);
      }
    }
  }
}

addLoadEvent(prepareSlideshow);
