﻿//Animations for the main page.

//NAV MOVER
//==================================================================
//Moves the main bar left and then redirects to the appropriate link
num = 0;
l = 0;
arr = []
function move_link() {
    //console.profile(num)
    num--;
    el = arr[l - num];
    //console.log($(el).attr('href'))
    var obj = document.getElementById($(el).attr('id'));
    var mainObj = document.getElementById('main');
    var x = findPosX(obj);
    var y = findPosX(mainObj);
    //alert (x);
    $(el).animate({ left: +100 }, 500, 'easeInBack');
    $(el).animate({ left: y - x }, 300, 'easeInBack');
    if (num > 0) {
        timedMsg()
    }
    else {
        //alert('Complete, loading page')
        //document.location=$(this).attr("href");
    }
}


function timedMsg() {
    var t = setTimeout("move_link()", 100)
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

$(document).ready(function () {
    num = $('.mainOptions ul li a').length;
    l = $('.mainOptions ul li a').length - 1;
    arr = $('.mainOptions ul li a');
    $('.mainOptions ul li a').click(function (ev) {
        var mp3 = $("#words_side");
        mp3[0].play();
        ev.preventDefault();
        var address = $(this).attr("href")
        timedMsg();
        //console.log($(this).context.href);
        setTimeout(function () {
            window.location = address;
        }, 1500);
    });
});

//END NAV MOVER
//==================================================================
