
var currentStep = 1;

//Creates sabinos.Timer object pointing to different functions for each event
var timer2 = new sabinos.Timer({
    AutoReset: true,                //Reset timer after each loop
    Interval: 0.1,                    //each loop takes 2 secunds to be fired after start/reset
    Loops: 190,                      //Reset will occur 10 times (set to -1 to repeat forever)
    Started: timer2Started,       //'example2Started' function called each time timer2 starts
    Stoped: timer2Stoped,         //'example2Stoped' function called each time timer2 stops
    Reseted: timer2Reseted,        //'example2Reseted' function called each time timer2 resets
    Elapsed: timer2Elapsed        //'example2Elapsed' function called each time timer2 elapses
    });

//Function called after button start is clicked
function timer2Start() {
    //Start timer object
    timer2.start();
    
   $("player_timeline_stop").show();
   $("player_timeline_play").hide();
}

//Function called after button start is clicked
function timer2Next() {
    if(currentStep > 0)
    {
        var nextLink = currentStep + 1;
        GoToLink(nextLink);
    }
}

//Function called after button start is clicked
function timer2Back() {
    if(currentStep > 0)
    {
        var prevLink = currentStep - 1;
        GoToLink(prevLink);
    }
}

//Function called after button stop is clicked
function timer2Stop(){

    if(timer2!=null)
        timer2.stop();
        
   $("player_timeline_stop").hide();
   $("player_timeline_play").show();
}

//function called each time timer2 elapses  
function timer2Elapsed() {

    var w       = (timer2.LoopsCompleted * 5);
    var width1  = w + 'px';
    
    
    $("timeline").setStyle({width: width1}); 
    
    switch(w)
    {
        case 10:
            showHeadline(1);
            break;
        case 190:
            showHeadline(2);
            break;
        case 380:
            showHeadline(3);
            break;
        case 570:
           showHeadline(4);
            break;
        case 760:
            showHeadline(5);
            break
       case 930:
            showHeadline(6);
            break;
       case 950:
            setTimeout("timer2Start();", 6000);
            break;
    }
}

function showHeadline(h)
{

    currentStep       = h;
    var headlineCount = 7;
    
    
    for(var i=1;i<headlineCount;i++)
    {
        var headlineId = "headline_" + i;
        
        if(i == h)
        {
            $(headlineId).show();
            
            new Effect.Opacity(headlineId, {  from: 0.5, to: 1.0,duration: 1.0});

        }
        else
        {
        
            $(headlineId).hide();
        }
    }
}

//function called each time timer2 restes
function timer2Reseted() {
    
}
//function called each time timer2 starts
function timer2Started() {
    
}
//function called each time timer2 stops
function timer2Stoped() {
   
}

function GoToLink(i)
{
    
    if(timer2!=null)
        timer2.stop();
        
   $("player_timeline_stop").hide();
   $("player_timeline_play").show();
    
    switch(i)
    {
         case 1:
           
            new Effect.Morph('timeline', {style:'width:25px', duration:'0.4'}); 
             showHeadline(1);
            break;
        case 2:
            new Effect.Morph('timeline', {style:'width:190px', duration:'0.4'}); 
            showHeadline(2);
            break;
        case 3:
        
            new Effect.Morph('timeline', {style:'width:380px', duration:'0.4'}); 
             showHeadline(3);
            break;
        case 4:
            new Effect.Morph('timeline', {style:'width:570px', duration:'0.4'});
             showHeadline(4);
            break;
        case 5:
            new Effect.Morph('timeline', {style:'width:760px', duration:'0.4'});
            showHeadline(5);
            break;
       case 6:
            new Effect.Morph('timeline', {style:'width:920px', duration:'0.4'});
            showHeadline(6);
            break;
    }
}

