var ZwickHeader = new Class(
{

    // vars
    items: null,
    counter: -1,
    duration: 5000,
    last: null,
    
    /**
     * Constructor
     * 
     */
    initialize: function(name)
    {
        window.addEvent('domready', this.onDomReady.bind(this));
    },
    
    /**
     * 
     */
    onDomReady: function()
    {
        // reset to start
        this.items = $$('#headerimgs li.headerimg');
        
        // logo animation
        this.logo = $('logo');
        this.logo.set('tween', {'transition':Fx.Transitions.Bounce.easeOut, 'duration':800});
        this.logo.tween('top', -180, this.logo.getStyle('top'));
        
        // behaviours
        for (var i=0; i<this.items.length; i++) {
            if (i+1 != this.items.length) {
                this.items[i].setOpacity(0);
            } else {
                this.last = this.items[i];
            }
        }
        
        // start interval
        this.startInterval();
    },
    
    startInterval: function()
    {
        this.interval = this.next.periodical(this.duration, this);
    },
    clearInterval: function()
    {
        $clear(this.interval);
    },
    
    /**
     * Interval function
     */
    next: function() 
    {
        this.counter++;
        if (this.counter == this.items.length) {
            this.counter = 0;
        }
        this.switchTo(this.counter);
    },
    
    /**
     * Switches to the given index
     */
    switchTo: function(index)
    {
        this.items[index].fade('in');
        this.last.fade('out');
        this.last = this.items[index];
    }

});
new ZwickHeader();
