
/**
 * Image src URLs
 **/
var serienNamen = new Array();
var zoombilder = new Array();
var bilderlinks = new Array();
var currentSelectedItem;

/**
 * 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,zoombild) {

if(url.length > 0)
{

      var innerHTML = 
		'<div class=\"thumbItem\" style=\"display:none;position:absolute;top:0px;z-index:99;margin-left:expression(\'-39px\');\" onMouseOut=\"this.style.display = \'none\';\"><a rel="ibox" href="#' + url + '" style=\"border: none 0px;\" onClick=\"iBox.handleTag(this);\"><img src=\"' + zoombild +'"\ style=\"border: none 0px;\"></a></div>' +
          '<a href="' + 
          url + '" onMouseOver=\"if(currentSelectedItem) currentSelectedItem.style.display=\'none\';this.parentNode.childNodes[0].style.display=\'block\';currentSelectedItem=this.parentNode.childNodes[0];\">' +
		'<img src="' + 
          imgUrl +
        '"/ >' + 
          title + 
          '<\/a>' ;
} else {
      var innerHTML = 
		'<img src="' + 
          imgUrl +
        '"/ >' + 
          title;
}  
//          '" onMouseOver=\"this.childNodes[0].style.display=\'block\';\" >' + 
//'<div style=\"display:none;background-color:#FF00FF;height:145px;width:77px;position:absolute;left:-0px;top:0px;z-index:99;\"><img src=\"' + zoombild +'"\></div>' +

    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], bilderlinks[i-1], serienNamen[i-1],zoombilder[i-1]));
    }
};



/**
 * 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 = "/fileadmin/templates/carousel/images/left-enabled.gif";        
    } else {
        leftImage.src = "/fileadmin/templates/carousel/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 = "/fileadmin/templates/carousel/images/right-enabled.gif";    
    } else {
        rightImage.src = "/fileadmin/templates/carousel/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 '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:        8,
            animationSpeed:    0.4,
            animationMethod:   YAHOO.util.Easing.easeBoth,
            scrollInc:         6,
            navMargin:         40,
            size:              carSize,
            loadInitHandler:   loadInitialItems,
            prevElement:     "prev-arrow",
            nextElement:     "next-arrow",
            loadNextHandler:   loadNextItems,
            loadPrevHandler:   loadPrevItems,
            prevButtonStateHandler:   handlePrevButtonState,
            nextButtonStateHandler:   handleNextButtonState
        }
    );
};

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

