/*
---

name: SlideShow.Extended

description: Extension for Ryan Florence's SlideShow (https://github.com/rpflorence/SlideShow)

authors: Rolf Langenhuijzen

license: MIT-style license.

requires: [SlideShow, More/Assets, Element.Data]

provides: SlideShow.Extended

...
*/

SlideShow.Extended = new Class({

	Extends: SlideShow,

	options: {
		/*
		onLoadImage: function(){},
		onLoadImageComplete: function(){},
		*/
	},

	initialize: function(){
		this.parent.apply(this, arguments);
	},

	loadImage: function(index, showOnload){
		this.fireEvent('loadImage', index);
		var slide = this.slides[index];
		if (this.slideLoaded(slide)){
			this.loadImageComplete(index, showOnload);
		} else {
			new Asset.image(slide.getData('src'), {
				onload: function(image){
					slide.grab(image);
					slide.store('loaded', true);
					this.loadImageComplete(index, showOnload);
				}.bind(this)
			});
		}
	},

	loadImageComplete: function(index, showOnload){
		if (showOnload) this.show(index);
		this.fireEvent('loadImageComplete', index);
	},

	slideLoaded: function(slide){
		return (slide.retrieve('loaded')) ? true : false;
	}
});
