Muma.Header = new Class (
{
    initialize: function()
    {
        this.headerInner = $('header-inner');
        this.childrenCount = this.headerInner.getChildren().length;

        this.maxMargin = this.childrenCount * 603;
        this.headerInner.setStyle('width', this.maxMargin);

        this.runAnimation.periodical(4000, this);
    }
})

Muma.Header.implement(
{
    runAnimation : function()
    {
        this.currentMargin = this.headerInner.getStyle('margin-left').replace('px', '');

        var fx = new Fx.Tween(this.headerInner, {duration: 1500, transition: Fx.Transitions.Elastic.easeOut});

        if (this.currentMargin == 0)
        {
            fx.start('margin-left', 0, -603);
        }

        if ((this.currentMargin - 603) == -this.maxMargin)
        {
            var fx = new Fx.Tween(this.headerInner, {duration: 500});
            fx.start('margin-left', -(this.maxMargin - 603), 0);
        }
        else
        {
            fx.start('margin-left', this.currentMargin, (this.currentMargin - 603));
        }
    }
});

window.addEvent('domready', function()
{
    new Muma.Header();
});
