
function slideSwitch(direction) {
    
    if (direction != "previous" && direction != "next") {

	    var $active = $('#slideshow li.active');
	    var $previous = $active.prev
	    

	    if ( $active.length == 0 ) $active = $('#slideshow li:last');

	    // use this to pull the images in the order they appear in the markup
	    var $next =  $active.next().length ? $active.next()
		: $('#slideshow li:first');


	    $active.addClass('last-active').removeClass('active');

	    $next.css({opacity: 1.0});
		$next.addClass('active');
		$active.removeClass('active last-active');
	
	    $active.css({opacity: 0.0})


   }else{



		if (direction == "next") {
		    var $active = $('#slideshow li.active');
		    var $next =  $active.next().length ? $active.next()
		    		: $('#slideshow li:first');

		    clearInterval(timerint);

			    // use this to pull the images in the order they appear in the markup
			var $next =  $active.next().length ? $active.next()
			: $('#slideshow li:first');


			$active.addClass('last-active').removeClass('active');

			$next.css({opacity: 1.0});
			$next.addClass('active');
			$active.removeClass('active last-active');

			$active.css({opacity: 0.0})

			
			timerint=setInterval("slideSwitch()", 8000 );

		}




		if (direction == "previous") {
		    var $active = $('#slideshow li.active');
		    var $prev =  $active.prev().length ? $active.prev()
		    		: $('#slideshow li:last');

		    
		    clearInterval(timerint);

		    $active.addClass('last-active').removeClass('active');

		    $prev.css({opacity: 1.0});
		    $prev.addClass('active');
		    $active.removeClass('active last-active');
		
		    $active.css({opacity: 0.0})
		    
		    
		    timerint=setInterval("slideSwitch()", 8000 );

		}

	}
}



$(function() {

	function slideSwitchcall() {
	    timerint=setInterval("slideSwitch()", 8000 );
	}

	slideSwitchcall();

	$('#slideshow').bind("mouseenter",function() {
		clearInterval(timerint);
	});

	$('#slideshow').bind("mouseleave",function() {
		slideSwitchcall();
	});

	 $('#prevtopstory').click(function() {
	    slideSwitch('previous');
	  });

	 $('#nexttopstory').click(function() {
	    slideSwitch('next');
	  });


});