// JavaScript Document
function slideSwitch(flag ) {
	clearInterval(myTimer);
	var $active = $('#slideshow a IMG.active');
	if ( $('#slideshow a:has(IMG.active)').length == 0 ) {
		$active = $('#slideshow a:last IMG');
	}	
	if (flag) {
		var $next = $('#slideshow a:has(IMG.active)').next().length  ? $('#slideshow a:has(IMG.active)').next().children('IMG') : $('#slideshow a:first IMG');
			
	} else {
		var $next = $('#slideshow a:has(IMG.active)').prev().length ? $('#slideshow a:has(IMG.active)').prev().children('IMG') : $('#slideshow a:last IMG');
	}
	
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
	myTimer = setInterval( slideSwitch, 5000, true);	
}
		
var myTimer;	
$(function() {
	myTimer = setInterval( slideSwitch, 5000, true);
	$('#imgprev').click(function() {
		slideSwitch(false);
	});
	$('#imgnext').click(function() {
		slideSwitch(true);
	});
});
