﻿function slideSwitch(dir) {
    var $active = $('#slideshow img.active');

    if ($active.length == 0) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next = (dir == 1) ? ($active.next().length ? $active.next()
        : $('#slideshow img:first')) : ($active.prev().length ? $active.prev()
        : $('#slideshow img:last'));

    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$.preloadImages = function() {
    var images = arguments[0];
    var container = arguments[1];
    for (var i = 0; i < images.length; i++) {
        $("<img>").attr("src", $(images[i]).attr("src")); 
        /*.bind("load", (function() {
            if (i == images.length - 1)
                $(container).css({ 'visibility': 'visible' });
        }))*/
    }
}

function slideManualSwitch(dir) {
    slideSwitch(dir);
}

$(document).ready(function() {
    $.preloadImages($('#slideshow').children(), $('.about-slideshow'));
    $('.about-slideshow').css({ 'visibility': 'visible' });
});

