/**
 * Image src URLs
 **/


/**
 * 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 = 
          '<a href="' + 
          url + 
          '"><img src="' + 
          imgUrl +
        '" width="' +
        100 +
        '" height="' +
        35+
        '"/>' +       
          '<\/a>';
  
    return  _proxy_jslib_handle(null, 'innerHTML', innerHTML, 0, 0);
    
};

/**
 * 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]; 

     _proxy_jslib_handle(null, 'load', load, 1, 0)(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) {
         _proxy_jslib_handle(null, 'load', load, 1, 0)(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) {
         _proxy_jslib_handle(null, 'load', load, 1, 0)(this, start, last);
    }
};

var load = function(carousel, start, last) {

    for(var i=start; i<=last; i++) {
        carousel.addItem(i, fmtItem( _proxy_jslib_handle(imageList, (i-1), 0, 0), "#", "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) {
         _proxy_jslib_assign('', leftImage, 'src', '=', ( "images/homepage/2008/widget/left-enabled.gif"));        
    } else {
         _proxy_jslib_assign('', leftImage, 'src', '=', ( "images/homepage/2008/widget/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) {
         _proxy_jslib_assign('', rightImage, 'src', '=', ( "images/homepage/2008/widget/right-enabled.gif"));    
    } else {
         _proxy_jslib_assign('', rightImage, 'src', '=', ( "images/homepage/2008/widget/right-disabled.gif"));
    }
    
};

/**
 * 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 ease of debugging; globals generally not a good idea
var pageLoad = function() {
    carousel = new (YAHOO.extension.Carousel)("dhtml-carousel", 
        {
            numVisible:        6,
            animationSpeed:    1.5,
            animationMethod:   YAHOO.util.Easing.easeBoth,
            scrollInc:         6,
            navMargin:         30,
            size:              35,
            loadInitHandler:   loadInitialItems,
            prevElement:     "prev-arrow",
            nextElement:     "next-arrow",
            loadNextHandler:   loadNextItems,
            loadPrevHandler:   loadPrevItems,
            prevButtonStateHandler:   handlePrevButtonState,
            nextButtonStateHandler:   handleNextButtonState

 }
    );
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);

 ;
_proxy_jslib_flush_write_buffers() ;