/**
 * Image src URLs
 **/
var imageList = [
				 "images/stories/destaques/01.jpg",
				 "images/stories/destaques/02.jpg",
				 "images/stories/destaques/03.jpg",
				 "images/stories/destaques/04.jpg",
				 "images/stories/destaques/05.jpg",
				 "images/stories/destaques/06.jpg",
				 "images/stories/destaques/07.jpg",
				 "images/stories/destaques/08.jpg",
				 "images/stories/destaques/09.jpg" 

				 ];
var urlList = [
					 		"index.php?option=com_content&view=article&id=96:acepran-02&catid=47:produtos&Itemid=96",				"index.php?option=com_content&view=article&id=100:aminomix-forte&catid=47:produtos&Itemid=96",				"index.php?option=com_content&view=article&id=102:aminomix-haras&catid=47:produtos&Itemid=96",				"index.php?option=com_content&view=article&id=124:enterex&catid=47:produtos&Itemid=96",			 "index.php?option=com_content&view=article&id=126:e-s-e-super&catid=47:produtos&Itemid=96",			"index.php?option=com_content&view=article&id=129:ginovet&catid=47:produtos&Itemid=96",				"index.php?option=com_content&view=article&id=134:hemolitan&catid=47:produtos&Itemid=96",				"index.php?option=com_content&view=article&id=137:hipervit&catid=47:produtos&Itemid=96",
				 
				 ];

var title = [
				 "Acepran",
				 "Aminomix Forte",
				 "Aminomix Haras",
				 "Enterex",
				 "E-S-E Super",
				 "Ginovet",
				 "Hemolitan",
				 "Hipervit",
				 "MODULO IMGSCROLL",
				 "MODULO IMGSCROLL"
				 
				 ];


/**
 * 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 alt="'+ title +'" title="'+ title +'" src="' + 
  		imgUrl +
		'" width="' +
		90 +
		'" height="' +
		88+
		'"/>		<\/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++) {
		var img=i;
		img--;
		carousel.addItem(i, fmtItem(imageList[i-1], urlList[i-1], title [img]));
	}
};



/**
 * 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 = "modules/mod_imgscroll/images/left-disabled.gif";		
	} else {
		leftImage.src = "modules/mod_imgscroll/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 = "modules/mod_imgscroll/images/right-disabled.gif";	
	} else {
		rightImage.src = "modules/mod_imgscroll/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:        4,
			animationSpeed:    0.4,
			animationMethod:   YAHOO.util.Easing.easeBoth,
			scrollInc:         3,
			navMargin:         40,
			size:              9, 	//Numero de Imagens
			loadInitHandler:   loadInitialItems,
			prevElement:     "prev-arrow",
			nextElement:     "next-arrow",
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
			
		}
	);
};

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