$(document).ready(function($) {
	bannerInterval = setInterval( "slideSwitch()", rotateSpeed );

	$('#slideshow-dots a').each(function() {
		$(this).click(function() {
			clearInterval(bannerInterval);
			bannerInterval=null;
			anID = $(this).children('span').attr('id').split('-');
			slideSwitch('slideshow-'+anID[1]);
			return false;
		});
	});
});
var bannerInterval;
var rotateSpeed = 5000;
function slideSwitch(obj) {
   
	var $active = $('#slideshow-container div.activeslide');
	
	//alert($active.attr('id'))
    if ( $active.length == 0 ) $active = $('#slideshow-container div.slideshow:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow-container div.slideshow:first');
	if (obj!==undefined) {
		$next = $('#'+obj);
	}
    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	
	
	var dot = $next.attr('id').split('-');
	$nextdot = $('#dots-'+dot[1]).children('img');
	$('#slideshow-dots img').attr('src',$nextdot.attr('src').replace('-w',''));
	

	ss = $nextdot.attr('src').split('/');
	aa = ss[ ss.length-1 ] = ss[ ss.length-1 ].split('.');
	aa[0] = aa[0]+'-w';
	newfname = aa.join('.');
	ss[ ss.length-1 ] = newfname;
	var newsrcobj = ss.join('/');
	$nextdot.attr('src',newsrcobj);
	
	
    $next.css({opacity: 0.0})
        .addClass('activeslide')
        .animate({opacity: 1.0}, 'fast', function() {
            $active.removeClass('activeslide last-active');
			if (bannerInterval==null) {
				bannerInterval = setInterval( "slideSwitch()", rotateSpeed );
			}
        });

}
