/* version 0.0.3 */
dojo.declare('dojoSpotlightClass', null, {
    constructor : function() {
        this.image = new Array();
        this.headline = new Array();
        this.summary = new Array();
        this.link = new Array();
        this.timeoutLenght = 12000;
        this.current = 3;
    },
    init : function() {
        this.spotlightMenu = dojo.query('#sn-nav-wrap .sn-tab');
        this.spotlightMenu.connect('onclick', function(e) {
            dojoSpotlight.stopTimer();
            switch (e.target.id) {
                case 'sn-forward':
                dojoSpotlight.next();
                break;
                case 'sn-back':
                dojoSpotlight.previous();
                break;
                case 'sn-pause':
                dojoSpotlight.action();
                break;
                case 'sn-1':
                dojoSpotlight.switchTo(3);
                break;
                case 'sn-2':
                dojoSpotlight.switchTo(4);
                break;
                case 'sn-3':
                dojoSpotlight.switchTo(5);
                break;
                case 'sn-4':
                dojoSpotlight.switchTo(6);
                break;
                case 'sn-5':
                dojoSpotlight.switchTo(7);
                break;
            }
        });
        this.startTimer();
    },
    add : function(headline, summary, link, image) {
        this.headline.push(headline);
        this.summary.push(summary);
        this.image.push(image);
        this.link.push(link);
    },
    startTimer : function() {
        this.timeoutID = setTimeout('dojoSpotlight.next()', this.timeoutLenght);
    },
    stopTimer : function() {
        clearTimeout(this.timeoutID);
    },
    next : function() {
        this.switchTo(this.current + 1);
    },
    previous : function() {
        this.switchTo(this.current - 1);
    },
    action : function() {
        var action = dojo.byId('sn-pause');
        if (dojo.hasClass(action, 'sn-play')) {
            dojo.removeClass(action, 'sn-play');
            dojo.addClass(action, 'sn-pause');
        } else {
            dojo.removeClass(action, 'sn-pause');
            dojo.addClass(action, 'sn-play');
            this.startTimer();
        }
    },
    switchTo : function (i) {
        dojo.removeClass(this.spotlightMenu[this.current], 'sn-on');
        dojo.addClass(this.spotlightMenu[this.current], 'sn-off');
        if (i > 7) { i = 3; }
        if (i < 3) { i = 7; }
        dojo.removeClass(this.spotlightMenu[i], 'sn-off');
        dojo.addClass(this.spotlightMenu[i], 'sn-on');
        this.current = i;
        i = i - 3;
        dojo.fadeOut({
            node: "sn-image-placeholder",
            duration: 300,
            onEnd: function() {
                dojo.byId('sn-image-placeholder').setAttribute('src', dojoSpotlight.image[i]);
                dojo.fadeIn({node: "sn-image-placeholder",duration: 1000}).play()
            }
        }).play();
        dojo.byId('sn-title').innerHTML = this.headline[i];
        dojo.byId('sn-teaser').innerHTML = this.summary[i];
        dojo.byId('sn-link').setAttribute('href', this.link[i]);
        if (dojo.hasClass(dojo.byId('sn-pause'), 'sn-play')) {
            this.startTimer();
        }
    }
});