var credits = {
  start: function()
  {
    credits.hideElements();
    credits.showBody();
    credits.showCredits(1.5);
  },
  showBody: function()
  {
    new Effect.BlindDown('body_wrapper', { duration: 2, afterFinish: function(){ $('body_wrapper').setStyle({height: '1%'}) }});
    new Effect.Opacity('section1', { from: 0, to: 1, duration: 1.5});
  },
  hideElements: function()
  {
    $('body_wrapper').show();
    $('section1').setOpacity(0);
    $('effects').setStyle({position: 'relative', height: credits_height+ 'px', overflow: 'hidden'});
    $('effects').childElements().each(function(e){
      e.hide();
    });
  },
  showCredits: function(delay)
  {
    var i = 0;
    $('effects').childElements().each(function(e){
      e.setStyle({
        position: 'absolute',
        top: $('effects').getHeight() - e.getHeight() + 'px',
        left: Math.round(($('effects').getWidth()/2 - e.getWidth()/2)) + 'px',
        opacity: 0
      });
      e.show();
      e.setAttribute('id', 'effect_' + i);

      new Effect.Morph('effect_' + i, {
        style: 'top: ' + Math.round(($('effects').getHeight() - e.getHeight())/3) * 2 + 'px; opacity: 1;',
        duration: 2,
        transition: Effect.Transitions.linear,
        queue: {position: 'front', scope: 'effects_' + i},
        delay: delay + (credits_delay * i)
      });

      new Effect.Morph('effect_' + i, {
        style: 'top: ' + Math.round(($('effects').getHeight() - e.getHeight())/3) + 'px;',
        duration: 2,
        transition: Effect.Transitions.linear,
        queue: {position: 'end', scope: 'effects_' + i},
        afterFinish: function () {
          if ($('effects').childElements().length == i + 1) credits.showCredits();
        }
      });

      new Effect.Morph('effect_' + i, {
        style: 'top: 0px; opacity: 0;',
        duration: 2,
        transition: Effect.Transitions.linear,
        queue: {position: 'end', scope: 'effects_' + i},
        afterFinish: function (effect) {
          if (effect.element.getAttribute('id') == 'effect_' + (i - 1))
          {
            credits.showCredits(0);
          }
        }
      });

      i++;
    });
  }
};

var credits_height = 250; //marimea zonei de credite
var credits_delay = 1.3; //dileyul intre elementele html scrolabile

Event.observe(window, 'load', credits.start);