
var totPages;

function aggiornaNext(el)
{
    var val=parseInt($('#curr_page').text())+1;
    //$('<div class="simplePagerNav"> <a href="#" rel='+(val-1)+'></a></div>').find('a').click();
    if (val<=totPages)
    {
        $('#curr_page').html(val);
        if (val+1<=totPages)
        {
            el.attr('rel',val+1);
        }
        $('#prev_gallery_page a').attr('rel',val-1);
        Cufon.replace('#curr_page', {fontFamily: "HelvNeue"});
    }

}

function aggiornaPrev(el)
{
    var val=parseInt($('#curr_page').text())-1;
    // $('<div class="simplePagerNav"> <a href="#" rel='+(val+1)+'></a></div>').find('a').click();
    if (val>0)
    {
        $('#curr_page').html(val);

        if (val-1>0)
        {
            el.attr('rel',val-1);
        }
        $('#next_gallery_page a').attr('rel',val+1);
        Cufon.replace('#curr_page', {fontFamily: "HelvNeue"});
    }
}

$(document).ready(function()
{
    totPages=Math.ceil($("#media_gallery .elem_anno").length / 9);

    $('#total_pages').html(totPages);
    $('#curr_page').html(1);

    $("#media_gallery").quickPager({
        pageSize: 9,
        currentPage: 1,
        holder: ".pager"
    });

    $('#cities_unoxtutti').click(function()
    {
        $('#overlay').show();
        return false;
    });

    $('#close a').click(function()
    {
        $('#overlay').hide();
        return false;
    });

    $('#next_gallery_page a').live('click',function()
    {
        aggiornaNext($(this));
        //return false;
    });

    $('#prev_gallery_page a').live('click',function()
    {
        aggiornaPrev($(this));
        //return false;
    });

    
});
