var imageCycler = {

	'paths': ["/user_files/image_cycler/1cyclercult.jpg","/user_files/image_cycler/1icebreaker09.jpg","/user_files/image_cycler/the-elms-river-session.jpg","/user_files/image_cycler/1cyclerrockworkplace.jpg","/user_files/image_cycler/rockblock-new-v2.jpg","/user_files/image_cycler/1rivercurrentnew-001.jpg","/user_files/image_cycler/1cyclerupcoming.jpg","/user_files/image_cycler/av-room-video.jpg"],
	'links': ["http://www.939theriverradio.com/phone_in_contests/view/?display=more&amp;item_id=21","http://www.livenation.com/edp/eventId/413419","http://www.939theriverradio.com/section/view/the_elms_river_session/112/","http://www.939theriverradio.com/section/view/rockthe_workplace/72/","mailto:youshouldplaythis@939theriverradio.com","/section/view/?fnode=45","http://www.939theriverradio.com/section/view/upcoming_roadie_events/44/","http://www.939theriverradio.com/sound_bytes/view/category/videos_from_our_listeners/6/"],
	'times': ["3","3","4","3","3","2","2","3"],
	'target': ["_top","_top","_top","_top","_blank","_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(); };
