var PREV_TOP_COORD = null
var TAB_TOP_COORDS = [0, -190, -380,-570]
var TAB_TOP_COORD_DELTAS = [-10, -40, -60,-80]
var ACTIVE_TAB_INDEX = null

function main() {
    if(window.location.pathname.search('resume.php') != -1) {
        document.getElementById('second-tab').style.top = -230
        ACTIVE_TAB_INDEX = 1
    } else if(window.location.pathname.search('projects.php') != -1) {
        document.getElementById('third-tab').style.top = -440
        ACTIVE_TAB_INDEX = 2
    } else if(window.location.pathname.search('pictures.php') != -1) {
        document.getElementById('fourth-tab').style.top = -650
        ACTIVE_TAB_INDEX = 3
    } else {
        document.getElementById('first-tab').style.top = -10
        ACTIVE_TAB_INDEX = 0
    }
}

function loadPage(addr) {
    document.location=addr
}

function mouseOverMenuTab(event) {
    var e = event.target
    var i = getTabIndex(e)
    if(i != ACTIVE_TAB_INDEX)
        e.style.top = TAB_TOP_COORDS[i] + TAB_TOP_COORD_DELTAS[i]
}

function mouseOutMenuTab(event) {
    var e = event.target
    var i = getTabIndex(e)
    if(i != ACTIVE_TAB_INDEX)
        e.style.top = TAB_TOP_COORDS[i]
}

function getTabIndex(e) {
    var index = null
    if( e.id.search('first') != -1)    
        index = 0    
    else if( e.id.search('second') != -1)    
        index = 1    
    else if( e.id.search('third') != -1)    
        index = 2    
    else
        index = 3
    return index
}

function animateTab(elem, tabIndex) {
    var delta = TAB_TOP_COORD_DELTAS[tabIndex]
    var curPlace = TAB_TOP_COORDS[tabIndex]
    var targetTop = curPlace + delta
    var step = delta / 10 
    _move()    
    
    function _move() {
        curPlace += step
        elem.style.top = curPlace
        if(targetTop != curPlace)        
            setTimeout(_move, 50)
    }    
}