/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
	// Brainweb: não utilizar DIV#slide.active pois o IE não reconhece
    var $active = $('#slideshow DIV.activeSlide');
    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');

    $next.css({opacity: 0.0}) //display: 'block', 
        .addClass('activeSlide')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('activeSlide last-active');
            	//.css({display: 'none'});
        });
}

function goToSlide(numberToActivate){
	// Brainweb: não utilizar DIV#slide.active pois o IE não reconhece	
	var $toDeactivate = $('#slideshow DIV.activeSlide');
	var $numberToDeactivate = $('#slideshow DIV.activeSlide #numero').val();
	if($numberToDeactivate != numberToActivate){
		var $slide = $('#slideshow DIV#slide:first');
		var $toActivate;
		for(var i = 1; i <= 4; i++){
			if(i == numberToActivate){
				$toActivate = $slide;
				break;
			}else{
				$slide = $slide.next();
			}
		}
		// activate the selected slide to deactivate current slide
		$toActivate.css({opacity: 0.0}) //, display: 'block'
			.addClass('activeSlide')
			.animate({opacity: 1.0}, 1000, function() {
				$toDeactivate.removeClass('activeSlide last-active');
				//.css({display: 'none'});
			});
	}
	// stop the slideshow
	clearInterval(idSlideSwitch);
}
var idSlideSwitch;
$(function() {
    idSlideSwitch = setInterval( "slideSwitch()", 8000 );
});
