﻿/**
* 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 = "gfx/first.gif"; // Right enabled
    } else {
        leftImage.src = "gfx/first.gif"; // Right disabled
    }
};

/**
* 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 = "gfx/last.gif"; // Left enabled
    } else {
        rightImage.src = "gfx/last.gif"; // Left disabled
    }

};


/**
* You must create the carousel after the page is loaded since it is
* dependent on an HTML element (in this case 'mycarousel'.) See the
* HTML code below.
**/
var carousel; // for ease of debugging; globals generally not a good idea
var pageLoad = function() {
    carouselRandom = new YAHOO.extension.Carousel("mycarouselRandom",
		{
		    numVisible: 3,
		    animationSpeed: 0.25,
		    scrollInc: 1,
		    navMargin: 20,
		    prevElement: "random-prev-arrow",
		    nextElement: "random-next-arrow",
		    /*autoPlay: 4000,*/
		    wrap: true,
		    size: 6,
		    prevButtonStateHandler: handlePrevButtonState,
		    nextButtonStateHandler: handleNextButtonState
		}
	);
		carousel = new YAHOO.extension.Carousel("mycarouselRecent",
		{
		    numVisible: 3,
		    animationSpeed: 0.25,
		    scrollInc: 1,
		    navMargin: 20,
		    prevElement: "recent-prev-arrow",
		    nextElement: "recent-next-arrow",
		    /*autoPlay: 4000,*/
		    wrap: true,
		    size: 6,
		    prevButtonStateHandler: handlePrevButtonState,
		    nextButtonStateHandler: handleNextButtonState
		}
	);
		carousel = new YAHOO.extension.Carousel("mycarouselTop",
		{
		    numVisible: 3,
		    animationSpeed: 0.25,
		    scrollInc: 1,
		    navMargin: 20,
		    prevElement: "top-prev-arrow",
		    nextElement: "top-next-arrow",
		    /*autoPlay: 4000,*/
		    wrap: true,
		    size: 6,
		    prevButtonStateHandler: handlePrevButtonState,
		    nextButtonStateHandler: handleNextButtonState
		}
	);
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);
