$(function() {
    
    //get artist links
    $("#artists").load("/wp-content/themes/default/ajax/artists.php", {links: '-1'}, function() {
        
        //individual artist listeners
        $('#artists a.artist').click(function(){
            
            $('#navigation a').each(function() {
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
            
            $('#gallery .content').hide();
            var artistid = $(this).attr('id').split('-');
            artistid = artistid[1];
        
            if ($('#artistcontent-' + artistid).length == 0) { //new artist request, load information and display
                
                $.post("/wp-content/themes/default/ajax/artists.php", {content: $(this).attr('id')}, function(data) {
                    $('#gallery').append(data);
                    $("a[rel^='prettyPhoto']").prettyPhoto();
                    $('#artistcontent-' + artistid).show();
                });
                
            } else { //artist already loaded, display
                $('#artistcontent-' + artistid).show();
            }
            
            $('html,body').animate({scrollTop: $('#gallery').offset().top}, 1000); //scroll to top of gallery
            
            return false;
        });
        
    });
    
    //exhibition information listener
    $('#navigation a.exhibition').click(function(){
        $('#navigation a').each(function() {
            $(this).removeClass('selected');
        });
        $(this).addClass('selected');
        $('#gallery .content').hide();
        $('#exhibitioncontent').show();
        return false;
    }).addClass('selected');
    
});