AutoCall = {
  startAdv  : function( index ){
    
    // VARIABLES
    var li = $('auto-call-adv').children;
    var index = index ? index : 0;
    var i;
    
    // HIDE ALL
    for( i=0; i<li.length; i++ ){
      li[i].hide();
    }

    // INIT MOTION
    new Effect.Opacity( li[index], { 
      queue    : { position:'end', scope:'AutoCall-scope' },
      from     : 0,
      to       : 1,
      duration : 0.8,
      beforeSetup : function(){
        li[index].show();
      }
    });
    new Effect.DropOut( li[index], { 
      queue       : { position:'end', scope:'AutoCall-scope' },
      delay       : 2,
      afterFinish : function(){
        AutoCall.startAdv( li[index+1]? index+1 : 0 );
      }
    });
    
  },
  openForm  : function(){
    
    // VARIABLES
    var li = $('auto-call-panel').getElementsByTagName('li');
    new Effect.Parallel([
      new Effect.toggle( li[0], 'blind', { sync: true }), 
      new Effect.toggle( li[1], 'blind', { sync: true })
    ], { 
      queue    : { position:'end', scope:'AutoCall-panel-scope', limit:1 },
      duration : 0.8
    });
    
  },
  startCall : function(){
    
    // VARIABLES
    
    $('auto-call-calling').hide();
    $('auto-call-log').show();
    $('auto-call-log').className = 'PopDowninfo';
    $('auto-call-log').innerHTML = 'Connexion en cours ...';
    
    ( engine.Ajax || engine.ajaxLite ).call( 'modules/web2poche/ajax/click2call.php', {
      onsuccess : function(data){
        $('auto-call-log').show();
        $('auto-call-log').className = 'PopDownsuccess';
        $('auto-call-log').innerHTML = data.firstChild.data;
      },
      onfail : function(data){
        
        // VARIABLES
        var data = data.firstChild.data;
    
        // PARAMS ERROR
        if( $(data) ){
          $('auto-call-log').hide();
          $('auto-call-calling').show();
          engine.focus(data);
        }
        
        // API ERROR
        else{
          $('auto-call-log').show();
          $('auto-call-log').className = 'PopDownfail';
          $('auto-call-log').innerHTML = data;
        }
        
      }
    });
  }
};


function pulsate( index ){
  var p = $('anim_header_div').getElementsByTagName('p');
  if( p[index] ){ 
    new Effect.Fade( p[index], {duration:1, from:1.0, to:0.1,
      afterFinish:function(){ new Effect.Appear( p[index], {duration:1, from:0.1, to:1.0 }); pulsate( index+1 ); }
    });
  }
  else setTimeout( function(){ header_drop(0); }, 5000);
}
function header_drop( index ){
  var p = $('anim_header_div').getElementsByTagName('p');
  if( p[index] ){
    new Effect.DropOut( p[index] );
    setTimeout( function(){ header_drop( index+1 ); }, 100);
  }
  else setTimeout( function(){ slide(0); }, 1000);
}
function slide( index ){
  var p = $('anim_header_div').getElementsByTagName('p');
  if( p[index] ){ 
    new Effect.MoveBy( p[index], 0, 200, {duration:1, from:1.0, to:0.0,
      afterSetup:function(){p[index].style.display='block';},
      afterFinish:function(){ slide( index+1 ); }
    });
  }
  else setTimeout( function(){ pulsate(0); }, 3000);
}
engine.addEvent( window, 'load', function(){ 
  pulsate(0);
});
