function slide_mark_dot(index) {
	
	 $('#slideshow .dots-nav a').removeClass('active');
	 $('#slideshow .dots-nav a:eq(' + index + ')').addClass('active');
	
}

function slide_prev() {
	
	var pos = $('#slideshow .photos').position();
	if (parseInt(pos.top) + parseInt($('#slideshow .photos img:first').height()) > 0 ) {
			$('#slideshow .photos').animate({
				'top':'-=' + (parseInt($('#slideshow .photos img:first').height()) * (parseInt($('#slideshow .photos img').length)-1) ) + 'px' 
			},
			500,
			'swing',
			function () 
			{ 
				var pos = $('#slideshow .photos').position();
				slide_mark_dot( Math.round(parseInt(pos.top) / parseInt(-$('#slideshow .photos img:first').height())) );
			}
		);	
	} else {
		$('#slideshow .photos').animate(
			{
				'top':'+=' + $('#slideshow .photos img:first').height() + 'px' 
			},
			500,
			'swing',
			function () 
			{ 
				var pos = $('#slideshow .photos').position();
				slide_mark_dot( Math.round(parseInt(pos.top) / parseInt(-$('#slideshow .photos img:first').height())) );				
			}
		);
	}
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

function slide_next() {
	
	var delay = 1;
	var pos = $('#slideshow .photos').position();
	if (parseInt(pos.top) - parseInt($('#slideshow .photos img:first').height()) <= (-parseInt($('#slideshow .photos img:first').height()) * (parseInt($('#slideshow .photos img').length)) ) ) {
		$('#slideshow .photos').css({'top':'0px'});	
		delay = 2;
	} else {
		$('#slideshow .photos').animate(
			{
				'top':'-=' + $('#slideshow .photos img:first').height() + 'px' 
			},
			{
				duration: 1000,
				easing:'easeInOutCirc',
				complete: function () 
				{ 
					var pos = $('#slideshow .photos').position();
					slide_mark_dot( Math.round(parseInt(pos.top) / parseInt(-$('#slideshow .photos img:first').height())) );				
				}
			}
		);
	}
	
	
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer * delay);
	
}

function slide_index(index) {
	
	var pos = $('#slideshow .photos').position();
	
	if ( parseInt(pos.top) <= parseInt(-$('#slideshow .photos img:first').height() * index) ) {
		$('#slideshow .photos').animate({
			'top':'+=' + Math.abs((Math.abs(parseInt(pos.top)) - parseInt($('#slideshow .photos img:first').height() * index))) + 'px' 
		});
	} else {
		$('#slideshow .photos').animate({
			'top':'-=' + Math.abs((Math.abs(parseInt(pos.top)) - parseInt($('#slideshow .photos img:first').height() * index))) + 'px' 
		});
	}
	
	slide_mark_dot( index );
	
	clearTimeout(slideTimeout);
	slideTimeout = setTimeout('slide_next()', slideTimer);
	
}

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