var num_textures_scroll_per_page = 12;
var textures_list = new Array();
var texture_scroll_selected = 0;

function init_scrolls_textures() {

    $('#arrow-top-tex').unbind('click');
    $('#arrow-top-tex').click(function() {
        scroll_bottom_textures();
    });

    $('#arrow-bottom-tex').unbind('click');
    $('#arrow-bottom-tex').click(function() {
        scroll_top_textures();
    });
}

/*
 *  TEXTURES
 */

function init_textures_scroll() {

    $('#textures').scrollTo( 0, 800, {queue:true} );

    var first_index_value = textures_list[0];
    $.aux = $('#' + first_index_value);
//    $('#products').scrollTo( $.aux, 800, {queue:true} );

    texture_scroll_selected = 0;

    // DISABLE ARROW LEFT
    $('#arrow-top-tex').removeClass('arrow-top-tex');
    $('#arrow-top-tex').addClass('arrow-top-tex-disabled');

    // TEST ARROW RIGHT
    if ( num_textures_scroll_per_page > (textures_list.length - 1) ) {
        // DISABLE ARROW RIGHT
        $('#arrow-bottom-tex').removeClass('arrow-bottom-tex');
        $('#arrow-bottom-tex').addClass('arrow-bottom-tex-disabled');
    }
    else {
        // ENABLE ARROW RIGHT
        $('#arrow-bottom-tex').removeClass('arrow-bottom-tex-disabled');
        $('#arrow-bottom-tex').addClass('arrow-bottom-tex');
    }
}

function clean_textures_scroll() {
    $('#arrow-top-tex').removeClass('arrow-top-tex');
    $('#arrow-top-tex').addClass('arrow-top-tex-disabled');

    $('#arrow-bottom-tex').removeClass('arrow-bottom-tex');
    $('#arrow-bottom-tex').addClass('arrow-bottom-tex-disabled');
}

function scroll_top_textures() {

    if ( (texture_scroll_selected + num_textures_scroll_per_page) > (textures_list.length - 1) ) {
        // NO SCROLL (last page)
    }
    else {
        var next_index = texture_scroll_selected + num_textures_scroll_per_page;
        var next_index_value = textures_list[next_index];

        $.aux = $('#' + next_index_value);

        $('#textures').scrollTo( $.aux, 800, {queue:true} );
        texture_scroll_selected += num_textures_scroll_per_page;
    }

    /* TEST NEXT PAGE TO ENABLE/DISABLE ARROWS */

    if ( (texture_scroll_selected + num_textures_scroll_per_page) > (textures_list.length - 1) ) {
        // DISABLE ARROW RIGHT
        $('#arrow-bottom-tex').removeClass('arrow-bottom-tex');
        $('#arrow-bottom-tex').addClass('arrow-bottom-tex-disabled');
    }
    if ( texture_scroll_selected > 0 ) {
        // ENABLE ARROW LEFT
        $('#arrow-top-tex').removeClass('arrow-top-tex-disabled');
        $('#arrow-top-tex').addClass('arrow-top-tex');
    }
}

function scroll_bottom_textures() {

    if ( (texture_scroll_selected - num_textures_scroll_per_page) < 0 ) {
        // NO SCROLL (first page)
    }
    else {
        var next_index = texture_scroll_selected - num_textures_scroll_per_page;
        var next_index_value = textures_list[next_index];

        $.aux = $('#' + next_index_value);

        $('#textures').scrollTo( $.aux, 800, {queue:true} );
        texture_scroll_selected -= num_textures_scroll_per_page;
    }

    /* TEST NEXT PAGE TO ENABLE/DISABLE ARROWS */

    if ( texture_scroll_selected == 0 ) {
        // DISABLE ARROW LEFT
        $('#arrow-top-tex').removeClass('arrow-top-tex');
        $('#arrow-top-tex').addClass('arrow-top-tex-disabled');
    }
    if ( (texture_scroll_selected + num_textures_scroll_per_page) <= (textures_list.length - 1) ) {
        // ENABLE ARROW RIGHT
        $('#arrow-bottom-tex').removeClass('arrow-bottom-tex-disabled');
        $('#arrow-bottom-tex').addClass('arrow-bottom-tex');
    }
}
