
var fmtItem = function(imgUrl, url, title) {
	var innerHTML = '<table border="0">';
	for(i=0;i<3;i++){
      innerHTML+='<td><img onclick="changeImg(\''+imgUrl[i][1]+'\')" src="'+ 
         imgUrl[i][0]+
        '" width="' +
        140 +
        '" height="' +
        140+'" style="cursor:pointer;"/></td>';
	}
	innerHTML+='</table>';
    return innerHTML;
    
};

function changeImg(src){
	var img = document.getElementById('GalleryImg');
	img.src = src;
}

/**
 * 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 upImage = args[1];

	if(enabling) {
		upImage.src = "images/up-enabled.gif";
	} else {
		upImage.src = "images/up-disabled.gif";
	}
	
};
var handleNextButtonState = function(type, args) {

	var enabling = args[0];
	var downImage = args[1];

	if(enabling) {
		downImage.src = "images/down-enabled.gif";
	} else {
		downImage.src = "images/down-disabled.gif";
	}
	
};


