function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(document).ready(function() {
    var slide_height = "198";

    var r = Math.floor((Math.random() * 100) % 39);
    var n = 0;
    $(".slide img").each(function(){
        if (r == n) $(this).addClass("active");
    	n++;
    });

    $(".slide").each(function(){
        var html_data = $(this).html();
        $(this).html("<div id='slideshow'>" + html_data + "</div>");
        slide_height = $(this).height();
    });

    $("#slideshow").height(slide_height + "px").each(function(){
        setInterval( "slideSwitch()", 5000 );
    });
    $("#slideshow").css("cursor", "pointer").click(function(){ document.location.href = "/clients"; });
});
