var imageCycler = {

	'paths': ["/user_files/image_cycler/2-leadership_calgary_with_ball.jpg","/user_files/image_cycler/2c-tree_planting_windsor-essex.jpg","/user_files/image_cycler/leadership_calgary_team.jpg","/user_files/image_cycler/93-ropes_team_building_windsor-essex.jpg","/user_files/image_cycler/class_of_07_on_slant.jpg","/user_files/image_cycler/lwb_retreat_2007_2.jpg","/user_files/image_cycler/9-from_above_class_in_horseshoe1.jpg","/user_files/image_cycler/lwb_retreat_20071.jpg","/user_files/image_cycler/2b-leadership_calgary_singing.jpg","/user_files/image_cycler/4-vss-barry_posner.jpg","/user_files/image_cycler/3-musical_chairs_on_laps_4.jpg","/user_files/image_cycler/92-summit_2007_group_photo_1.jpg","/user_files/image_cycler/class_of_2008_at_opening_session.jpg"],
	'links': ["","","","","","","","","","","","",""],
	'times': ["3","3","3","3","3","3","3","3","3","3","3","3","3"],
	'target': ["_blank","_blank","_blank","_blank","_blank","_blank","_blank","_blank","_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>';

		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(); };
