window.addEvent('load', function() {

    /*if ($$('.teaser-button').length){
        var tb = $$('.teaser-button')[0].getFirst();
        fadefade(tb, 0, 500);
    }*/
    
    if ($('c34') && $('c133')) $('c34').setStyle('display', 'none');
    if ($('c17') && $('c126')) $('c17').setStyle('display', 'none');
    if ($('c21') && $('c128')) $('c21').setStyle('display', 'none');
    if ($('c24') && $('c133')) $('c24').setStyle('display', 'none');
    
    $$('.fce-newsticker').each(function(item){
        var children = item.getFirst().getChildren();
        rotate(0, children);
    });	
    
    var toggler = $$('.toggler');
    var slider = $$('.slider');
    
    /*toggler.each(function(item, index){
        
        var fxSlide = new Fx.Slide(slider[index],{
            duration: 500
        })
        
        if (index >= 1) fxSlide.hide();
        
        item.addEvents({
            'click': function(){
                fxSlide.toggle();
            }
        });
    });*/
    
    var sloganSlide = new Fx.Morph($$('.slogan')[0], {duration: 'long'}); 
    sloganSlide.start({
        'top': 176,
        'right': 260
    });
    
    $$('.csc-textpic-single-image').each(function(item){
        var oImg = item.getFirst();
        if (oImg.nodeName == 'IMG' && oImg.width > 500){
            oImg.setStyles({
                'margin-bottom': 0,
                'border': '0px solid #aaaaaa'
            });
            
            item.setStyles({
                'margin-bottom': 15,
                'width': 500,
                'overflow-x': 'scroll',
                'overflow-y': 'hidden'
            });
        }
    });

});

function rotate(index, children){
    index = (children[index]) ? index : 0;    
    children[index].setStyle('display', 'block');
    fade(children[index], 1, 1000, function(){        
        (function(){
            fade(children[index], 0, 1000, function(){
                children[index].setStyle('display', 'none');
                rotate(index+1, children);
            });
        }).delay(500);
    });
}

function fade(element, opacity, duration, cb){
    var fading = new Fx.Tween(element, {
        property: 'opacity',
        duration: duration,
        link: 'chain',
        onComplete: function(){
            if (cb) cb(); 
        }
    }).start(opacity);
}

function fadefade(element, opacity, duration, cb){
    var fading = new Fx.Tween(element, {
        property: 'opacity',
        duration: duration,
        link: 'chain',
        onComplete: function(){
            if (cb){
                cb();
            } else fade(element, 1, 200, function(){
                (function(){fadefade(element, 0, 500);}).delay(1000);
            });
        }
    }).start(opacity);
}
