/**
 * Slider component
 * 
 * @copyright: Solid Parnters i-design B.V.
 * @author: Sven Moleman
 * @requirements: Mootools 1.2 
 * @param {SlideShow} SlideShow
 */
//if (console == undefined) {
//    var console = {
//        log: function(value) {
//            alert(value);
//        }
//    };
//}

var SlideShow = new Class({
    options:{
        'slideSpeed': 5000,
        'slideComplete': function(){}
    },
    initialize: function(object,options){
        this.setOptions(options);

        this.object = object;
        this.slides = object.getChildren();
        this.slides.setStyle('opacity','0');
        this.selectedIndex = object.getChildren().length - 1;
        this.slideLength = object.getChildren().length;
    },
    start: function()   {
        this.slides[this.selectedIndex].setStyle('opacity',1);
        this.periodicalId = this.slide.periodical(this.options.slideSpeed, this);
        return this.periodicalId;
    },
    stop: function()    {
        $clear(this.periodicalId);
    },
    slide: function(index)  {
        if (index == undefined) {
            index = ((this.selectedIndex+1) >= this.slideLength) ? 0 : (this.selectedIndex+1);
        }
        this.slides.each(function(slide,slideIndex)  {
            if (slideIndex == index)    {
                slide.set('tween',{duration: 1200});
                slide.fade(1);
                this.slideComplete();
            }
            if (slideIndex == this.selectedIndex)   {
                slide.set('tween',{duration: 1200});
                slide.fade(0);
            }
        }.bind(this));
        this.selectedIndex = index;
    },
    slideComplete: function() {
        this.options.slideComplete();
    }
});
SlideShow.implement(new Options);

SlideShow.implement(new Events);
