// JavaScript Document/**
var imageList = [
				 "<a href=\"http://www.nba.com/thunder/rumble/book.html\"><img src=\"http://www.nba.com/media/thunder/slider_bookrumble.jpg\" width=\"342\" height=\"270\" /></a>",
				 "<a href=\"http://www.nba.com/thunder/rumble/funstuff.html\"><img src=\"http://www.nba.com/media/thunder/slider_funstuff.jpg\" width=\"342\" height=\"270\" /></a>",
				 "<a href=\"http://www.nba.com/thunder/rumble/story.html\"><img src=\"http://www.nba.com/media/thunder/slider_mystory.jpg\" width=\"342\" height=\"270\" /></a>",
				 "<a href=\"http://www.nba.com/thunder/rumble/photos.html\"><img src=\"http://www.nba.com/media/thunder/slider_photos.jpg\" width=\"342\" height=\"270\" /></a>",
				 "<a href=\"http://www.nba.com/thunder/rumble/videos.html\"><img src=\"http://www.nba.com/media/thunder/slider_videos.jpg\" width=\"342\" height=\"270\" /></a>",
				 ];

/**
 * Since carousel.addItem uses an HTML string to create the interface
 * for each carousel item, this method formats the HTML for an LI.
 **/
var fmtItem = function(imgUrl, url, title) {

  	var innerHTML =	imgUrl;
  
	return innerHTML;
	
};

/**
 * Custom inital load handler. Called when the carousel loads the initial
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadInitHandler
 **/
var loadInitialItems = function(type, args) {

	var start = args[0];
	var last = args[1]; 

	load(this, start, last);	
};

/**
 * Custom load next handler. Called when the carousel loads the next
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadNextHandler
 **/
var loadNextItems = function(type, args) {	

	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
};

/**
 * Custom load previous handler. Called when the carousel loads the previous
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadPrevHandler
 **/
var loadPrevItems = function(type, args) {
	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
};

var load = function(carousel, start, last) {
	for(var i=start; i<=last; i++) {
		carousel.addItem(i, fmtItem(imageList[i-1], "#", "Number "+i));
	}
};



/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 **/
var handlePrevButtonState = function(type, args) {
	var enabling = args[0];
	var leftImage = args[1];
	if(enabling) {
		leftImage.src = "/media/thunder/RB-arrowLeft.png";		
	} else {
		leftImage.src = "/media/thunder/RB-arrowLeft.png";	
	}
	
}

/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the next button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: nextButtonStateHandler
 **/
var handleNextButtonState = function(type, args) {
	var enabling = args[0];
	var rightImage = args[1];
	if(enabling) {
		rightImage.src = "/media/thunder/RB-arrowRight.png";	
	} else {
		rightImage.src = "/media/thunder/RB-arrowRight.png";
	}
	
};

/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'dhtml-carousel'.) See the
 * HTML code below.
 **/
var carousel; // for testing
var pageLoad = function() 
{
	carousel = new YAHOO.extension.Carousel("dhtml-carousel", 
		{
			numVisible:        1.05,
			animationSpeed:    0.8,
			animationMethod:   YAHOO.util.Easing.easeBoth,
			scrollInc:         1,
			navMargin:         0,
			size:              5.2,
			revealAmount:      100,
			loadInitHandler:   loadInitialItems,
			prevElement:       "prev-arrow",
			nextElement:       "next-arrow",
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState,
			wrap: true,
			firstVisible: 1
		}
	);
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);

