$(document).ready(function() {
	$(".foto").hover(function() {
		$(this).find("span").stop().animate({bottom:0},300);
	}).mouseout(function() {
		$(this).find("span").stop().animate({bottom:-18},300);		
	});
	var t = $("#slider");
	if(t) {
		var curPic=1,countPics=6,picWidth=581,timer,timeout=4000;
		var n=function(j) {var i=j+1;return(i>countPics)?1:i;};
		var r=function(){
			clearTimeout(timer);
			var newCurPic=n(curPic), newNextPic=n(newCurPic);
			$('div',t).each(function(i,e) {
				var el=$(e),n=el.attr("class").split("p").join("");
				if(n==curPic) el.stop(!0,!1).animate({left:-1*picWidth},500);
				else if(n==newCurPic) el.stop(!0,!1).animate({left:0},500);
				else if(n==newNextPic) el.stop(!0,!1).css("left",picWidth);
			});
			curPic = newCurPic;
			timer=setTimeout(r,timeout);
		};
		$(t).click(r);
		timer=setTimeout(r,timeout);
	}
});
