window.addEvent('domready',function(){
    var flash_wrapper = $('flashy-container');
    if (Browser.Engine.trident && Browser.Engine.version <= 4){
        flash_wrapper.setStyle('display','none');
        $('content-home').setStyle('paddingTop',25);
    }
    var flashy = $$('div.flashy-wrapper');
    flashy.setStyles({
        'position' : 'absolute',
        'top' : 0,
        'left' : 0
    });
    var one = flashy.shift();
    var flash_bottom = flash_wrapper.getStyle('height');
    flashy.setStyle('top',flash_bottom);
    var flash_frames = $('flash-frames');
    var flash_frames_a = flash_frames.getElements('a');
    var interval;
    var time = 8000;
    
    var click_next_active_a = function(use_1){
        //alert(use_1);
        var nxt;
        flash_frames_a.each(function(e){
            var n = e.get('href').replace('#','');
            if (e.hasClass('frame-' + n + '-active')){
                // try to get next
                nxt = $(document.body).getElement('.frame-' + (n.toInt() + 1).toString());
                if (!nxt || use_1) nxt = $(document.body).getElement('.frame-1');
            }
        });
        nxt.fireEvent('click');
    }

    var flash_click = function(){
        $clear(interval);
        var n = this.get('href').replace('#','');
        if (this.hasClass('frame-' + n + '-active')) return false;
        flash_frames_a.each(function(a){
            var n1 = a.get('href').replace('#','');
            a.set('class','frame-' + n1);
        });
        this.set('class','frame-' + n + '-active');
        one.set('tween',{duration:400,onComplete : function(){
                // get the new element
                // animate it up
                // set it as one at the end
                var up = $('flash-' + n);
                up.set('tween',{duration:400}).tween('top',0);
                one = up;
                interval = click_next_active_a.delay(time,flash_wrapper,[false]);
            }.bindWithEvent(this)
        }).tween('top',flash_bottom);
        return false;
    }

    flash_frames_a.addEvent('click',flash_click);
    interval = click_next_active_a.delay(time,flash_wrapper,[false]);
});

