/*
Copyright/Droit de copie: Arnaud LIOTTA
Date: 4-02-09

All right Reserved/Tous droits R�serv�s

Contact: arnaud.liotta@xalnia.fr

*/

// <!CDATA[
// Tab representation object
function Tab(_id, _top,_width,_height){
    this.initialId = _id;
    this.initialTop = _top;
    this.initialWidth = _width;
    this.initialHeight = _height;
}

var currTabHd;

// declare the tabs
var tabArray = new Array();
tabArray[0] = new Tab("tab1","170px","0px","40px");
tabArray[1] = new Tab("tab2","210px","0px","40px");
tabArray[2] = new Tab("tab3","250px","0px","40px");
tabArray[3] = new Tab("tab4","290px","0px","40px");
tabArray[4] = new Tab("tab5","330px","0px","40px");
tabArray[5] = new Tab("tab6","370px","0px","40px");


function test(){
    var currTab = tabArray[0];
    alert(currTab.initialId);
}

// expend the specified Tab
function activateTab(_currTab) {
    expendElement(_currTab);
}

function collapseElement(){
    // loop through the array of tabs
    for(i = 0; i < tabArray.length; i++){
        // Reset an element to the 0 width and default top and height
        var currTab = tabArray[i];
        
        var currElementId = currTab.initialId;
        document.getElementById(currElementId).style.top = currTab.initialTop;
        document.getElementById(currElementId).style.width = currTab.initialWidth;
        document.getElementById(currElementId).style.height = currTab.initialHeight;        
    }
    currTabHd = document.getElementById("currTabHd");
    resetZIndex();
    
}

function resetZIndex(){
    // loop through the array of tabs
    for(i = 0; i < tabArray.length; i++){
        // Reset an element to the 0 width and default top and height
        var currTab = tabArray[i];
        
        var currElementId = currTab.initialId;
        document.getElementById(currElementId).style.zIndex = 0;
    }
}

function setZIndex(_currTab, _prevTab){
    // reset the z-index if the tab is neither the active nor the previous one
    // loop through the array of tabs
    for(i = 0; i < tabArray.length; i++){
        // Reset an element to the 0 width and default top and height
        var currTab = tabArray[i];
        
        var checkedElementId = currTab.initialId;    
    
        if(_currTab != checkedElementId && _prevTab != checkedElementId){
            document.getElementById(checkedElementId).style.zIndex = 0;
            document.getElementById(checkedElementId).style.visibility = "hidden";
        }
    }

    // set zIndex
    var prevElement = null;
    if(_prevTab != "") prevElement = document.getElementById(_prevTab);
    var currElement = document.getElementById(_currTab);
    
    if(prevElement!=null){
        prevElement.style.zIndex=9;
        prevElement.style.visibility="hidden";
    }
    currElement.style.visibility="visible";
    currElement.style.zIndex=10;
}


function expendElement(_eltId){
    // previous element
    var prevTab;
    
    
    
    if(currTabHd.value != 0) prevTab = currTabHd.value;
    else{
        prevTab = "tab1";
    }

    // If the elemnet is not the current element
    if(currTabHd.value != _eltId){
        currTabHd.value = _eltId;
    }else{
        return;
    }

    // Reset all and set the element zIndex
    setZIndex(_eltId,prevTab);
    setButtonClass(_eltId,prevTab);
    
    // curr Tab object
    var currTab;

    // Get the current Tab Object
    for(i = 0; i < tabArray.length; i++){
        if(tabArray[i].initialId == _eltId){
            currTab = tabArray[i];
        }
    }
   
    // reset tab display to initial
    document.getElementById(_eltId).style.height = currTab.initialHeight;
    document.getElementById(_eltId).style.top = currTab.initialTop;
    document.getElementById(_eltId).style.width = currTab.initialWidth;

    // increase the width then the top and height
    increaseCurrWidth(_eltId, 650);
}

function increaseCurrWidth(_eltId, _finalWidth){
	

	
    // number of pixel used to increment the width
    var numPix =30;

    // retrieve the current top
    var currWidth = document.getElementById(_eltId).style.width;
    var currWidthInt = parseInt(currWidth);
    
    _finalWidth = parseInt(_finalWidth);
    

    
    if(currWidthInt < _finalWidth){
        // increase width
        if(currWidthInt + numPix > _finalWidth){
            document.getElementById(_eltId).style.width = _finalWidth+"px";
        }else{
            document.getElementById(_eltId).style.width = parseInt(currWidthInt)+parseInt(numPix)+"px";
            
        }
        setTimeout("increaseCurrWidth('" + _eltId + "'," + _finalWidth + ")",5);
    }else{
        // increase top and bottom part
        increaseTop(_eltId,100);
        increaseBottom(_eltId,580);
    }
}



function increaseTop(_eltId, _finalTop){
	
    // Number of pixel used to increase the top
    var numPix = 10;

    // retrieve the current top
    var currTop = document.getElementById(_eltId).style.top;
    var currTopInt = parseInt(currTop.replace("px",""));
    
    var currHeight = document.getElementById(_eltId).style.height;
    var currHeightInt = parseInt(currHeight.replace("px",""));
    
    // increase the Top value
    if(currTopInt > _finalTop){
        document.getElementById(_eltId).style.top = (currTopInt-numPix)+"px";
        setTimeout("increaseTop('" + _eltId + "'," + _finalTop + ")",10);
    }else{
        return;
    }
}

function increaseBottom(_eltId, _finalHeight){
    // Number of pixel used to increase the height
    var numPix = 20;

    // retrieve the height
    var currHeight = document.getElementById(_eltId).style.height;
    var currHeightInt = parseInt(currHeight.replace("px",""));
    
    // increase the heigh
    if(currHeightInt < _finalHeight){
        if((_finalHeight - currHeightInt) < numPix){
            document.getElementById(_eltId).style.height = _finalHeight;
        }else{
            document.getElementById(_eltId).style.height = (currHeightInt + numPix) +"px";
        }
        
        setTimeout("increaseBottom('" + _eltId + "'," + _finalHeight + ")",10);
    }else{
        return;
    }
}

function Button2_onclick() {
    collapseElement();
}

// change the style of the called button
function setButtonClass(_currTabId,_prevTabId){
    var currTabNode;
    var prevTabNode;
    
    var currTabId;
    var tabSuffix = "Bkg";

    //reset previous button class
    if( _prevTabId != 0){
    	
        currTabId = _prevTabId + tabSuffix;        
        prevTabNode = document.getElementById(currTabId);
        prevTabNode.setAttribute("className","divOdd",0);
    }

    // set current button class
    currTabId = _currTabId + tabSuffix;
    prevTabNode = document.getElementById(currTabId);

    prevTabNode.setAttribute("className","divOddActivated",0);
    
    return;
}

// ]]>