var priorCenterItem = 1;
var imageList = [ "",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/swann240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/broad240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/pontingrun240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/pontingpulls240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/flintoffrunout240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/clarke240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/husseypulls240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/husseycuts240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/husseycentury240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/haddin240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/strausscatch240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/harmison240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/swannhussey240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/flintoffponting240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/pontingclarke240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/pontingurn240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/straussmos240809_th65.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/strausslifts240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/struassurn240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/straussteammates240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/englandteamchamp240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/flintofffamily240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/strussfamily240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/harmisonflintoff240809_th.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/thumbnails/flower240809_th.jpg"];
var urlList = [ "",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/swann240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/broad240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/pontingrun240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/pontingpulls240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/flintoffrunout240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/clarke240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/husseypulls240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/husseycuts240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/husseycentury240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/haddin240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/strausscatch240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/harmison240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/swannhussey240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/flintoffponting240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/pontingclarke240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/pontingurn240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/straussmos240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/strausslifts240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/struassurn240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/straussteammates240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/englandteamchamp240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/flintofffamily240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/strussfamily240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/harmisonflintoff240809.jpg",
"/images/photo-gallery/the-oval-test-(eng-v-aus)-day-4/flower240809.jpg"];
var headList = [ "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""];
var capList = [ "",
"Graeme Swann gave England the ideal start when he removed Simon Katich",
"Stuart Broad celebrates his early success",
"Ricky Ponting showed huge determination to steady Australia",
"Ricky Ponting swivels and pulls",
"Andrew Flintoff celebrates after running out Ricky Ponting",
"A rueful Michael Clarke after being run out for a duck",
"Michael Hussey pulls during his hundred",
"Michael Hussey cuts off the back foot",
"Michael Hussey celebrates his century",
"Brad Haddin mis-judged and top-edged",
"Andrew Strauss celebrates after catching Brad Haddin",
"Steve Harmison dismissed Mitchell Johnson and Stuart Clark off consecutive balls",
"Graeme Swann claimed the final wicket as England regained the Ashes",
"Ricky Ponting shakes hands with Andrew Flintoff in his final Test",
"Ricky Ponting shows his disappointment after he became only the second Australian captain to lose two Ashes series in England",
"Ricky Ponting doesn't look at the prize that got away",
"Andrew Strauss receives his Man of the Series award",
"Andrew Strauss goes to lift the urn",
"Andrew Strauss holds the Ashes urn",
"Andrew Strauss holds the Ashes aloft with team-mates",
"The England team celebrate with champagne",
"Andrew Flintoff with his emotional parents",
"Andrew Strauss with his wife, kids...and the Ashes",
"Great mates: Steve Harmison and Andrew Flintoff savour victory",
"England Coach Andy Flower poses with the Ashes urn in the dressing room"];
var lastRan = -1;
var fmtItem = function(imgUrl, url, title, i) {
var innerHTML = '<img id="carousel-image-' + i + '" src="' + imgUrl + '" width="' + 75 + '" height="' + 75+ '"/><a id="carousel-anchor-' + i + '" href="' + url + '">' + title + '</a>';
return innerHTML;
};
var loadInitialItems = function(type, args) {
 var start = args[0];
 var last = args[1]; 
load(this, start, last);
spotlight(this);
preview(this);
};
var loadNextItems = function(type, args) {;
var li = this.getItem(priorCenterItem);;
var start = args[0];
var last = args[1];
var alreadyCached = args[2];
if(!alreadyCached) {
load(this, start, last);
 }
spotlight(this);
 preview(this);
};
var loadPrevItems = function(type, args) {
// get the last middle item and turn off spotlight
var li = this.getItem(priorCenterItem);
var start = args[0];
var last = args[1]; 
var alreadyCached = args[2];
 if(!alreadyCached) {
load(this, start, last);
}
spotlight(this);
preview(this);
};
var load = function(carousel, start, last) {
for(var i=start;i<=last;i++) {
carousel.addItem(i, fmtItem(imageList[i], urlList[i], "", i), 'non-spotlight');
 // Image click will scroll to the corresponding carousel item.
 YAHOO.util.Event.addListener('carousel-image-'+i, 'click', function(evt) {
 this.carousel.scrollTo(this.index-2);
  }, {carousel:carousel,index:i}, true);
 }
};
var getRandom = function(max, last) {
  var randomIndex;
  do {
     randomIndex = Math.floor(Math.random()*max);
   } while(randomIndex == last);
  return randomIndex;
};
var handlePrevButtonState = function(type, args) {
  var enabling = args[0];
  var leftImage = args[1];
  if(enabling) {
      leftImage.src = "/images/left-enabled.gif"; 
  } else {
     leftImage.src = "/images/left-disabled.gif";
 }
};
var handleNextButtonState = function(type, args) {
var enabling = args[0];
var rightImage = args[1];
if(enabling) {
rightImage.src = "/images/right-enabled.gif";   
} else {
rightImage.src = "/images/right-disabled.gif";
}
};
 function completeHandler(type, args) {
}
function preview(carousel) {
var firstVisible = carousel.getProperty("firstVisible");
var middle = firstVisible + 2;
var anchor = YAHOO.util.Dom.get('carousel-anchor-' + middle);
//alert(anchor.href)
YAHOO.util.Dom.get('preview').innerHTML = '<img src="' + anchor.href + '"/>';
//alert(middle);
var status = "Showing " + middle + " of 25"; 
YAHOO.util.Dom.get("indicator").innerHTML = status;
YAHOO.util.Dom.get("photo-header").innerHTML = headList[middle];
YAHOO.util.Dom.get("photo-caption").innerHTML = capList[middle];
}
function spotlight(carousel) {
var firstVisible = carousel.getProperty("firstVisible");
var start = firstVisible;
var revealAmount = carousel.getProperty("revealAmount");
var size = carousel.getProperty("size");
if(revealAmount && firstVisible > 1) {
   start = firstVisible - 1;
}
var lastVisible = firstVisible + carousel.getProperty("numVisible") - 1;
var end = lastVisible;
 if(revealAmount && lastVisible < size) {
    end = lastVisible + 1;
 }
var middle = firstVisible + 2;
for(var i=start; i<=end; i++) {
    var li = carousel.getItem(i);
   if(i == middle) {
       YAHOO.util.Dom.replaceClass(li, 'non-spotlight', 'spotlight');
       priorCenterItem = i;
   } else {
       YAHOO.util.Dom.replaceClass(li, 'spotlight', 'non-spotlight');
   }
 }
}
     var carousel; // for ease of debugging; globals generally not a good idea
var pageLoad = function() 
{
   carousel = new YAHOO.extension.Carousel("dhtml-carousel", 
      {
    numVisible:         6,
    animationSpeed:     0.6,
    animationMethod:    YAHOO.util.Easing.backBoth,
    scrollInc:          1,
    navMargin:          40,
    scrollBeforeAmount: 2,
    firstVisible:       1,
    size:               25,
    scrollAfterAmount:  3,
    prevElement:        "prev-arrow",
    nextElement:        "next-arrow",
    loadInitHandler:    loadInitialItems,
    loadNextHandler:    loadNextItems,
    loadPrevHandler:    loadPrevItems,
    prevButtonStateHandler:   handlePrevButtonState,
    nextButtonStateHandler:   handleNextButtonState,
    animationCompleteHandler: completeHandler
   }
 );
  //carousel.loadNextHandlerEvt.subscribe(beforeNext, carousel);
};
YAHOO.util.Event.addListener(window, 'load', pageLoad);

