var currentIndex = 0;
var secciones = new Array();
secciones[0] = "#home";
secciones[1] = "#firmProfile";
secciones[2] = "#ourPeople";
secciones[3] = "#ourPeople2";
secciones[4] = "#ourPeople3";
secciones[5] = "#ourPeople4";
secciones[6] = "#ourPeople5";
secciones[7] = "#projects";
secciones[8] = "#architecture";
secciones[9] = "#planning";
secciones[10] = "#interiors";
secciones[11] = "#detalle";
secciones[12] = "#imagenA";
secciones[13] = "#imagenB";
secciones[14] = "#imagenC";
secciones[15] = "#imagenD";
secciones[16] = "#projectlist";
secciones[17] = "#projectlist2";
secciones[18] = "#projectlist3";
secciones[19] = "#projectlist4";
secciones[20] = "#projectlist5";
secciones[21] = "#projectlist6";
secciones[22] = "#projectlist7";
secciones[23] = "#projectlist8";
secciones[24] = "#projectlist9";
secciones[25] = "#contact";

var nextLinks = new Array();
nextLinks[0] = "#firmProfile";
nextLinks[1] = "#ourPeople";
nextLinks[2] = "#ourPeople2";
nextLinks[3] = "#ourPeople3";
nextLinks[4] = "#ourPeople4";
nextLinks[5] = "#ourPeople5";
nextLinks[6] = "#projects";
nextLinks[7] = "#architecture";
nextLinks[8] = "#planning";
nextLinks[9] = "#interiors";
nextLinks[10] = "#projects";
nextLinks[11] = "#imagenA";
nextLinks[12] = "#imagenB";
nextLinks[13] = "#imagenC";
nextLinks[14] = "#imagenD";
nextLinks[15] = "#projects";
nextLinks[16] = "#projectlist2";
nextLinks[17] = "#projectlist3";
nextLinks[18] = "#projectlist4";
nextLinks[19] = "#projectlist5";
nextLinks[20] = "#projectlist6";
nextLinks[21] = "#projectlist7";
nextLinks[22] = "#projectlist8";
nextLinks[23] = "#projectlist9";
nextLinks[24] = "#projects";
nextLinks[25] = "";

var prevLinks = new Array();
prevLinks[0] = "";
prevLinks[1] = "#home";
prevLinks[2] = "#firmProfile";
prevLinks[3] = "#ourPeople";
prevLinks[4] = "#ourPeople2";
prevLinks[5] = "#ourPeople3";
prevLinks[6] = "#ourPeople4";
prevLinks[7] = "#ourPeople5";
prevLinks[8] = "#projects";
prevLinks[9] = "#architecture";
prevLinks[10] = "#planning";
prevLinks[11] = "#projects";
prevLinks[12] = "#detalle";
prevLinks[13] = "#imagenA";
prevLinks[14] = "#imagenB";
prevLinks[15] = "#imagenC";
prevLinks[16] = "#projects";
prevLinks[17] = "#projectlist";
prevLinks[18] = "#projectlist2";
prevLinks[19] = "#projectlist3";
prevLinks[20] = "#projectlist4";
prevLinks[21] = "#projectlist5";
prevLinks[22] = "#projectlist6";
prevLinks[23] = "#projectlist7";
prevLinks[24] = "#projectlist8";
prevLinks[25] = "#projectlist9";

jQuery(function($) {
    /**
    * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
    * @see http://flesler.demos.com/jquery/scrollTo/
    * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
    */

    // The default axis is 'y', but in this demo, I want to scroll both
    // You can modify any default like this
    $.localScroll.defaults.axis = 'x';

    // Scroll initially if there's a hash (#something) in the url 
    //    $.localScroll.hash({
    //        target: '#main', // Could be a selector or a jQuery object too.
    //        queue: true,
    //        duration: 1500
    //    });

    /**
    * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
    * also affect the >> and << links. I want every link in the page to scroll.
    */
    $.localScroll({
        target: '#main', // could be a selector or a jQuery object too.
        queue: true,
        duration: 1000,
        hash: false,
        onAfter: function(anchor, settings) {
            // The 'this' contains the scrolled element (#content)
        currentIndex = findIndexByHash('#' + anchor.id)
            setVisibilityForLinks();
        }
    });

    var diferencia = $(window).height() - $('#site').height();
    if (diferencia > 0) {
        $('#site').css({ marginTop: diferencia / 2 });
    }

    
    $('#lnk_Back').hide();

    $('#lnk_Back').click(function() {
        if (currentIndex > 0) {
            $('#main').stop().scrollTo(prevLinks[currentIndex], 1000, { axis: 'x' });
            currentIndex = findIndexByHash(prevLinks[currentIndex]);
            setVisibilityForLinks();
        }
    });

    $('#lnk_Next').click(function() {
        if (currentIndex < secciones.length - 1) {
            $('#main').stop().scrollTo(nextLinks[currentIndex], 1000, { axis: 'x' });
            currentIndex = findIndexByHash(nextLinks[currentIndex]);
            setVisibilityForLinks();
        }
    });

    function findIndexByHash(theHash) {
        for (i = 0; i < secciones.length; i++) {
            if (theHash == secciones[i]) {
                return i;
            }
        }
        alert("not found " + theHash);
        return 0;
    }

    function setVisibilityForLinks() {
        if (currentIndex == 0) {
            $('#lnk_Back').hide();
        } else {
            $('#lnk_Back').show();
        }
        if (currentIndex == secciones.length - 1) {
            $('#lnk_Next').hide();
        } else {
            $('#lnk_Next').show();
        }
    }

});