var slide_t;

$(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;
		}
	);
	
	//	SLIDER
	
	$('#main-content .slider .info-nav li a').click(
		
		function () {
			
			clearTimeout(slide_t);
			
			if ($(this).hasClass('active')) return false;
			
			var indexOld = $(this).parent().parent().children('li').children('a').index( $(this).parent().parent().children('li').find('.active'));
			var index = $(this).parent().parent().children('li').children('a').index($(this));
			var sign = '+';
			if (index > indexOld) sign = '-';
			
			$(this).parent().parent().children('li').find('.active').removeClass('active');
			$(this).addClass('active');
			
			$('#main-content .slider .slider-content-wrapper').children('.slider-content:eq(' + indexOld + ')') .fadeOut(500, function () {
				$('#main-content .slider .slider-content-wrapper').children('.slider-content:eq(' + index + ')') .fadeIn();
			});

			
		
			
		}
	
	);
	
});

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 div.img:visible');
	slide.fadeOut();
	var prev = slide.prev();
	if (prev.length == 0) {
		prev = $('#slideshow .photos div.img:last');
	}
	prev.fadeIn();
	
	slide_mark_dot($('#slideshow .photos div.img').index( prev ) );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

function slide_next() {
	
	var slide = $('#slideshow .photos div.img:visible');
	slide.fadeOut();
	var next = slide.next();
	if (next.length == 0) {
		next = $('#slideshow .photos div.img:first');
	}
	next.fadeIn();
	
	slide_mark_dot($('#slideshow .photos div.img').index( next ) );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

function slide_index(index) {
	
	var slide = $('#slideshow .photos div.img:visible');
	slide.fadeOut();
	var next = $('#slideshow .photos div.img:eq(' + index + ')');
	if (next.length == 0) {
		next = $('#slideshow .photos div.img:first');
	}
	next.fadeIn();
	
	slide_mark_dot($('#slideshow .photos div.img').index( next ) );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

slideTimer = 4000; // 4 sec * 1000
slideTimeout = setTimeout('slide_next()', slideTimer);
