
var imageList = [
				 "producatori/acer.jpg",
				 "producatori/cobra.jpg",
				 "producatori/giorgio-armani.jpg",
				 "producatori/asus.jpg",
				 "producatori/whistler.jpg",
				 "producatori/benq.jpg",
				 "producatori/canon.jpg",
				 "producatori/lg.jpg",
				 "producatori/mio.jpg",
				 "producatori/pqi.jpg",
				 "producatori/logitech.jpg",
				 "producatori/western-digital.jpg",
				 "producatori/kingmax.jpg",
				 "producatori/casio.jpg",
				 "producatori/amd.jpg",
				 "producatori/dell.jpg",
				 "producatori/proview.jpg",
				 "producatori/spire.jpg"
				 ];
var urlList = [
				 "magazine-online-preturi-produse-acer.html",
				 "magazine-online-preturi-produse-cobra.html",
				 "magazine-online-preturi-produse-giorgio-armani.html",
				 "magazine-online-preturi-produse-asus.html",
				 "magazine-online-preturi-produse-whistler.html",
				 "magazine-online-preturi-produse-benq.html",
				 "magazine-online-preturi-produse-canon.html",
				 "magazine-online-preturi-produse-lg.html",
				 "magazine-online-preturi-produse-mio.html",
				 "magazine-online-preturi-produse-pqi.html",
				 "magazine-online-preturi-produse-logitech.html",
				 "magazine-online-preturi-produse-western-digital.html",
				 "magazine-online-preturi-produse-kingmax.html",
				 "magazine-online-preturi-produse-casio.html",
				 "magazine-online-preturi-produse-amd.html",
				 "magazine-online-preturi-produse-dell.html",
				 "magazine-online-preturi-produse-proview.html",
				 "magazine-online-preturi-produse-spire.html",
				 ];
				 


/**
 * 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 +
		'" />' + 
  		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);	
};

/**
 * 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], urlList[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 = "images/left-enabled.gif";		
	} else {
		leftImage.src = "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 = "images/right-enabled.gif";	
	} else {
		rightImage.src = "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:        5,
			animationSpeed:    0.6,
			animationMethod:   YAHOO.util.Easing.easeBoth,
			scrollInc:         5,
			navMargin:         40,
			size:              17,
			loadInitHandler:   loadInitialItems,
			prevElement:     "prev-arrow",
			nextElement:     "next-arrow",
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);
