/**
 * Image src URLs
 **/
/* var imageList = [
                 "http://billwscott.com/carousel/images/thumb_1.jpg",
                 "http://billwscott.com/carousel/images/thumb_2.jpg",
                 "http://billwscott.com/carousel/images/thumb_3.jpg",
                 "http://billwscott.com/carousel/images/thumb_4.jpg",
                 "http://billwscott.com/carousel/images/thumb_5.jpg",
                 "http://billwscott.com/carousel/images/thumb_6.jpg",
                 "http://billwscott.com/carousel/images/thumb_7.jpg",
                 "http://billwscott.com/carousel/images/thumb_8.jpg",
                 "http://billwscott.com/carousel/images/thumb_9.jpg",
                 "http://billwscott.com/carousel/images/thumb_10.jpg",
                 "http://billwscott.com/carousel/images/thumb_11.jpg",
                 "http://billwscott.com/carousel/images/thumb_12.jpg",
                 "http://billwscott.com/carousel/images/thumb_13.jpg",
                 "http://billwscott.com/carousel/images/thumb_14.jpg",
                 "http://billwscott.com/carousel/images/thumb_15.jpg",
                 "http://billwscott.com/carousel/images/thumb_16.jpg",
                 "http://billwscott.com/carousel/images/thumb_17.jpg",
                 "http://billwscott.com/carousel/images/thumb_18.jpg"
                 ]; */

/**
 * 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 a = "showImg('"+imgUrl+"');";

      var innerHTML = 
          '<a href="' + 
          url + 
          '" onclick="'+a+' return false;"><img src="' + 
          imgUrl +
        '" width="' +
        75 +
        '" height="' +
        75+
        '"/>' + 
          '<\/a>';
          
         /* + title */
  
    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) {
        if(window.location.href.indexOf("en/") !=-1)
            leftImage.src = "/img/en/left-enabled.gif";        
        else
            leftImage.src = "/img/left-enabled.gif";        
    } else {
            leftImage.src = "/img/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) {
        if(window.location.href.indexOf("en/") != -1)
            rightImage.src = "/img/en/right-enabled.gif";    
        else
            rightImage.src = "/img/right-enabled.gif";    
    } else {
        rightImage.src = "/img/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;
var pageLoad = function() 
{
    carousel = new YAHOO.extension.Carousel("dhtml-carousel", 
        {
            numVisible:        5,
            animationSpeed:    .8,
            animationMethod:   YAHOO.util.Easing.easeBoth,
            scrollInc:         5,
            navMargin:         -7,
            size:              imageList.length,
            loadInitHandler:   loadInitialItems,
            prevElement:       "prev-arrow",
            nextElement:       "next-arrow",
            loadNextHandler:   loadNextItems,
            loadPrevHandler:   loadPrevItems,
            prevButtonStateHandler:   handlePrevButtonState,
            nextButtonStateHandler:   handleNextButtonState
           /* wrap: true */
        }
    );
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);

if (!window.console || !console.firebug)
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

function showImg(url) {
    document.getElementById('showImage').src = url.replace("thumb","img");
}



