/**
 * Image src URLs
 **/
myImage = function (thumbUrl, url, title, summary)
{
	this.thumbUrl = thumbUrl;
	this.url = url;
	this.title = title;
	this.summary = summary;
};

var imgRockGardenList = [
		new myImage	(
					"images/thumb/jcb and boulder.jpg",
					"images/jcb and boulder.jpg",
					"1986",
					""),
		new myImage	(
					"images/thumb/IMGP0744.jpg",
					"images/IMGP0744.jpg",
					"May",
					""),
		new myImage	(
					"images/thumb/Polystichum.gif",
					"images/Polystichum.gif",
					"Polystichum setiferum",
					""),
		new myImage	(
					"images/thumb/IMG_1267.jpg",
					"images/IMG_1267.jpg",
					"August",
					""),
		new myImage	(
					"images/thumb/IMG_1266.jpg",
					"images/IMG_1266.jpg",
					"Rhododendrom & Cornus",
					""),
		new myImage	(
					"images/thumb/Weba.jpg",
					"images/Weba.jpg",
					"April",
					""),
		new myImage	(
					"images/thumb/Web7.jpg",
					"images/Web7.jpg",
					"July",
					"")			
		];
var imgCottageGardenList = [
		new myImage	(
					"images/thumb/Euphorbia.jpg",
					"images/Euphorbia.jpg",
					"March",
					""),
		new myImage	(
					"images/thumb/IMGP0767.jpg",
					"images/IMGP0767.jpg",
					"May",
					""),
		new myImage	(
					"images/thumb/Web4.jpg",
					"images/Web4.jpg",
					"July",
					""),
		new myImage	(
					"images/thumb/IMG_1281.jpg",
					"images/IMG_1281.jpg",
					"August",
					"")
		];
var imgFrontGardenList = [
		new myImage	(
					"images/thumb/732 RECTANGLE 2.jpg",
					"images/732 RECTANGLE 2.jpg",
					"April",
					""),
		new myImage	(
					"images/thumb/IMG_1278.jpg",
					"images/IMG_1278.jpg",
					"August",
					""),
		new myImage	(
					"images/thumb/IMG_1280.jpg",
					"images/IMG_1280.jpg",
					"August",
					""),
		new myImage	(
					"images/thumb/IMG_1284.jpg",
					"images/IMG_1284.jpg",
					"August",
					"")
		];
var imgWildFlowerMeadowList = [
		new myImage	(
					"images/thumb/cowslip new.jpg",
					"images/cowslip new.jpg",
					"Cowslip",
					""),
		new myImage	(
					"images/thumb/2006-08-11-001.jpg",
					"images/2006-08-11-001.jpg",
					"Harebells",
					""),
		new myImage	(
					"images/thumb/2006-08-11-003.jpg",
					"images/2006-08-11-003.jpg",
					"Knapweed",
					""),
		new myImage	(
					"images/thumb/2006-08-11-005.jpg",
					"images/2006-08-11-005.jpg",
					"Ox-eye daisy",
					"")
		];
var imgSitooterieList = [
		new myImage	(
					"images/thumb/New_Garden_0803.jpg",
					"images/New_Garden_0803.jpg",
					"July",
					""),
		new myImage	(
					"images/thumb/Easter_024.jpg",
					"images/Easter_024.jpg",
					"Helleborus orientalis",
					""),
		new myImage	(
					"images/thumb/IMG_1286.jpg",
					"images/IMG_1286.jpg",
					"August",
					""),
		new myImage	(
					"images/thumb/2006-08-11-009.jpg",
					"images/2006-08-11-009.jpg",
					"August",
					""),
		new myImage	(
					"images/thumb/Webb.jpg",
					"images/Webb.jpg",
					"August 2002",
					"")
		];
var imgHerbGardenList = [
		new myImage	(
					"images/thumb/Web3.jpg",
					"images/Web3.jpg",
					"July",
					""),
		new myImage	(
					"images/thumb/Web5.jpg",
					"images/Web5.jpg",
					"July",
					""),
		new myImage	(
					"images/thumb/Web8.jpg",
					"images/Web8.jpg",
					"August",
					""),
		new myImage	(
					"images/thumb/IMG_1282.jpg",
					"images/IMG_1282.jpg",
					"August",
					"")
		];
var imgVegetableGardenList = [
		new myImage	(
					"images/thumb/Web11.jpg",
					"images/Web11.jpg",
					"June",
					""),
		new myImage	(
					"images/thumb/Web9.jpg",
					"images/Web9.jpg",
					"White currant",
					""),
		new myImage	(
					"images/thumb/Web10.jpg",
					"images/Web10.jpg",
					"July",
					""),
		new myImage	(
					"images/thumb/IMGP1673.jpg",
					"images/IMGP1673.jpg",
					"August",
					"")
		];
/**
 * 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(img) {

  	/*
  	var innerHTML = 
  		'<a href="#" ' +
  		'onclick="window.open(&#39'+img.url+'&#39,&#39;f2p&#39;,&#39;scrollbars=yes,resizable=yes,width='+img.width+',height='+img.height+'&#39;);return false;"' +
  		'><img src="' + 
  		img.thumbUrl +
		'" width="' +
		75 +
		'" height="' +
		75+
		'"/>' + 
  		img.title + 
  		'</a>' +
  		img.summary;
  	*/
  	var innerHTML = 
  		'<a href="'+img.url+'" ' +
  		'rel="lightbox" ' + 
  		'><img src="' + 
  		img.thumbUrl +
		'" width="' +
		75 +
		'" height="' +
		75+
		'"/>' + 
  		img.title + 
  		'</a>' +
  		img.summary;
  	
  	//alert (innerHTML); 	
  	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++) {
		switch (carousel.carouselElemID) {
			case "dhtml-carousel":
				if (imgWildFlowerMeadowList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgWildFlowerMeadowList[i - 1]));
				}
				break;
			case "dhtml-carousel2":
				if (imgCottageGardenList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgCottageGardenList[i - 1]));
				}
				break;
			case "dhtml-carousel3":
				if (imgHerbGardenList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgHerbGardenList[i - 1]));
				}
				break;
			case "dhtml-carousel4":
				if (imgFrontGardenList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgFrontGardenList[i - 1]));
				}
				break;
			case "dhtml-carousel5":
				if (imgSitooterieList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgSitooterieList[i - 1]));
				}
				break;
			case "dhtml-carousel6":
				if (imgRockGardenList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgRockGardenList[i - 1]));
				}
				break;
			case "dhtml-carousel7":
				if (imgVegetableGardenList[i - 1] != null) {
					carousel.addItem(i, fmtItem(imgVegetableGardenList[i - 1]));
				}
				break;
		}
	}
	initLightbox();
};

var getRandom = function(max, last) {
	var randomIndex;
	do {
		randomIndex = Math.floor(Math.random()*max);
	} while(randomIndex == last);
	
	return randomIndex;
};

/**
 * 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 pageLoad = function() 
{
	var carouselFlowerMeadow = new YAHOO.extension.Carousel("dhtml-carousel", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 4,
			prevElementID:     "left-arrow",
			nextElementID:     "right-arrow",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	var carouselCottageGarden = new YAHOO.extension.Carousel("dhtml-carousel2", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 3,
			prevElementID:     "left-arrow2",
			nextElementID:     "right-arrow2",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	var carouselHerbGarden = new YAHOO.extension.Carousel("dhtml-carousel3", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 4,
			prevElementID:     "left-arrow3",
			nextElementID:     "right-arrow3",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	var carouselFrontGarden = new YAHOO.extension.Carousel("dhtml-carousel4", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 4,
			prevElementID:     "left-arrow4",
			nextElementID:     "right-arrow4",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	var carouselSitooterie = new YAHOO.extension.Carousel("dhtml-carousel5", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 5,
			prevElementID:     "left-arrow5",
			nextElementID:     "right-arrow5",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	var carouselRockGarden = new YAHOO.extension.Carousel("dhtml-carousel6", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 7,
			prevElementID:     "left-arrow6",
			nextElementID:     "right-arrow6",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	var carouselVegetableGarden = new YAHOO.extension.Carousel("dhtml-carousel7", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size:							 4,
			prevElementID:     "left-arrow7",
			nextElementID:     "right-arrow7",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}		
	);
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);