/*
 * jQuery Slider
 *
 * Copyright (c) 2009 Domenico M. Maresca - domenico.maresca@gmail.com
 *
 * $Date: 2009-11-16 $
 * $Rev: 0.85.12 $
 */
$(document).ready(function(){
	var currentshow = 0;
	var maxshow = 5;
	var elements = $("#tours .tour").length;
	var movePx = 164;
	
	if(elements>maxshow){
		var timer = null;
		var scrollDir = 1;
		var timerDelay = 5000;
		var animationDuration = 1500;
		var currentshow = 0;
		
		function nextElements(){
			if(currentshow==elements-maxshow) return;
			currentshow++;
			moveElements();
		}
		
		function prevElements(){
			if(currentshow==0) return;
			currentshow--;
			moveElements();
		}
		
		function moveElements(){			
			var newPosition = currentshow * movePx;
			$("#tours").animate({'left': -newPosition},{duration: animationDuration});
		}
		
		function autoScrolling(){
			if(currentshow==elements-maxshow) scrollDir*=-1;
			else if(currentshow==0) scrollDir=1;
			if(scrollDir>0) nextElements();
			else prevElements();
		}
		
		$("a.next").click(function(){
			nextElements();
			clearInterval(timer);
		});
		$("a.prev").click(function(){
			prevElements();
			clearInterval(timer);
		});
		timer = setInterval(autoScrolling, timerDelay);
	}
});
