/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license
    
***/

function slideSwitch(bannername) {
    var $active = $('#'+bannername+' IMG.active');

    if ( $active.length == 0 ) $active = $('#'+bannername+' IMG:last');
	//alert($active.next().length+' xx '+$active.length);
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#'+bannername+' IMG:first');
	if($next.attr('id')==''){
		$next = $('#'+bannername+' IMG:first');
	}
    $active.addClass('last-active');
    
    var nextid = $next.attr('id');
    var startbanner = nextid.indexOf('_') + 1;
    var startno = nextid.indexOf('-') + 1;
    var bannerclass = nextid.substr(startbanner, nextid.indexOf('-'));
    var bannerno = nextid.substr(startno, nextid.length);
    if((bannerno - 1)==0) {
    
   		var thisid = $active.attr('id');
    	var startno = thisid.indexOf('-') + 1;
    	var bannerprev = thisid.substr(startno, thisid.length);
	}else 
    	var bannerprev = bannerno - 1;
    	
    $('#switcher_'+bannerclass+'-'+bannerprev).removeClass( 'sactive' ); 
    $('#switcher_'+bannerclass+'-'+bannerno).addClass( 'sactive' );
    
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
}
var next_timer;
$(document).ready(function() {   
	if($('#switcher_bannertop-1').length>0){
	    $('#switcher_bannertop-1').addClass( 'sactive' );
	    next_timer = setInterval("slideSwitch('bannertop')",8000);
	    $('ul.swicher li').click( function() {
		    clearInterval(next_timer);
 			next_timer = setInterval("slideSwitch('bannertop')",8000);

	        $('ul.swicher li').removeClass( 'sactive' );
			$(this).addClass( 'sactive' );
	        var thisswitch    = $(this).attr('id');	
		    var startno = thisswitch.indexOf('_') + 1;
		    var bannername = thisswitch.substr(startno, thisswitch.length);
		    $('.slideshow IMG').removeClass( 'active' );
		    $('#'+bannername).addClass('active').fadeIn('1000');
			//next_timer = setInterval("slideSwitch('bannertop')",8000);
	    });
    }
});


