/**
 * Image src URLs
 **/


var imageList = ["/images/Panna_Cotta.jpg","/images/Roasted_Asparagus.jpg","/images/Balsamic_vinigrette.jpg","/images/Shrimp_Fresh_TomatoPasta.jpg","/images/recipe_summer_succotash.jpg","/images/recipe_fried_green_tomato.jpg","/images/recipe_fresh_corn_salad.jpg","/images/recipe_yellow_squash_stuffed.jpg","/images/food_key_lime_cake.jpg","/images/recipe_stuffed_chicken_goat_cheese.jpg"];

var urlList = ["http://tnhomeandfarm.com/index.php/site/recipes/transferdesserts/panna_cotta","http://tnhomeandfarm.com/index.php/site/recipes/transferside_dishes/roasted_asparagus","http://tnhomeandfarm.com/index.php/site/recipes/transfersoups_and_salads/balsamic_vinaigrette","http://tnhomeandfarm.com/index.php/site/recipes/transferentrees/shrimp_and_fresh_tomato_pasta","http://tnhomeandfarm.com/index.php/site/recipes/transferside_dishes/summer_succotash","http://tnhomeandfarm.com/index.php/site/recipes/transferside_dishes/fried_green_tomatoes","http://tnhomeandfarm.com/index.php/site/recipes/transfersoups_and_salads/fresh_corn_salad","http://tnhomeandfarm.com/index.php/site/recipes/transferside_dishes/garden_stuffed_yellow_squash","http://tnhomeandfarm.com/index.php/site/recipes/transferdesserts/key_lime_cake","http://tnhomeandfarm.com/index.php/site/recipes/transferentrees/stuffed_chicken_breasts_with_spinach_goat_cheese_and_sun_dried_tomatoes"];
				 
var titleList = ["Panna Cotta","Roasted Asparagus","Balsamic Vinaigrette","Shrimp and Fresh Tomato Pasta","Summer Succotash","Fried Green Tomatoes","Fresh Corn Salad","Garden-Stuffed Yellow Squash","Key Lime Cake","Stuffed Chicken Breasts with Spinach, Goat Cheese, and Sun-Dried Tomatoes"];

/**
 * 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 + 
  		'" target="_blank"><img src="http://tnhomeandfarm.com/_functions/phpthumb/phpThumb.php?src=' + 
  		imgUrl +
		'&w=120&h=150&zc=T" />' + 
  		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 loadInitialItems2 = 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 loadNextItems2 = 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 loadPrevItems2 = function(type, args) {
	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
};

var load = function(carousel2, start, last) {
	for(var i=start; i<=last; i++) {
		carousel2.addItem(i, fmtItem(imageList[i-1], urlList[i-1], titleList[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 handlePrevButtonState2 = function(type, args) {
	var enabling = args[0];
	var leftImage = args[1];
	if(enabling) {
		leftImage.src = "http://tnhomeandfarm.com/images/left-enabled.gif";		
	} else {
		leftImage.src = "http://tnhomeandfarm.com/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 handleNextButtonState2 = function(type, args) {
	var enabling = args[0];
	var rightImage = args[1];
	if(enabling) {
		rightImage.src = "http://tnhomeandfarm.com/images/right-enabled.gif";	
	} else {
		rightImage.src = "http://tnhomeandfarm.com/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 carousel2; // for testing
var pageLoad2 = function() 
{
	carousel2 = new YAHOO.extension.Carousel2("dhtml-carousel2", 
		{
			numVisible:        3,
			animationSpeed:    0.75,
			animationMethod:   YAHOO.util.Easing.easeBoth,
			scrollInc:         1,
			navMargin:         50,
			size:              10,
			revealAmount:      25,
			loadInitHandler:   loadInitialItems2,
			prevElement:       "prev-arrow2",
			nextElement:       "next-arrow2",
			loadNextHandler:   loadNextItems2,
			loadPrevHandler:   loadPrevItems2,
			prevButtonStateHandler:   handlePrevButtonState2,
			nextButtonStateHandler:   handleNextButtonState2,
			wrap: true,
			firstVisible: 1
		}
	);
};

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