/* 	slideshow script 
	written by Mark Whitcher of AnIdea, LLC
	see us at www.anideaweb.com
	copyright ©2007 by Mark Whitcher
*/
var length_of_time_each_image_will_appear = 4.0;	/* How long each image should be displayed */


/* DO NOT CHANGE ANYTHING BELOW THIS POINT */
var settings = new Object;
settings.show_length = length_of_time_each_image_will_appear
var images = new Object


function startShow() {
	images.items = $('slideshow').getChildren();
	images.items.each(function(item,index) {
		if(index != 0) {item.fade('hide');}
	})
	images.position = 0
	images.previous_position = images.items.length - 1
	images.next_position = function() {
		var position = this.position + 1
		if (position >= this.items.length) {
			position = 0
		}
		return position
	}
	images.current_image = function() {return this.items[this.position]}
	images.next_image = function() {return this.items[this.next_position()]}
	images.set_next = function() {this.previous_position = this.position;
		this.position = this.next_position()}
	images.previous_image = function() {return this.items[this.previous_position]}

	/* Start the show */
	setTimeout('transition()',(settings.show_length * 1000))  /* then we schedule the next transition*/
}

function transition() {
	new Fx.Tween(images.current_image(),{
		property: 'opacity',
		duration: 2000
	}).start(0)
	new Fx.Tween(images.next_image(),{
		property: 'opacity',
		duration: 2000
	}).start(1)
	images.set_next();
	setTimeout('transition()',(settings.show_length * 1000))  /* then we schedule the next transition*/
}
function goLeft() {
	images.previous_image().removeClassName('first')
	images.previous_image().setStyle({opacity:"1"})
	images.current_image().removeClassName('next')
	images.current_image().addClassName('first')
	images.next_image().addClassName('next')
	images.next_image().setStyle({left:"0"})
	fadeCurrent()
	images.set_next()
	moveLeft()
	setTimeout('goRight()', settings.show_length * 1000)
}

function goRight() {
	images.previous_image().removeClassName('first')
	images.previous_image().setStyle({opacity:"1"})
	images.current_image().removeClassName('next')
	images.current_image().addClassName('first')
	images.next_image().addClassName('next')
	images.next_image().setStyle({left:"-"+settings.move_amount+"px"})
	fadeCurrent()
	images.set_next()
	moveRight()
	setTimeout('goLeft()', settings.show_length * 1000)
}

function transitionImages() {
}

function moveLeft() {
	var moveAmount = 0 - settings.move_amount
 	new Effect.Move(images.current_image(),{duration:settings.total_time(),x:moveAmount,y:0,mode:'absolute'})
}
function moveRight() {
 	new Effect.Move(images.current_image(),{duration:settings.total_time(),x:settings.move_amount,y:0,mode:'relative'})
}

function fadeCurrent() {
	new Effect.Opacity(images.current_image(),{duration:settings.transition_length, from: 1.0, to: 0.0})
}


