var sidebarStatus = true;

$(document).ready(function() 
{
        // Events
        $("#home-content .sidebar ul li").mouseenter(function() {
                jQuery(".over", this).fadeIn();
        }).mouseleave(function() {
                jQuery(".over", this).fadeOut();
        });
        
        $(".sidebar .button").click(function() 
        {
                var target = $(this).parent();
                target.animate( {marginLeft: sidebarStatus ? -(parseInt(target.css('width')) - 34) : 0}, 250, 'easeOutCirc');
                
                $(this).css("background-image", sidebarStatus ? "url(library/images/home/button_open.png)" : "url(library/images/home/button_close.png)");
                if (sidebarStatus)
                {
                        $(this).parent().children("ul").animate( {marginLeft: -200 }, 200, 'easeOutCirc');
                } else 
                {
                        $(this).parent().children("ul").animate( {marginLeft: 0 }, 200, 'easeOutCirc');
                }
                
                sidebarStatus = !sidebarStatus;
        })
        
       placeElements(); 
});

$(window).resize(function() { placeElements()} );


function placeElements()
{
        var proportion = ($(window).height() - 140 - 34) / 630;
        if (proportion > 1 || proportion < 0.5) proportion = 1;
        
        $(".sidebar").css("marginLeft", sidebarStatus ? 0 : -(parseInt($(".sidebar").css('width')) - 34));
        $(".sidebar ul").css("marginLeft", sidebarStatus ? 0 : -50);

	$("#home-content .background-image img").css("width", 1600 * windowHeight/808);
	$("#home-content .background-image img").css("height", windowHeight);
	$("#home-content .background-image img").css("right", -(((1600 * windowHeight/808) - (windowWidth - 234))/2));
	
        $("#home-content .sidebar").css("width", 235 * proportion + 34);
        $("#home-content .sidebar .background").css("width", 235 * proportion + 34);
        $("#home-content .sidebar ul li").css("width", 235 * proportion);
        $("#home-content .sidebar ul li").css("height", 145 * proportion);
        $("#home-content .sidebar ul li").children().css("width", 235 * proportion);
        $("#home-content .sidebar ul li").children().css("height", 145 * proportion);
        $("#home-content .sidebar ul li .over").css("width", 235 * proportion);
        $("#home-content .sidebar ul li .over").css("height", 145 * proportion);
        $("#home-content .sidebar ul li .over").children().css("width", 235 * proportion);
        $("#home-content .sidebar ul li .over").children().css("height", 145 * proportion);
}
