/**
 * 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, title_real) {
	var innerHTML = '<a '+ url + '  class="photo_thumb"><img src="' + imgUrl + '"  alt="' + title_real + '" title="' + title_real + '" />' + title + '<\/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 loadInitialItems = function(type, args) {

    var start = args[0];
    var last = args[1]; 

    load(this, start, last);    
	//brightenOrDim(this);

	var status = start + " / " + Math.ceil(this.getProperty("size") / this.getProperty("scrollInc"));
    YAHOO.util.Dom.get("indicator").innerHTML = status;
};

var animComplete = function(type, args) {
    var direction = args[0]; // string either: 'next' or 'prev'
    
    var status = Math.ceil((this.getFirstVisible()+this.getProperty("scrollInc")-1)/this.getProperty("scrollInc")) + " / " + Math.ceil(this.getProperty("size") / this.getProperty("scrollInc"));
    YAHOO.util.Dom.get("indicator").innerHTML = status;
};

/**
 * 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);
    }
	//brightenOrDim(this);
};

/**
 * 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);
    }
	//brightenOrDim(this);
};

/*
var brightenOrDim = function(carousel) {
	var firstItemRevealed=carousel.getFirstItemRevealed();
	var lastItemRevealed=carousel.getLastItemRevealed();
	var firstVisible = carousel.getProperty("firstVisible");
	var lastVisible = carousel.getLastVisible();
		
	var first = (firstItemRevealed == -1) ? firstVisible : firstItemRevealed;
	var last = (lastItemRevealed == -1) ? lastVisible : lastItemRevealed;
	
	for(var i=first; i<=last; i++) {
		var li = carousel.getItem(i);
		if(li) {
			if(i == firstItemRevealed || i==lastItemRevealed) {
				YAHOO.util.Dom.replaceClass(li, "bright", "dim");
			} else {
				YAHOO.util.Dom.replaceClass(li, "dim", "bright");
			}
		}
	}
	
};


var load = function(carousel, start, last) {
	var numVisible = carousel.getProperty("size");
    for(var i=start; i<=last; i++) {
		carousel.addItem(i, fmtItem(imageList[i-1], urlList[i], " "), "bright");
	}
};
var numVisible = (carousel.getLastItemRevealed()-1)/carousel.getProperty("numVisible");
*/

var preveri = function isDefined(variable)
{
	return (!(!(document.getElementById(variable))))
}

var load = function(carousel, start, last) {
	var numVisible = carousel.getProperty("size");
    for(var i=start; i<=last; i++) {
    	if(altList[i-1]!=0){
    		var test = altList[i-1];
    	}else var test="bookingpoint";	
       //carousel.addItem(i, fmtItem(imageList[i-1], urlList[i], '<div>' + i + ' / ' + numVisible + '</div>', test));
	}
};
//carousel.addItem(i, fmtItem(imageList[i-1], urlList[i], '<div>' + i + ' / ' + numVisible + '</div>', test));		


/**
 * 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 = "/images/design/pagination_left_on.jpg";        
    } else {
        leftImage.src = "/images/design/pagination_left_off.jpg";    
    }
    
}

/**
 * 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 = "/images/design/pagination_right_on.jpg";    
    } else {
        rightImage.src = "/images/design/pagination_right_off.jpg";
    }
    
};

var carousel; // for testing