
function fixArrowNews(move){
    if(move < parseInt($('.news').length - parseInt($('#news_window').width() / $('.news').outerWidth())))
        $('#news_arrow_dx').css('background-image','url("images/news_dx_on.png")');
    else
        $('#news_arrow_dx').css('background-image','url("images/news_dx_off.png")');

    if(move > 0)
        $('#news_arrow_sx').css('background-image','url("images/news_sx_on.png")');
    else
        $('#news_arrow_sx').css('background-image','url("images/news_sx_off.png")');

    $('#news_number').text(move+1+'/'+numNews);
}

$(document).ready(function(){
    $('#tappo').addClass('stappato');
    homeAnimation();

    numNews=$('.news').length;
    $('#news_number').text('1/'+numNews);
    newsWidth=numNews*$('.news:first').outerWidth(true);
    $('#news_row').width(newsWidth);
    $('#news_row').css('left',$('#news_window').width() - newsWidth);


    $('#menu_row').width($('.menu_item').length * ($('.menu_item').width()+parseInt($('.menu_item').css('padding-left'))+parseInt($('.menu_item').css('padding-right'))));


    var news_move = 0;
    fixArrowNews(news_move);

   $('#news_arrow_sx').click(function() {
        if(news_move > 0){
            $('#news_row').animate({'left' : parseInt($('#news_row').css('left'))-$('.news').outerWidth('true')});
            news_move--;
            fixArrowNews(news_move);
        }
    });

    $('#news_arrow_dx').click(function() {
        if(news_move < parseInt($('.news').length - parseInt($('#news_window').width() / $('.news').outerWidth('true')))){
            $('#news_row').animate({'left' : parseInt($('#news_row').css('left'))+$('.news').outerWidth('true')});
            news_move++;
            fixArrowNews(news_move);
        }
    });

    addSwipeListener(document.getElementById('menu'), function(e) {
        if(e.direction=='left'){
            $('#right_arrow').click();
        }
        else{
            $('#left_arrow').click();
        }
    });

    addSwipeListener(document.getElementById('news_window'), function(e) {
        if(e.direction=='left'){
            $('#news_arrow_sx').click();
        }
        else{
            $('#news_arrow_dx').click();
        }
    });
});

