  var newsLift = $('newsLift');
  var imageStrip = $('newsImgs');
  var images = imageStrip.getElementsByTagName('img');
  var count = $('imageCount');
  var next = $('imageNext');
  var prev = $('imagePrev')
  var currentImageIndex = 0;
  var currentImage = images[0];
  var moving=false;



  imageStrip.setStyle({ 
    width: (images.length * parseInt(newsLift.getStyle('width')) + 3)  + "px",  
    height: "120px",
    clip: "rect(" + images[0].width + "px " + images[0].height + "px " + images[0].width + "px " + images[0].height + "px)",
    overflow:"hidden"   
  });

  for (var i =0; i < images.length; i++) {
    new Insertion.Bottom('control','<a href="javascript:setImage(' + i + '); stopRotate();" id="imgNav'+i+'"></a>');
  }
  
  function setImage(index) {
    if(moving==false) {
      moving=true;
      currentImage = images[ index ];
      var indexInterval = currentImageIndex - index;
      currentImageIndex = index;
      var moveByX = parseInt( newsLift.getStyle('width') ) * indexInterval;
      showAll();
      var slide = new Effect.MoveBy( imageStrip, 0, moveByX, { 
        duration: 1.5, 
        transition: Effect.Transitions.sinoidal,
        afterFinish: hideOthers } );
    }
  }
  
  function showAll() {
    for(var i =0; i < images.length; i++) {
      images[i].parentNode.onclick = function() {return true};
      images[i].style.cursor = "hand";
    }
  }
  
  function hideOthers() {
    moving=false;
    for(var i =0; i < images.length; i++) {
      if (i != currentImageIndex) {
        images[i].parentNode.onclick = function() {return false};
        images[i].style.cursor = "hand";
      } 
    }
  }
  
  // auto rotation
  var play = true;  
  var rotateTimer = 5000;

  function autoRotate() {
     if(play) {
    if (currentImageIndex == images.length - 1) {
      setImage(0);
    } else {
      setImage(currentImageIndex + 1);
    }
     }
  }
  
  function stopRotate() {
     clearInterval(autoPlay);
     play=false;
     setTimeout(startRotate,rotateTimer);
  }

  var autoPlay;
  function startRotate() {
      play=true;
      autoPlay = setInterval(autoRotate,rotateTimer);
  }
  
  // initialise
  startRotate();
  imgnavOver(0);
