/*
 *Accordeon-like Moving, for Showreel
 */

var cookieIsSet = 'no';


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

    var normal_fxcontainer              = 309;
    
    
    

    if($('eyecatcher').innerHTML != ''){
        // some Corrections
        $('fx_container').setStyle('height', normal_fxcontainer);
        $('fx_container').setStyle('margin', '16px 0');

        //check COOKIE, display Showreel to first-time visitor
        if(document.cookie){
            var a = document.cookie;
            cookieIsSet = a.search('date');
        }
        if(cookieIsSet == 'no'){
            trigger_expand();
        }
        
        // some Teaser Movement
        teaser_moving();  //TODO: Activate, when ready
    }
});


function trigger_expand() {

        var closer = $('closer');
        closer.setStyle('display', 'block');

        // set Slideshow to Pause, while Showreel is active
        //myShow_jf_headerslide_slideshow.pause();

        // autostart Movie
        $f().play();

        // set COOKIE and dont expand Showreel automaticlly
        var a = new Date();
        var b = new Date();
        a = new Date(a.getTime() +1000*60*60*24*365);
        document.cookie = 'date='+b.toGMTString()+'; expires='+a.toGMTString()+';';

        var totIncrement_vertical	= 0;
        var increment_vertical		= 236;
        var normal_fxcontainer          = 309;
        var increment_fxcontainer       = 354;
        var fx_eyecatcher = new Fx.Tween($('eyecatcher'), {duration: 750, transition: Fx.Transitions.Expo.easeOut});
        var fx_fxContainer = new Fx.Tween($('fx_container'), {duration: 750, transition: Fx.Transitions.Expo.easeOut});

        if(totIncrement_vertical == 0) {
            $('player').setStyle('display', 'block');
            totIncrement_vertical -= increment_vertical;
            fx_eyecatcher.pause();
            fx_eyecatcher.start('margin-top', totIncrement_vertical);
            fx_fxContainer.start('height', increment_fxcontainer);


            var showreelText = $('vjs-banner');
            /* create Close Element */
            //var closer = document.createElement("div");
            
            closer.addClass('closeBtn');

            closer.addEvent('click', function() {
                totIncrement_vertical += increment_vertical;

                //pause the movie
                $f().pause();

                fx_eyecatcher.pause();
                fx_eyecatcher.start('margin-top', totIncrement_vertical);
                fx_fxContainer.start('height', normal_fxcontainer);
                //$('eyecatcher').removeChild(closer);
                closer.setStyle('display', 'none');
                showreelText.setStyle('display', 'block');

                // start Slideshow again, if close-btn is clicked
                //myShow_jf_headerslide_slideshow.pause();
            });

            $('eyecatcher').appendChild(closer);
            showreelText.setStyle('display', 'none');

        }
}


/*
 * MOVING the 3 TEASERS
 */

function teaser_moving(){

   var teaser_container = $('teaser_wrapper');
   var teaser_position = 0;
   var teaser_total    = 840;
   var teaser_inc      = 280;


   var fx_teasermover = new Fx.Tween(teaser_container, {duration: 1250, transition: Fx.Transitions.Expo.easeInOut});

   window.setInterval(function(){
       if(teaser_position == 0 || teaser_position == -280 || teaser_position == -560){
           teaser_position -= teaser_inc;
           fx_teasermover.start('margin-left', teaser_position);
       }else{
           teaser_position += teaser_total;
           fx_teasermover.start('margin-left', teaser_position);
       }
   },10000);

}