/*
@author     Igor "SkAZi" Potapov <igor@potapoff.org>
@copyright  Plan-B Ltd.
@requires   MooTools 1.2
*/

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

    var news = $$('#sub-index-right .news')[0];
    var banner = $$('#sub-index-right .banner')[0];
    if(news && banner && news.getSize().y < banner.getSize().y)
        news.setStyle('height', banner.getSize().y);

    new Loader([ $('right-page-inner').style.backgroundImage.replace(/url\((.*)\)/, '$1') ] );
    
    $('turn-on-page').addEvent('click', function(){
        
       
        //if($('outer').getSize().x != 980) return;
        
        $('turn-on-page').fade('out');
        
        $('right-page-animation').setStyle('width', 212);
        
        $('right-page-animation-shade').setStyle('visibility', 'visible');
        
        $('outer').set('morph', {duration: 300, transition: 'back:out'}).morph({
            'width': 1640,
            'marginLeft': -1660 - $('wrapper').getPosition().x + window.getSize().x
        });
        
        (function(){
            $('right-page-shade').setStyle('visibility', 'hidden');
            $('right-page-animation-shade').setStyle('visibility', 'visible');
            $('right-page-animation').tween('width', 870);
            (function(){
                $('right-page-animation-shade').setStyle('visibility', '');
                if(!oldschool)
                    $('flow').setStyle('opacity', 0).fade('in');
            }).delay( 500 );
            
        }).delay( 300 );

    });
    
    $('turn-off-page').addEvent('click', function(){
        
        if(!oldschool)
            $('flow').setStyle('opacity', 1).fade('out');

        (function(){
            $('right-page-animation-shade').setStyle('visibility', 'visible');
            $('right-page-animation').tween('width', 212);
            
            (function(){
                $('turn-on-page').fade('in');
                $('right-page-shade').setStyle('visibility', '');
                $('right-page-animation-shade').setStyle('visibility', '');
                $('outer').set('morph', {duration: 300, transition: 'back:out'});
                $('outer').morph({ 'width': 980, 'marginLeft': 0 });
            }).delay( 400 );
        }).delay( 400 );
    });
            
    enableLanguageSelect();
});
