var currentCollectionIndex = 0;

function showImage() {
    var img = document.getElementById('ctl00_cphContent_collection_image');
    var elementUL = document.getElementById('collection_list');
    var elementsHyperLink= elementUL.getElementsByTagName('a');
    
    if (elementUL!=null){   
        for (counter = 0; counter < elementsHyperLink.length; counter++) {
            if (elementsHyperLink[counter].className = 'selected'){elementsHyperLink[counter].className = '';};
            if (counter == currentCollectionIndex) {
                elementsHyperLink[counter].className = 'selected'; // selected
                if (img != null) { 
                    blendimage('image_wrap','ctl00_cphContent_collection_image', images[currentCollectionIndex],400);
                    img.alt = elementsHyperLink[counter].innerHTML;
                    }
                } 
            }
    }
 }

function nextPhoto() {
  currentCollectionIndex = (currentCollectionIndex + 1) % collectionCount;
  showImage();
}

function pauseOnCollection(id) {
  rotator.stop();
  currentCollectionIndex = id;
  showImage(); 
}

function startRotation() {
  rotator = new PeriodicalExecuter(function() { nextPhoto() }, 4);  /* 4 seconds. */
}

addLoadEvent(startRotation);
