
/**
 * 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 = "images/left-enabled.gif";
    } else {
        leftImage.src = "images/left-disabled.gif";
    }

};

/**
 * 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 = "images/right-enabled.gif";
    } else {
        rightImage.src = "images/right-disabled.gif";
    }

};


/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'bookCarousel'.) See the
 * HTML code below.
 **/

var pageLoad = function()
{
   var carousel = new YAHOO.extension.Carousel("bookCarousel",
        {
            numVisible:        1,
            animationSpeed:    0.5,
            scrollInc:         1,
            navMargin:         20,
            prevElement:     "prev-arrow",
            nextElement:     "next-arrow",
            size:              8,
            prevButtonStateHandler:   handlePrevButtonState,
            nextButtonStateHandler:   handleNextButtonState,
	    wrap: true,
	    autoplay: 5000
        }
    );
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);

var changePage = function(e, args) {
    var carousel = args[0];
    var pageNum = args[1];

    carousel.scrollTo(pageNum);
};
