$(function() {

    var win = $(window),
    fullscreen = $('.full'),
    image = fullscreen.find('img'),
    imageWidth = image.width(),
    imageHeight = image.height(),
    imageRatio = imageWidth / imageHeight;

    function resizeImage() {
        var winWidth = win.width(),
        winHeight = win.height(),
        winRatio = winWidth / winHeight;

        if (winRatio > imageRatio) {
            image.css({
                width: winWidth,
                height: Math.round(winWidth / imageRatio)
            });
        } else {
            image.css({
                width: Math.round(winHeight * imageRatio),
                height: winHeight
            });
        }
    }

    win.bind({
        load: function() {
            resizeImage();
        },
        resize: function() {
            resizeImage();
        }
    });

    $("body").css("display", "none");
    $("body").fadeIn(600);
    $(".name").css("display", "none");
    $(".name").delay(700).fadeIn(2000);
    $(".nav").css("display", "none");
    $(".nav").delay(1500).fadeIn(900);
    
    $('a').click(function() {
        var divname = this.name;
        $("#" + divname).fadeToggle(900);
    });

    $(".openUp").click(function() {
        $(".content").slideToggle("fast");
    });

    $(".gsUp").click(function() {
        $("#gs").fadeIn(1000);
    });

    $("#switch").click(function() {
      $('.full').fadeToggle("slow").toggleClass('bodyBG');
      $('.nav>a').toggleClass('navToggle');
    });

    $('#dialog_link, ul#icons li').hover(
      function() { $(this).addClass('ui-state-hover'); }, 
      function() { $(this).removeClass('ui-state-hover'); }
    );

});
