﻿
/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
    
var currentTab = 1; 
var totalTabs = 5; 
var stopped = 0;

function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = document.getElementById(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num) {

    if (document.getElementById('SB_tabContent'+num).style.display == 'none'){
       for (var i=1;i<=totalTabs;i++){

                var temph = 'SB_tabHeader'+i;
                var h = document.getElementById(temph);
                if (h == null)
                {
                    h = document.getElementById("SB_tabHeaderActive" + i);
                    h.id = temph; 
                }
                var tempc = 'SB_tabContent'+i;
                var c = document.getElementById(tempc);
                if(c.style.display != 'none'){
                        toggleDisp(tempc);
                }
           
        }
        
        var h = document.getElementById('SB_tabHeader'+num);
        h.id="SB_tabHeaderActive" + num; 
        //h.blur();
        var c = document.getElementById('SB_tabContent'+num);
        c.style.marginTop = '2px';
        toggleDisp('SB_tabContent'+num);
        
       // currentTab = num;
    }
}

var timeoutID = 0; 

function Timer(){   //Boucle de 3 secondes (3000 milisecondes)
    currentTab = 1; 
    toggleTab(currentTab, totalTabs);
    timeoutID = setTimeout("switchTab()",7000);
}

function Resume(){   //Boucle de 3 secondes (3000 milisecondes)
    if (stopped == 0)
    {
        toggleTab(currentTab, totalTabs);
        timeoutID = setTimeout("switchTab()",7000);
    }
}

function showTab(x)
{
    toggleTab(x, totalTabs);
}

function goTabAdd(x)
{
    currentTab += x; 
    if (currentTab == 0) currentTab = totalTabs; 
    if (currentTab > totalTabs) currentTab = 1; 
    toggleTab(currentTab, totalTabs);
}

function goTab(x)
{
    currentTab = x; 
    toggleTab(currentTab, totalTabs);
}

function switchTab()
{
    currentTab++;
    if (currentTab > totalTabs) currentTab =  1; 
    toggleTab(currentTab, totalTabs);
    timeoutID = setTimeout("switchTab()",7000);
}

function Stop(x){      //Arret de la boucle
   window.clearTimeout(timeoutID)
   stopped = x;
}

