var imageCycler = {

	'paths': ["/user_files/image_cycler/camppattersongolffundraisercou.jpg","/user_files/image_cycler/mankatonightoutbeforeyou.gif","/user_files/image_cycler/summerstaycation10cou.jpg","/user_files/image_cycler/peoplezfestwindowcou.jpg","/user_files/image_cycler/joshturnerdonrickles-002.jpg","/user_files/image_cycler/roomsandrest25000cou.jpg","/user_files/image_cycler/ultimatesummerpatiopartiescou-001.jpg","/user_files/image_cycler/blueearthcountyfair10cou.jpg","/user_files/image_cycler/countrygoldlardawg.jpg","/user_files/image_cycler/wefest-001.jpg","/user_files/image_cycler/scootersstoufersautocou.jpg","/user_files/image_cycler/bikenight2010cou-001.jpg","/user_files/image_cycler/calssiccarrollinscou.jpg","/user_files/image_cycler/weddingguide2010cou.jpg","/user_files/image_cycler/swatcountry2.jpg","/user_files/image_cycler/jakesstadiumpizza-002.jpg","/user_files/image_cycler/nodiet-001.jpg","/user_files/image_cycler/3_50_projectcou.jpg","/user_files/image_cycler/diningguideforcountry.jpg"],
	'links': ["/section/view/scramble_golf_fundraiser/194/","http://www.mankatonightout.com/","","/section/view/peoplez_fest/193/","http://www.mysticlake.com/entertainment","/section/view/win_up_to_25_000_dollars_in_cash/192/","/section/view/ultimate_summer_patio_parties/181/","http://www.blueearthcountyfair.org/","/section/view/country_gold/184/","http://www.country103.com/contests/view/","/section/view/register_to_win_a_scooter/188/","/section/view/bike_night/180/","/section/view/classic_car_roll_in_s/178/","/section/view/wedding_guide_2010/170/","/section/view/swat/168/","","/section/view/no_diet/158/","/section/view/3_50_project/126/","http://www.country103.com/section/view/dining_guide/90/"],
	'times': ["5","8","5","5","5","5","5","5","5","5","5","5","5","5","5","5","5","5","10"],
	'target': ["_top","_top","_blank","_top","_blank","_top","_top","_blank","_top","_blank","_top","_top","_top","_top","_top","_top","_top","_top","_top"],
	'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(); };
