/*** 
    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 :)
***/

//nastaveni parametru pro imageshow

var intervalNext;

function slideSwitchNextInterval() {		
	
var numberPict = $('#topSlideshow').children().size();
	
	if(numberPict > 1) {
    var $active = $('#topSlideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#topSlideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#topSlideshow IMG:first');            
           
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
   }
}

function slideSwitchNext() {		
		clearInterval(intervalNext);
    var $active = $('#topSlideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#topSlideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#topSlideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitchPrev() {
		clearInterval(intervalNext);
    var $active = $('#topSlideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#topSlideshow IMG:first');

    var $prev =  $active.prev().length ? $active.prev()
        : $('#topSlideshow IMG:last');

    $active.addClass('last-active');

    $prev.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
}

function setDefault() {
	 var $active = $('#topSlideshow IMG.active');

    if ( $active.length == 0 ) { 
			 var $sibs  =$('#topSlideshow IMG');
			var rndNum = Math.floor(Math.random() * $sibs.length );			
			$active=$( $sibs[ rndNum ] );			
			$active.addClass('active');
		}
		
		$('#topSlideshow').css("visibility", "visible");
}

$(document).ready(function() {
		
		if(typeof(timerPict) != 'undefined') {
    intervalNext = setInterval("slideSwitchNextInterval()", timerPict );
		
    setDefault();
    $('#topSlideshowControlPrev').bind("click", function(e){ slideSwitchPrev()});
    $('#topSlideshowControlNext').bind("click", function(e){ slideSwitchNext()});
    }
 });


