var imageCycler = {

	'paths': ["/user_files/image_cycler/zero_tolerance.jpg","/user_files/image_cycler/disneyice2010.jpg","/user_files/image_cycler/travis-tritt.jpg","/user_files/image_cycler/elite_8.jpg","/user_files/image_cycler/family_of_fans.jpg","/user_files/image_cycler/ms_walk.jpg","/user_files/image_cycler/pony_express.jpg","/user_files/image_cycler/george_jones.jpg","/user_files/image_cycler/untitled-1-001.jpg","/user_files/image_cycler/honorflight.jpg"],
	'links': ["http://www.zerotolerancefights.com/","http://www.sprintcenter.com/default.asp?id=87&amp;objid=652","http://www.ticketmaster.com/event/06004443A64E912D?artistid=732965&amp;majorcatid=10001&amp;minorcatid=2","http://www.ncaa.com/sports/w-baskbl/champpage/w-baskbl-div2-index.html","/section/view/family_of_fans/76/","http://nationalmssociety.org/chapters/walk-ms-mid-america/index.aspx","http://www.ponyexpress.org/index.php?page=buffalo-bill-contest","http://www.click-to-enter.info/contest//contest.php?id=7892403290001057ce05276e1b29b0a9","http://www.countrystampede.com/","http://www.honorflightkc.com/"],
	'times': ["5","5","5","5","5","5","5","5","5","5"],
	'target': ["_blank","_blank","_blank","_blank","_top","_blank","_blank","_blank","_blank","_blank"],
	'currentImage': 0,
	'currentTimeout': false,
	'init': function() {

		var image = new Image();
		for (var i=0; i<this.paths.length; i++){
			image.src = this.paths[i];
		}

		this.changeImage(0,false);

	},
	'changeImage': function(t,realClick) {
		var innerHTMLText 		= '';

		if (this.links[t] != '') innerHTMLText += '<a href="' + this.links[t] + '" target="' + this.target[t]  + '">';
		innerHTMLText += '<img src="' + this.paths[t] + '" class="imageCyclerImage">';
		if (this.links[t] != '') innerHTMLText += '</a>';
		
		//Fix the double '?' caused by output_add_rewrite_var(), simply search for ?session and replace with &session
		innerHTMLText	= innerHTMLText.replace('?session','&session');

		document.getElementById("imageCyclerImageContainer").innerHTML = innerHTMLText;

		//Highlight the current image.
		document.getElementById("menuButton_" + this.currentImage).className = "menuButton";
		document.getElementById("menuButton_" + t).className = "menuButton current";

		this.currentImage = t;

		if( this.currentImage+1 <= this.paths.length - 1 && !realClick) {
			this.currentTimeout = window.setTimeout('imageCycler.changeImage(' + parseInt(this.currentImage+1) + ',false)', this.times[this.currentImage] * 1000);
		} else if( this.currentImage == this.paths.length - 1 ) {	// Start the cycle again
			this.currentTimeout = window.setTimeout('imageCycler.changeImage(0,false)', this.times[0] * 1000);
		}

	},
	'selectImage': function (t) {

		this.changeImage(t,true);
		window.clearTimeout(this.currentTimeout);

	},
	'prevImage': function () {

		if( this.currentImage-1 >= 0) {
			this.changeImage(this.currentImage-1,true);
		} else	{
			this.changeImage(this.paths.length-1,true);
		}

		window.clearTimeout(this.currentTimeout);

	},
	'nextImage': function () {

		if( this.currentImage+1 <= this.paths.length - 1) {
			this.changeImage(this.currentImage+1,true);
		} else {
			this.changeImage(0,true);
		}

		window.clearTimeout(this.currentTimeout);

	}

}

window.onload = function() { imageCycler.init(); };
