$(document).ready(function() {
	
	//	SLIDESHOW
	
	$('#slideshow ul.buttons li.prev a').click(
		function () {
			slide_prev();
			return false;
		}
	);
	
	$('#slideshow ul.buttons li.next a').click(
		function () {
			slide_next();
			return false;
		}
	);
	
	$('#slideshow ul.dots-nav li a').click(
		function () {
			slide_index( $('#slideshow ul.dots-nav li a').index( this ) );
			return false;
		}
	);
	
});

function slide_mark_dot(index) {
	
	 $('#slideshow .dots-nav a').removeClass('active');
	 $('#slideshow .dots-nav a:eq(' + index + ')').addClass('active');
	
}

function slide_prev() {
	
	var slide = $('#slideshow .photos img:visible');
	slide.fadeOut();
	var prev = slide.prev();
	if (prev.length == 0) {
		prev = $('#slideshow .photos img:last');
	}
	prev.fadeIn();
	
	slide_mark_dot($('#slideshow .photos img').index( prev ) );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

function slide_next() {
	
	var slide = $('#slideshow .photos img:visible');
	slide.fadeOut();
	
	var current = $('#slideshow .photos img').index( slide );
	current++;
	var next = $('#slideshow .photos img:eq(' + current + ')');
	if (next.length == 0) {
		next = $('#slideshow .photos img:first');
	}
	next.fadeIn();
	
	slide_mark_dot($('#slideshow .photos img').index( next ) );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

function slide_index(index) {
	
	var slide = $('#slideshow .photos img:visible');
	slide.fadeOut();
	var next = $('#slideshow .photos img:eq(' + index + ')');
	if (next.length == 0) {
		next = $('#slideshow .photos img:first');
	}
	next.fadeIn();
	
	slide_mark_dot($('#slideshow .photos img').index( next ) );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

slideTimer = 6500; // 4 sec * 1000
slideTimeout = setTimeout('slide_next()', slideTimer);
