﻿SS = function(id) {
    var tmp = this;
    this.slides = new Array();
    $(id).select('.slide').each(function(el) {
        tmp.slides[tmp.slides.length] = el;
    });
    this.selected = Math.floor(Math.random() * this.slides.length);

    if (tmp.slides.length - 1 > tmp.selected) tmp.next = tmp.selected + 1; else tmp.next = 0;

    $(this.slides[this.selected]).show();
    $('slidec_' + this.selected).addClassName('sel');

    this.start();
}

SS.prototype.start = function() {
    var t = this;
    function mSwitch() {
        t.gonext();
    }
    this.timer = setInterval(mSwitch, 8000);
}

SS.prototype.gonext = function() {
    $('slidec_' + this.selected).removeClassName('sel');
    $(this.slides[this.selected]).fade({ duration: 0.8 });
    var tmp = this;
    $('slidec_' + this.next).addClassName('sel');
    $(this.slides[this.next]).appear({ duration: 0.8, afterFinish: function() { tmp.selected = tmp.next; if (tmp.slides.length - 1 > tmp.selected) tmp.next = tmp.selected + 1; else tmp.next = 0; } });
}