$(function(){
    // contact
    $("li#email").text("email: " + "jakub.stolarski+kaisho" + "@gmail.com");
    // gallery
    $("a.more").click(
        function() {
            var link = $(this);
            var gallery_id = link.attr('rel');
            var gallery_part = $('#gallery_part' + gallery_id);
            if (gallery_part.length) {
                gallery_part = gallery_part;
                if (gallery_part.css('display') == 'none')
                    link.text('Mniej...');
                else
                    link.text('Więcej...');
                gallery_part.toggle('slow');
            } else {
                var gallery = $('#gallery' + link.attr('rel'));
                gallery_part = $('<div id="gallery_part' + gallery_id + '"></div>');
                gallery.after(gallery_part);
                gallery_part.hide();
                gallery_part.load(link.attr('href') + '?ajax=', null,
                    function(){
                        link.text('Mniej...');
                        tb_init('#gallery_part' + gallery_id +' a.thickbox');
                        gallery_part.show('slow');
                    }
                );
            }
            return false;
        }
    );
    // contests
    $("#contests h3").click(
            function(){
                $(this).next().next().toggle('slow');
            }
        ).css('cursor', 'pointer');
    $("#contests h4").click(
            function(){
                $(this).next().toggle('slow');
            }
        ).css('cursor', 'pointer');
    $("#contests div").hide();
    
    // ranking
    $("#ranking h3").click(
            function(){
                $(this).next().toggle('slow');
            }
        ).css('cursor', 'pointer').next().hide();

    // menu
    $('#menu>ul>li>ul').hide();
    $('#menu>ul>li').hover(
            function(){
                $(this).children('ul').show('slow');
            },
            function(){
                $(this).children('ul').hide('slow');
            }
        ).click(
            function(){
                $('#menu>ul>li').children('ul').hide();
                $(this).children('ul').show();
                $('#menu>ul>li').unbind('mouseenter');
                $('#menu>ul>li').unbind('mouseout');
            });
    
    // exams
    $('#exams a').click(
            function(){
                $(this).next().toggle('slow');
            }
        ).next().hide();
});
