var imageCycler = {
	
	'paths': ["/user_files/image_cycler/stratfordcycler.jpg","/user_files/image_cycler/waterparkcycler.jpg","/user_files/image_cycler/switchcycler.jpg","/user_files/image_cycler/crewcycler.jpg","/user_files/image_cycler/mmitpcycler-001.jpg","/user_files/image_cycler/holeinonecycler.jpg","/user_files/image_cycler/5cycler.jpg"],
	'links': ["/section/view/weekend_giveaways/1123/","/contests/view/contest/1112/big_splash_waterpark_party","/contests/view/contest/1132/the_switch_movie_premiere","/shows/view/?fShowId=6","/section/view/mmitp/1065/","/section/view/hole_in_one_tour/1014/","/shows/view/5_o_clock_favourite/501/"],
	'times': ["5","5","5","5","5","5","5"],	
	'target': ["_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>';
		
		document.getElementById("imageCyclerImageContainer").innerHTML = innerHTMLText;
	
		//Highlight the current image.
		document.getElementById("menuButton_" + this.currentImage).style.background = '#909090';	
		document.getElementById("menuButton_" + t).style.background = '#D0D0D0';
	
		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(); };
