// JavaScript Document
function Carousel()
{
	
	this.carouselDiv = "Not set";
	this.spotlightDiv = "Not set";
	
	this.imageSource = new Array();
	this.imageLink = new Array();
	this.imageText = new Array();
	this.imageThumbnail = new Array();

	this.imageSource.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/zerotofivelogo1.jpg");
	this.imageLink.push("www.cincyschoolzone.com/subindex/daycare/daycare_news");
	this.imageThumbnail.push("http://media2.cincyschoolzone.com//photo/2011/12/05/zero_to_five_image_20111205095942_82_61.JPG");
	this.imageText.push("Zero to Five: Why early learning matters");

	this.imageSource.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/FreshmenAdvice.jpg");
	this.imageLink.push("www.cincyschoolzone.com/dpp/colleges_universities/college_news/College-tips-for-incoming-freshman");
	this.imageThumbnail.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/tnFreshmenAdvice.jpg");
	this.imageText.push("College Tips for Freshmen");

	this.imageSource.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/buyschool.jpg");
	this.imageLink.push("www.cincyschoolzone.com/dpp/colleges_universities/college_news/college-bound-2011%3A-what-to-buy%3F-where-to-buy%3F");
	this.imageThumbnail.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/tncollege.jpg");
	this.imageText.push("College Bound: What to buy, where to buy");

	this.imageSource.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/schoolfashion.jpg");
	this.imageLink.push("www.cincyschoolzone.com/dpp/news/Neon%2C-animal-prints%2C-plaids-and-academic-chic-are-all-in");
	this.imageThumbnail.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/tnfashion.jpg");
	this.imageText.push("Back to school fashions");

	this.imageSource.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/schoolfood.jpg");
	this.imageLink.push("www.cincyschoolzone.com/dpp/news/school-zone-9%3A-healthy-lunches");
	this.imageThumbnail.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/tncafeteria.jpg");
	this.imageText.push("Healthy School Food");
	
	this.imageSource.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/Search1.jpg");
	this.imageLink.push("www.cincyschoolzone.com/subindex/elementary_middle/elementary_search?state=oh");
	this.imageThumbnail.push("http://media2.cincyschoolzone.com/html/widgets/ImageLibrary/Carousel/tnSearch.jpg");
	this.imageText.push("2011 Schools Guide Search");
	
	//this.imageSource.push("/sites/cncsz/images/slideshow//Elementary.jpg");
	//this.imageLink.push("www.cincyschoolzone.com/content/elementary-search/default.aspx??gradesServed=elementary");
	//this.imageThumbnail.push("/sites/cncsz/images/slideshow//tnElementary.jpg");
	//this.imageText.push("How Does Your School Stack Up?");
	
	this.currentImage = -1;
	this.numberOfImages = this.imageSource.length;

}

Carousel.prototype = {
	
	constructor : Carousel,
	
	setCarouselDiv : function (value) 
	{
		
		this.carouselDiv = value;
		
	},
	
	getCarouselDiv : function ()
	{
		
		return this.carouselDiv;
		
	},
	
	setSpotlightDiv : function (value) 
	{
		
		this.spotlightDiv = value;
		
	},
	
	getSpotlightDiv : function ()
	{
		
		return this.spotlightDiv;
		
	},
	
	getElement : function(id)
	{
		
		if (document.getElementById)
		{
			
			return document.getElementById(id);
			
		}
		else if (document.all)
		{
			
			return document.all[id];
			
		}
		else
		{
			
			throw new Error("No way to retrieve the element " + id);
			
		}
		
	},
	
	render : function ()
	{
		
		this.currentImage += 1;
		if (this.currentImage > this.numberOfImages - 1)
		{
			
			this.currentImage = 0;
			
		}
		
		var _carouselContainer = this.getElement(this.carouselDiv);
		var _spotlightContainer = this.getElement(this.spotlightDiv);
		
		_carouselContainer.innerHTML = 
			"<a href=\"http://" + this.imageLink[this.currentImage] + "\">"		
			+ "<image id=\"moveableImage\" style=\"width:607px;\" src=\"" + this.imageSource[this.currentImage] + "\" alt=\"Image\" />"
			+ "</a>";
			
		var _previousImage = this.currentImage - 1;
		if (_previousImage < 0)
		{
		
			_previousImage = this.numberOfImages - 1;
			
		}

		var _nextImage = this.currentImage + 1;
		if (_nextImage > this.numberOfImages - 1)
		{
			
			_nextImage = 0;
		
		}
		
		var _nextNextImage = _nextImage + 1;
		if (_nextNextImage > this.numberOfImages - 1)
		{
			
			_nextNextImage = 0;
		
		}
		
		_spotlightContainer.innerHTML =
			"<table><tr>" 
			+ "<td style=\"background-color:#ffffff;\">"
			+ "<a href=\"javascript:slideShow.renderPrevious();\"><</a>"
			+ "</td>" 
			+ "<td>"
			+ "<a href=\"http://" + this.imageLink[this.currentImage] + "\">"		
			+ "<img src=\"" + this.imageThumbnail[this.currentImage] + "\" alt=\"Image\" class=\"spotlightImageCurrent\" />"
			+ "</a>"
			+ "</td>" 
			+ "<td>"
			+ "<span class=\"spotlightImageText\">" + this.imageText[this.currentImage] + "</span>"
			+ "</td>"
			+ "<td>"
			+ "<a href=\"http://" + this.imageLink[_nextImage] + "\">"		
			+ "<img src=\"" + this.imageThumbnail[_nextImage] + "\" style=\"border=2px;\" alt=\"Image\" class=\"spotlightImage\" />"
			+ "</a>"
			+ "</td>" 
			+ "<td>"
			+ "<span class=\"spotlightImageText\">" + this.imageText[_nextImage] + "</span>"
			+ "</td>"
			+ "<td>"
			+ "<a href=\"http://" + this.imageLink[_nextNextImage] + "\">"		
			+ "<img src=\"" + this.imageThumbnail[_nextNextImage] + "\" alt=\"Image\" class=\"spotlightImage\" />"
			+ "</a>"
			+ "</td>" 
			+ "<td>"
			+ "<span class=\"spotlightImageText\">" + this.imageText[_nextNextImage] + "</span>"
			+ "</td>"
			+ "<td style=\"background-color:#ffffff;\">"
			+ "<a href=\"javascript:slideShow.render();\">></a>"
			+ "</td>" 
			+ "</tr></table>";
			
		var _currentMoveableImage = document.getElementById("moveableImage");
		var _originalSize = _currentMoveableImage.style.width;
		//alert("Width: " + _originalSize);
		for (var looper=1; looper < 607; looper+=1)
		{
			//alert("Left: " + looper);
			_currentMoveableImage.style.left = looper;
		}
			
	},
	
	renderPrevious : function()
	{
			
		this.currentImage = this.currentImage - 2;
		
		if (this.currentImage < 0)
		{
			
			this.currentImage = 0;
			
		}

		this.render();
	
	}
	
};

