
function slideSwitch() {

//active button
 var current= $('#onlist .on').parent();
 
  if(current.next().length==0 ){
    $next_btn= $('#onlist li:first');
  }
  else {
    $next_btn=  current.next();
  }
 $next_btn.find('a').addClass('on'); 
 current.find('a').removeClass('on'); 
     
     
//switch slide

    var $active = $('#slideshow #slides IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow #slides IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow #slides IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(document).ready(function() {


//end slideSwitch()

	$(function() {
	    timer=setInterval( "slideSwitch()", 5000 );
	});

//buttons


	$('#slideshow').append("<div id='listWrapper'>"+
		"<ul id='onlist'>"+
		"</ul>"+
	"</div>");

	$('#slideshow img').each(function(){
		$('#onlist').append('<li><a href="#">&nbsp;<\/a><\/li>');
	});
			
	$('#onlist li:first a').addClass('on');
	

$("#onlist a").hover(
  function () {
  	run=0;
  	//stop animation
	clearInterval(timer);
	
  	//clear other hover states
  	c_btn=$('.on');
  	n_btn=$(this);
  	$(c_btn).removeClass('on');
    $(n_btn).addClass('on');
    
    //find position
    var index = $("#onlist li").index($(this).parent());
        
    //change slide
    var $active = $('#slideshow #slides img.active');
    var $next =  $('#slideshow #slides img').eq(index);

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    
  }, 
  function () {
  //restart animation 
  	run=1;
    timer = setInterval("slideSwitch()", 5000);
  }
);
});




