// AJAX
$(document).ready(function() {
    
    var container = $('#container');
    
    // loads page from href into container
    function load_page(href) {

        container.fadeOut(300, loadContent);

        function loadContent() {
            $('#main').remove();
            container.load(href+' #main', showContent);
        }

        function showContent() {
            // kit style
            var kit = $('#main').attr('rel').substr(4);
            $('#kit-style').attr('href', 'kits/'+kit+'style.css');
            // menu position select
            $('#menu li a[href='+href+']').addClass('selected');
            // show new content
            container.fadeIn(600);
            $('#scroll-pane').jScrollPane();
            $("a[rel^='prettyPhoto']").prettyPhoto();
        }

    }

    // list of <a>'s that use ajax page load:
    // - all menu items
    // - logo link
    // - newsletter & feedback buttons
    // - cover mins
    var links = '#menu li a, #logo a, #newsletter-btn, #feedback-btn, #cds a';

    // link clicks event delegation
    $('#site').delegate(links, 'click', function(e) {
        e.preventDefault();
        play_sound();
        load_page($(this).attr('href'));
    });

});
