newsClosed = false;

$(document).ready(function () {
    var imageObj = new Image();
    imagePath = "Images/OcchioDiBue.jpg"
    $(imageObj).attr("src", imagePath).load(function () {
        resizeWindow(null);
        $("#background").css("background-image", "url(" + imagePath + ")");
        $("#background").fadeIn(1000);
    });

    $(".news-button").hover(function () {
        $(this).addClass("pointer");
        $(this).css("background-position", "0 -12px");
    }, function () {
        $(this).css("background-position", "0 0");
    });

    $("#news-close").click(function () {
        newsClosed = true;

        // OPZIONALE
        $("#news-background").stop().animate({ height: 70 }, 300);

        $("#news-content").animate({ top: '-=' + $("#news-container").height() }, 300, function () {
            $("#news-close").css("display", "none");
            $("#news-open").css("display", "inline");
            resizeNews(true);
        });
    });

    $("#news-open").click(function () {
        newsClosed = false;

        $("#news-title").stop().animate({ left: ($("#news-wrapper").width() - 984) / 2 }, 200);
        $("#news-container").animate({ right: 0 }, 200, function () {
            $("#news-content").animate({ top: 0 }, 300);
            $("#news-close").css("display", "inline");
            $("#news-open").css("display", "none");

            // OPZIONALE
            $("#news-background").stop().animate({ height: $("#news-content").height() + 15 }, 200);
        });
    });
});

$(window).bind("resize", resizeWindow);
function resizeWindow( e ) {
	//$('#background').css ('background-position', String (($(window).width() - 1280) / 2) + 'px ' + String(($(window).height() - 1280) / 2) + 'px');
    resizeNews(false);
}

function resizeNews(animation) {
    if (newsClosed) {
        //newsPos = ($("#news-wrapper").width() + $("#news-title").width()) / 2 - 168;
        newsPos = ($("#news-wrapper").width() - 174);
        if ($("#news-wrapper").width() < 1024) { newsPos = $("#news-wrapper").width() - 174; };
        if (animation) {
            $("#news-container").stop().animate({ right: newsPos }, 200);
            $("#news-title").stop().animate({ left: 12 }, 200);

            

        } else {
            $("#news-container").css("right", newsPos);
            $("#news-title").css("left", 12);
        }

    } else {
        $("#news-title").css("left", ($("#news-wrapper").width() - 984) / 2);
    }
}
