function initializePortfolio(themepath) {
    // NOTE: THIS REQUIRES centerdiv.js TO HAVE ALREADY BEEN LOADED
    //
    // Define what happens when we click on a portfolio item
    $(".portfolio .gallery .gallery-item a").click(function(){
        var newImage = $(this).attr('href');
        $('#bigpic').empty();
        $('#bigpic').prepend('<img src="'+themepath+'/_img/ajax-loader.gif" />');
        centerDiv(0);
        $('#bigpic').load(newImage, function(data) {
            centerDiv(0);
        });
        stopSlideshow();
        return false;
    });

    // Now let's go ahead and load the first image by default
    changeImage (0);

    // Now set up our navigation between rows in the gallery
    var currRow = 0;
    $(".portfolio .gallery .gallery-row").hide();
    $(".portfolio .gallery .gallery-row:eq("+currRow+")").show();
    $(".portfolio .gallery").append('<div id="next-row-nav"><a href="#">&gt;</a></div>');
    $(".portfolio .gallery").prepend('<div id="prev-row-nav"><a href="#">&lt;</a></div>');
    $(".portfolio .gallery #prev-row-nav a").hide(); // Because we're on row 0 now

    $(".portfolio .gallery #next-row-nav a").click(function() {
        nextRow();
        return false;
    });

    $(".portfolio .gallery #prev-row-nav a").click(function() {
        prevRow();
        return false;
    });

    function nextRow()
    {
        currRow++;
        $(".portfolio .gallery .gallery-row").hide();
        $(".portfolio .gallery .gallery-row:eq("+currRow+")").show();
        // Now show/hide nav links
        $(".portfolio .gallery #prev-row-nav a").show();
        if (currRow == $(".portfolio .gallery .gallery-row").size() - 1)
        {
            $(".portfolio .gallery #next-row-nav a").hide();
        }
    }

    function prevRow()
    {
        currRow--;
        $(".portfolio .gallery .gallery-row").hide();
        $(".portfolio .gallery .gallery-row:eq("+currRow+")").show();
        // Now show/hide nav links
        if (currRow == 0)
        {
            $(".portfolio .gallery #prev-row-nav a").hide();
        }
        $(".portfolio .gallery #next-row-nav a").show();
    }

    // Next, let's set up the clickable bar that causes the whole thumbnail
    // navigation to show or hide itself

    $('.portfolio .gallery').prepend('<a href="#" id="toggle-thumbnails">Thumbnails</a>');
    $(".portfolio .gallery").css('height','13px');

    $(".portfolio .gallery").mouseenter(function() {
        var delay = 100 * 5;
        $(".portfolio .gallery #toggle-thumbnails").toggleClass("showing");
        $(".portfolio .gallery").stop();
        $(".portfolio .gallery").animate({
          "height": "113px"
        }, {duration: delay});
    });

    $(".portfolio .gallery").mouseleave(function() {
        var delay = $(".portfolio .gallery").height() * 5;
        $(".portfolio .gallery").stop();
        $(".portfolio .gallery").animate({
          "height": "13px"
        }, {duration: delay});
        setTimeout(function() {$(".portfolio .gallery #toggle-thumbnails").toggleClass("showing");}, delay);
    });

    // Now let's set up autoplay
    var autoplay = 1;
    var currImage = 0;
    var slideshow;

    $('#autoplay a').click(function() {
       if (autoplay)
       {
           // Turn it off
           stopSlideshow();
       }
       else
       {
           // Turn it on
           startSlideshow();
       }
       return false;
    });

    function changeImage(newImageNum)
    {
        numImages = $(".portfolio .gallery .gallery-item").size();
        if (newImageNum == numImages)
        {
            newImageNum = 0;
            currImage = 0;
        }
        var newImage = $(".portfolio .gallery .gallery-row .gallery-item a:eq("+newImageNum+")").attr('href');
        $('#bigpic').empty();
        $('#bigpic').prepend('<img src="'+themepath+'/_img/ajax-loader.gif" />');
        centerDiv(0);
        $('#bigpic').load(newImage, function(data) {
            centerDiv(0);
        });
    }

    function stopSlideshow()
    {
        // Modify the checkbox as needed
        $('#autoplay a').addClass('off');
        autoplay = 0;

        // Now actually stop the slideshow
        clearInterval(slideshow);
    }

    function startSlideshow()
    {
        // Modify the checkbox as needed
        $('#autoplay a').removeClass('off');
        autoplay = 1;

        // Now actually set up the slideshow
        slideshow = setInterval(nextImage,6000);
    }

    function nextImage()
    {
        currImage++;
        changeImage(currImage);
    }

    startSlideshow();

    // Now make the right menu work when we hover
    $("ul#portfolio-menu li").mouseenter(function() {
        $("ul#portfolio-menu li.current_page_item").addClass('current_page_item_off');
        $("ul#portfolio-menu li.current_page_item_off").removeClass('current_page_item');
        $(this).addClass('port-menu-hover');
    });

    $("ul#portfolio-menu li").mouseleave(function() {
        $("ul#portfolio-menu li.current_page_item_off").addClass('current_page_item');
        $("ul#portfolio-menu li.current_page_item").removeClass('current_page_item_off');
        $(this).removeClass('port-menu-hover');
    });
}
