var lastRan = -1;

var fmtItem2 = function(text, url, index) {

      var innerHTML = 
          '<div id="text-wussten' + index + '" style="width:260px; height:68px;  line-height:16px; text-align:left; color:#666666; font-size:11px;">' + 
          text +'</div>';
  /*
  
   var innerHTML = 
          '<a id="dhtml-carousel-a-'+index+'" href="' + 
          url + 
          '"><div id=""><img id="dhtml-carousel-img-' + index + '" src="' + 
          imgUrl +
        '" width="' +
        468 +
        '" height="' +
        264+
        '"/>' + 
          title + 
          '</div><\/a>';
  */
    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 loadInitialItems2 = function(type, args) {

    var start = args[0];
    var last = args[1]; 

    load2(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 loadNextItems2 = function(type, args) {    

    var start = args[0];
    var last = args[1]; 
    var alreadyCached = args[2];
    
    if(!alreadyCached) {
        load2(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 loadPrevItems2 = function(type, args) {
    var start = args[0];
    var last = args[1]; 
    var alreadyCached = args[2];
    
    if(!alreadyCached) {
        load2(this, start, last);
    }
};

var load2 = function(carousel2, start, last) {
    for(var i=start;i<=last;i++) {
        var liItem2 = carousel2.addItem(i, fmtItem2(textList[i], "#", i));
/*
        // If you want to add handlers for mouse over, mouse out or other events,
        // here is the pattern
        YAHOO.util.Event.addListener(liItem, "mouseover", function(e) {
        //console.log("mouseover>>"+this.id);
        });
        YAHOO.util.Event.addListener(liItem, "mouseout", function(e) {
            //console.log("mouseout<<"+this.id);
        });
*/
    }
}

/**
 * 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 handlePrevButtonState2 = function(type, args) {

    var enabling = args[0];
    var leftImage = args[1];
    if(enabling) {
        leftImage.src = "prev_o.png";    
    } else {
        leftImage.src = "prev_o.png";
    }
    
};

var carousel2; // for ease of debugging; globals generally not a good idea

/**
 * 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 pageLoad2 = function() 
{
    carousel2 = new YAHOO.extension.Carousel("dhtml-carousel2", 
        {
            numVisible:        1,
            animationSpeed:   0.7,
            scrollInc:         1,
            navMargin:         0,
            prevElement:     "prev-arrow2",
            nextElement:     "next-arrow2",
            loadInitHandler:   loadInitialItems2,
            loadNextHandler:   loadNextItems2,
            loadPrevHandler:   loadPrevItems2,
            prevButtonStateHandler:   handlePrevButtonState2,
            autoPlay: 6000,
            size:5,
            wrap:true
        }
    );
    

};


/**
 * Illustrates stop autoplay
 */
var stopAutoPlay2 = function(e) {
    YAHOO.util.Dom.get("status").innerHTML = "Auto Play Stopped!";
    carousel2.stopAutoPlay2();
};

/**
 * Illustrates start autoplay
 */
var startAutoPlay2 = function(e) {
    YAHOO.util.Dom.get("status").innerHTML = "Auto Play Started!";
    carousel2.startAutoPlay2(2000);
};

YAHOO.util.Event.addListener(window, 'load', pageLoad2);
/*YAHOO.util.Event.addListener("stop-button", 'click', stopAutoPlay);
YAHOO.util.Event.addListener("start-button", 'click', startAutoPlay);*/

