$(document).ready(function() {
	

	
	//	SLIDER
	
	$('#slider ul.buttons li.prev a').click(
		function () {
			
			if ($('#slider .inner ul').is(':animated')) return false;
			
			if ($('#slider .inner ul').css('left').replace('px','') <= -$('#slider .inner').width()  ) {
				$('#slider .inner ul').animate(
					{
						'left':'+=' + $('#slider .inner').width() + 'px'	
					},
					function () {
						if ($('#slider .inner ul').css('left').replace('px','') > 0 ) {
							$('#slider .inner ul').css({'left':'0px'});
						}
					}
				);
			}
			return false;
		}
	);
	
	$('#slider ul.buttons li.next a').click(
		function () {
			
			if ($('#slider .inner ul').is(':animated')) return false;
			
			if ($('#slider .inner ul').css('left').replace('px','') >= -$('#slider .inner ul').width() + $('#slider .inner ul').css('left').replace('px','') ) {
				$('#slider .inner ul').animate(
					{
						'left':'-=' + $('#slider .inner').width() + 'px'	
					}
				);
			} else {
				$('#tour .inner ul').animate(
					{
						'left':'-=' + $('#slider .inner ul').css('left')	
					}
				);
			}
			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 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 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').animate(
			{
				'top':'+=' + Math.abs(pos.top) + '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())) );				
				}
			}
		);	
	} 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);
	
}

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 = 4000; // 4 sec * 1000
slideTimeout = setTimeout('slide_next()', slideTimer);
