var ssInterval = 0;
jQuery(document).ready(function() {	
	// Get tabs
	var slideshow = jQuery('#slideshow');	
	if (slideshow.length > 0) {
		// Listeners
		jQuery('#slideshow .buttons a').click(function() {
			jQuery('#slideshow .buttons a').parent().attr('class', '');
			jQuery('#slideshow .slides li').fadeOut(500);
			
			var num = this.id.substr(this.id.indexOf('-')+1);
			jQuery('#slide-'+num).fadeIn(500);
			jQuery('#button-'+num).parent().attr('class', 'selected');
			
			window.clearInterval(ssInterval);
		});
	
		// Start animation
		window.clearInterval(ssInterval);
		ssInterval = window.setInterval(function() {
			// Find next
			var li = jQuery('#slideshow .buttons .selected');
			var next = li.next();
			if (next.length == 0) {
				next = jQuery('#slideshow .buttons li:first');
			}
			
			// Find number
			var id = next.children('a').attr('id');
			var num = id.substr(id.indexOf('-')+1);
			
			// Fade out
			jQuery('#slideshow .buttons a').parent().attr('class', '');
			jQuery('#slideshow .slides li').fadeOut(500);
			
			// Fade in
			jQuery('#slide-'+num).fadeIn(500);
			jQuery('#button-'+num).parent().attr('class', 'selected');
		}, 5000);
	}
});

