// User font size with cookie
www_istat_it.userFontSize =
{
    name:"fontSize",
    options:{'path':'/','expires':30},
    init:function() {
        var userSize = www_istat_it.cookie(this.name);
        if (userSize==null || userSize=="")
            www_istat_it.fontSize.init();
        else
            www_istat_it.fontSize.size(userSize);
    },
    smaller:function()
    {
        www_istat_it.cookie(this.name, www_istat_it.fontSize.smaller(), this.options);
    },
    larger:function()
    {
        www_istat_it.cookie(this.name, www_istat_it.fontSize.larger(), this.options);
    },
    reset:function()
    {
        www_istat_it.fontSize.reset();
        www_istat_it.cookie(this.name, null);
    }
}

$(document).ready( function() {

    var labelStatistics = 'Statistics by';
    if ('it' == www_istat_it.state.lang)
        labelStatistics = 'Statistiche per';
        
    $('#header').append('<div id="label statistics" style="position:relative;color:#7aba3c;font-size:24px;float:right;clear:right;top:-2.5em;">' + labelStatistics + '</div>');
    
    www_istat_it.userFontSize.init();  
    // Console
    var consoleActive = $("#console li." + www_istat_it.state.lang);
    consoleActive.addClass('active');
    $("#tabs > li").hover(
        function () {
            $(this).siblings("li").removeClass('active');
            $(this).addClass('active');
        },
        function () {
            $(this).removeClass('active');
            consoleActive.addClass('active');
        }
    );

    // Menu docs
    var menuActive = $("#header > .menuList li.active");
    $("#header > .menuList > li *").hover(
        function() {
            $(this).parentsUntil('.menuList').addClass('active');
            // IE fa on orrendo sfarfallio...
            // Non si risolve con un setTimeout
            $(this).parentsUntil('.menuList').siblings("li").removeClass('active');
        },
        function() {
            menuActive.addClass('active');
            $(this).parentsUntil('.menuList').removeClass('active');
        }
    );

    // Menu I.Stat
    var IDotStatActive = $("#header > .IDotStatList li.active");
    //$("#header > .IDotStatList > li *").hover(
    $("#header > .IDotStatList > li > a, #header > .IDotStatList > li > ul").hover(
        function() {
            $(this).parentsUntil('.IDotStatList').addClass('active');
            $(this).parentsUntil('.IDotStatList').siblings("li").removeClass('active');
        },
        function() {
            IDotStatActive.addClass('active');
            $(this).parentsUntil('.IDotStatList').removeClass('active');
        }
    );
    var IDotStatLiActive = $("#header > .IDotStatList > li > ul > li.active");
    $('#header > .IDotStatList > li > ul > li').hover(
        function() {
            $(this).addClass('active');
            $(this).siblings('li').removeClass('active');
        },
        function() {
            $(this).removeClass('active');
            IDotStatLiActive.addClass('active');
        }
    );

    // Alternate
    $('.alternate').prev('img').click(function() {
            $(this).next('.alternate').slideToggle('fast');
    });
    
    // Sidebar
var sidebar = new Array();
sidebar['it'] = 48812;
sidebar['en'] = 48815;
$(document).ready(function() {
    $.getJSON("/proxy.php?url=" + escape("http://docs.istat.it/www/ws/ws.php?action=post&id=" + sidebar[www_istat_it.state.lang]), function(data) {
        $('#sidebar_page').html(data[sidebar[www_istat_it.state.lang]]['page']);
    });
});

    if ($('#sidebar').outerHeight() > $('#body').outerHeight(true))
        $('#body').height($('#sidebar').outerHeight(true) - $('#body').css('padding-top').substr(0, $('#body').css('padding-top').length -2));
    else 
        setTimeout("if($('#sidebar').outerHeight() < $('#body').outerHeight(true)) $('#sidebar').height($('#body').outerHeight(true))",500);         
  });  
  

