var timeoutID;
var delay = 15000;
function slideSwitch( selIndex ) {
    //alert(selIndex);
    if( selIndex != null ) {
        clearTimeout( timeoutID );
        $( '#slideshow div.slide' ).removeClass( 'active' );
        var activeDOMel = $( '#slideshow div.slide' ).get( selIndex-1 );
        var active = ( selIndex == 0 ) ? $('#slideshow div.slide:last') : $( activeDOMel )
        active.addClass( 'active' );
    }else {    
        var active = $('#slideshow div.active');
        if ( active.length == 0 ) 
            active = $('#slideshow div.slide:last');
    }
    
    // use this to pull the divs in the order they appear in the markup
    var next =  active.next().length ? active.next()
        : $('#slideshow div.slide:first');
        
    // uncomment below to pull the divs randomly
    // var sibs  = active.siblings();
    // var rndNum = Math.floor(Math.random() * sibs.length );
    // var next  = $( $sibs[ rndNum ] );    
    
    active.addClass('last-active');
        
    // hide the minislide
    if( selIndex == null ) {
        var nextSlideIndex = $( '#slideshow div.slide' ).index( next );
        var miniSlideOb = $( $( '.o_minislide' ).get( nextSlideIndex ) );
        switchMiniSlide( miniSlideOb, false );
    }

    // animate the slide
    next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('active last-active');
        });
    
    timeoutID = setTimeout( "slideSwitch(null)", delay );
}

function initSlideShow( aSlideIndex )
{
    timeoutID = setTimeout( 'slideSwitch(' + aSlideIndex + ')', delay );
}

