var hold_speed = 5000;
var opacStart = 0;
var opacEnd = 100;
var pause = false;
var timerchange;
var images = new Array();
var array_index = 0;

function initiateRotation() {
  var container = document.getElementById("rotation_container");
  var image = document.createElement("img");
  image.src = images[0][0];
  image.id = "banner_image";
  image.style.cursor = "pointer";
  image.onclick = function() { window.location = images[0][1]; }
  image.onmouseover = function() { pause = true;clearTimeout(timerchange); };
  image.onmouseout = function() { if(pause) { pause = false; timerchange = setTimeout("changeImg()",hold_speed);}};
  var rotation_panel = document.getElementById("rotation_panel");
  /*var first_left = Math.floor((581-21*images.length)/2) + (images.length-1)*21;*/
  var first_left = 549;
  for(var i=images.length; i > 0; i--) {
    var number = document.createElement("span");
    number.innerHTML = i+"";
    number.style.left = (first_left - 21*(images.length - i))+"px";
    number.className = "opacityOn";
    number.onmouseover = function() { this.className = "opacityOff"; }
    number.onmouseout = function() { this.className = "opacityOn"; }
    number.onclick= function() { clearTimeout(timerchange);changeImage(parseInt(this.innerHTML));}
    container.appendChild(number);
  }
  container.appendChild(image);
  rotate();
}

function rotate() {
  timerchange = setTimeout("changeImg()",hold_speed);
}

function changeImage(num) {
  var image = document.getElementById("banner_image");
  array_index = num - 1;
  image.src = images[array_index][0];
  image.onclick = function() { window.location = images[array_index][1]; }
  rotate();
}

function changeImg() {
  if(pause) return;
  var image = document.getElementById("banner_image");
  if(++array_index >= images.length) { array_index = 0; }
  image.src = images[array_index][0];
  image.onclick = function() { window.location = images[array_index][1]; }
  rotate();
}
