	// ----------------- ************************ ----------------- //
	//   DOJO SLIDESHOW - 1.0
	//   writen by Kevin /DOT/ Jaako /AT/ webmedia /DOT/ ee
	//
	// ----------------- ************************ ----------------- //



slideshow = function(vars) { //allow customization through vars

	// ---------------- global variables - set defaults ------------//

	this.automaticSlideshow = (vars["automatic"]) ? vars["automatic"] : 0; //auto advance?

	//times and speeds
	this.slideDuration = (vars["slideDuration"]) ? vars["slideDuration"] : 5000; //length of time each slide is displayed
	this.fastAnimationSpeed = (vars["fastAnimationSpeed"]) ? vars["fastAnimationSpeed"] : 350;
	this.slowAnimationSpeed = (vars["slowAnimationSpeed"]) ? vars["slowAnimationSpeed"] : 1800;

	//DOM elements
	this.slideContainer = (vars["slideContainer"]) ? vars["slideContainer"] : ""; //class of wrapper div of all slides
	this.slideClassName = (vars["slideClassName"]) ? vars["slideClassName"] : ""; //common part of all slide classnames
	this.paginationContainer = (vars["paginationContainer"]) ? vars["paginationContainer"] : "";	//class of wrapper element of pagination links
	this.paginationLink = (vars["paginationLink"]) ? vars["paginationLink"] : "";	//pagination link

	this.timerObj = 0; //object to hold timeout instance
	this.currentSlide = 1; //default to slide 1
	this.numberofSlides = 1; //number of slides (overridden later)

	// --------------------- slideshow methods ----------------------//

	this.buttonPushed = function(buttonID) {
		newSlide = buttonID; //put destination slide into newSlide (override later if "next" or "prev" was pushed)
		switch (buttonID) {
			case "next": //click next button
				newSlide = (this.currentSlide*1 < this.numberofSlides*1) ? newSlide = this.currentSlide*1+1 : newSlide = 1; break;

			case "prev": //click prev button
				newSlide =  (this.currentSlide*1 == 1) ? newSlide = this.numberofSlides : newSlide = this.currentSlide*1-1; break;
			default:
				newSlide = parseInt(newSlide);
		}

		if (newSlide != this.currentSlide) {
			this.animateSlide(newSlide,this.fastAnimationSpeed); //call animateSlide() with newSlide, use fastAnimationSpeed for button presses.
		}
	} // buttonPushed

	// ---------------------------------------

	this.animateSlide = function(slideID,animationSpeed) {
		//perform slideshow animation

		//set new and old slide nodeIDs
		oldSlide = dojo.query(this.slideClassName + this.currentSlide)[0];
		newSlide = dojo.query(this.slideClassName + slideID)[0];

		//set new and old button nodeIDs
		oldButton = dojo.query(this.paginationContainer + this.currentSlide)[0];
		newButton = dojo.query(this.paginationContainer + slideID)[0];

		//do animation
		dojo.fadeOut({node: oldSlide, duration: animationSpeed, onEnd: function(){oldSlide.style.display="none"}}).play();
		dojo.fadeIn({node: newSlide, duration: animationSpeed, onPlay: function(){newSlide.style.display=""}}).play();

		dojo.removeClass(oldButton,"active");
		dojo.addClass(newButton,"active");

		this.currentSlide = slideID; //set currentSlide variable to use new slide

	} // animateSlide

	// ---------------------------------------

	this.slideshowTimer = function() {
		//when the auto-advance timer fires, advance to next slide
		newSlide = (this.currentSlide*1 < this.numberofSlides*1) ? this.currentSlide*1+1 : 1;
		this.animateSlide(newSlide, this.slowAnimationSpeed) //use slowAnimationSpeed for slide auto-advances
	}

 	// ---------------------------------------
	this.pause = function() {
		callback = this;
		clearInterval(callback.timerObj); callback.timerObj = null;
	}
	// ---------------------------------------
	this.play = function() {
		callback = this;
		if (!callback.timerObj) {
			callback.timerObj = setInterval(function(){ callback.slideshowTimer(); }, callback.slideDuration);
		}
	}
	// ---------------------------------------

	this.init = function() {
		//initialize dojo event hooks and set up variables and timers

		callback = this; //setup a callback variable to reference "this" for use inside dojo functions
		currentActive = 1;

		dojo.addOnLoad(function() {		//init dojo when DOM is ready
			slideCount = 1;
			//unhide all slides, set opacites to 0 (but leave slide 1 visible)
			dojo.query(callback.slideContainer + ":not(" + callback.slideClassName + "1)").forEach(function(node, index, arr){
				node.style.display="none";
				dojo.style(node, "opacity", "0");
				dojo.removeClass(node,"hidden");
				slideCount++; //count slides
			});

			callback.numberofSlides = slideCount;

			//set up event hooks for slideshow pagination links
			dojo.query(callback.paginationLink).forEach(function(node, index, arr){
				dojo.connect(node, "onmouseover", function(e) {
					e.preventDefault(); //override default link behavior
					nodeClass = node.parentNode.className; //get buttonID from CSS class of LI element
					buttonPushed = ((nodeClass != "prev") && (nodeClass != "next")) ? nodeClass.split("-")[1] : nodeClass; //don't split prev & next buttons
					callback.buttonPushed(buttonPushed);
				});
				if (callback.automaticSlideshow) { //if automatic slideshow, enable mouseOver/Out pause of slideshow timer
					dojo.connect(node, "onmouseover", function(){ clearInterval(callback.timerObj); callback.timerObj = null });
					dojo.connect(node, "onmouseout", function(){
						if (!callback.timerObj) {
							callback.timerObj = setInterval(function(){ callback.slideshowTimer(); }, callback.slideDuration);
						}
					});
				}
			});

			if (callback.automaticSlideshow) {  //if automatic slideshow, start slideshow timer and enable "read more" pauses
				callback.timerObj = setInterval(function(){ callback.slideshowTimer(); },callback.slideDuration);
				dojo.query(callback.slideContainer + " p.more a").forEach(function(node, index, arr){ //select "read more" links
					dojo.connect(node, "onmouseover", function(e) { clearInterval(callback.timerObj); callback.timerObj = null }); //pause slideshow
					dojo.connect(node, "onmouseout", function(){
						if (!callback.timerObj) {
							callback.timerObj = setInterval(function(){ callback.slideshowTimer(); }, callback.slideDuration); //unpause slideshow
						}
					});
				});
			}

	}); //end dojo addOnLoad
	} // init

// ---------------------------------------
} // end of slideshow object
// ---------------------------------------

