/***
*
*  QuickSlides: A barebones slideshow
*  
***/
var QuickSlides = new Class({
        //
		//  initialize
		//
		Implements: [Options,Events],
		options: {
				wait:4000,
				preLoad:1,
				autoLoad:true,
				initIndex:0
		},
		initialize: function(paths,transbox,options){
				this.setOptions(options);
				this.paths = paths
				this.transbox = transbox
				this.errors = []
				this.index = this.options.initIndex
				this.percentLoaded = 0
				this.numMissing = 0
				this.numLoaded = 0
				this.numImages = this.paths.length
				if (this.options.autoLoad) this.loadImages()
		},
		//
		// CONTROLS
		//
		play: function(wait){
				if (!wait) this.next()
				if (this.timer) clearTimeout(this.timer)
				this.timer = this.next.periodical(this.options.wait,this)
		},
		pause: function(){
				if (this.timer) clearTimeout(this.timer)
				this.timer = null
		},
		next: function(){
				this.goTo(this.index + 1 < this.images.length ? this.index + 1 : 0)
		},
		prev: function(){
				this.goTo(this.index - 1 >= 0 ? this.index - 1 : this.images.length - 1)
		},
		goTo: function(index){
				this.transbox.swap(this.images[index])
				this.index = index
		},
		//
		//	LOADING
		//
		loadImages: function(){
				this.images = []
				var assets = new Asset.images(this.paths,{
						onProgress: function(counter,index){
								this.numLoaded++
								this.images.push(assets[index])
								this.percentLoaded = (((this.numLoaded) / this.numImages) * 100).toFixed(0)
								this.fireEvent('PROGRESS')
								if (this.numLoaded == this.options.preLoad) this.play(true)
						}.bind(this),
						onComplete: function(){
								this.numMissing = this.numImages - this.numLoaded
								this.numImages = this.numLoaded
								this.percentLoaded = 100
								this.fireEvent('COMPLETE')
						}.bind(this),
						onError: function(){
								this.fireEvent('ERROR')
						}.bind(this)
				})        
		}
});
