$(document).ready(function(){
    /* here comes my code */
    var lang = $('#aboutMe').html();
    if (lang == 'Me')
    {
        lang = 'en';
    }
    else
    {
        lang = 'fr';
    }
    
    $(window).load(function()
    {/* nice fade-in to display the 3 buttons */
        /* update time in the banner */
        var currentDate = new Date();
        $('#siteBannerTime').html(currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds());

        /* display buttons */
        $('.divButton').fadeIn('slow');
    });

    $('.aboutButton').click(function()
    {/* when aboutMenu is clicked */
        /* update time in the banner */
        var currentDate = new Date();
        $('#siteBannerTime').html(currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds());

        /* change page content */
        
        return false;
    });

    $('#siteBanner').click(function()
    {
        /* Reload home page */
        if (lang == 'en')
        {
            window.location = 'http://orny.me?lng=en';
        }
        else
        {
            window.location = 'http://orny.me';
        }
    });

    $('#cv').click(function()
    {/* when cv is clicked */
        /* update time in the banner */
        var currentDate = new Date();
        $('#siteBannerTime').html(currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds());
        
        /* change page content */
        $.ajax(
        {
            type: 'GET',
            url: './misc/contents/cv.php',
            success: function(content)
            {
                $('#content').html(content);
                $('#content').animate({marginLeft: '20%', marginRight: '20%'});
                $('#cv').animate({marginTop:'3%'}, 'slow');
                $('#blog').animate({marginLeft:'5%', marginTop:'0%'}, 'slow');
                $('#content').animate({marginTop:'-20%'}, 'slow');
                $('#works').animate({marginLeft:'82%', marginTop:'5%'}, 'slow');
                $('#cv').animate({marginLeft:'43%'}, 'slow', function()
                {
                    $('#footer').css({position: 'relative'});
                    $('#bio').fadeOut('normal');
                    $('#content').fadeIn('slow');
                });
            }
         });
         
         return false;
    });


    $('#works').click(function()
    {/* when cv is clicked */
        /* update time in the banner */
        var currentDate = new Date();
        $('#siteBannerTime').html(currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds());

        /* change page content */
        $.ajax(
        {
            type: 'GET',
            url: './misc/contents/works.php',
            success: function(content)
            {
                $('#footer').css({position: 'fixed'});
                $('#content').html(content);
                $('#content').animate({marginLeft: '20%', marginRight: '20%'});
                $('#works').animate({marginTop:'-20%'}, 'slow');
                $('#cv').animate({marginTop:'15%', marginLeft:'82%'}, 'slow');
                $('#content').animate({marginTop:'-15%'}, 'slow');
                $('#blog').animate({marginLeft:'5%', marginTop:'8%'}, 'slows');
                $('#works').animate({marginLeft:'43%'}, 'slow', function()
                {
                    $('#bio').fadeOut('normal');
                    $('#content').fadeIn('slow');
                });
            }
         });

         return false;
    });

    $('.aboutButton').click(function()
    {/* when about button is clicked */
        /* update time in the banner */
        var currentDate = new Date();
        $('#siteBannerTime').html(currentDate.getHours()+':'+currentDate.getMinutes()+':'+currentDate.getSeconds());

        if ( $('.aboutElements a').css('display') == 'none')
            {
                $('.aboutElements a').show({display:'block'}, 'slow');
                $('.aboutElements h1').show({display:'block'}, 'slow');
            }
        else
            {
                $('.aboutElements *').hide('fast');
            }
            
        return false;
    });

    $('.aboutElement').click(function()
    {
        var thatThis = $(this);

        $('.menuButton').fadeOut('normal');
        $('#bio').fadeOut('200', function(){
            if( thatThis.attr('id') == 'aboutConditions')
            {
                $('#footer').css({position: 'relative'});
            }
            else
            {
                $('#footer').css({position: 'fixed'});
            }
            
            $('#content').html($('div.'+thatThis.attr('id')).html());
            $('#content').fadeIn(1500);
            $('#content').css({marginTop: '30px'});
        });

        return false;
    });
});
