$(function(){
	$(".fotolong").css('width',($(".fotolong .foto").size()*242)+'px');
	$(".fotolong").css('left','0px');
	fotocount = $(".fotolong .foto").size();
	currentfoto = 1;
	fotoanimating = false;
	
	$(".fotovideo .leftarrow").click(function() {
		if (!fotoanimating) {
		
			fotoanimating=true;
			currentfoto--;
			if (currentfoto==0) {
				currentfoto=fotocount;
			}
		
			var newLeft = (currentfoto-1)*242*-1;
			
			$(".fotolong").animate({"left" : newLeft},function() {
				fotoanimating = false;
			});
			
			$(".caption").fadeOut();
			$(".caption"+currentfoto).fadeIn();
			$(".button").not($(".button"+currentfoto)).removeClass("selected");
			$(".button"+currentfoto).addClass("selected");
		
		}
	});
	$(".fotovideo .rightarrow").click(function() {
		if (!fotoanimating) {
		
			fotoanimating=true;
			currentfoto++;
			if (currentfoto>fotocount) {
				currentfoto=1;
			}
		
			var newLeft = (currentfoto-1)*242*-1;
			
			$(".fotolong").animate({"left" : newLeft},function() {
				fotoanimating = false;
			});
			
			$(".caption").fadeOut();
			$(".caption"+currentfoto).fadeIn();
			
			$(".button").not($(".button"+currentfoto)).removeClass("selected");
			$(".button"+currentfoto).addClass("selected");			
		}
	});	
	
	$(".fotovideo .button").click(function() {
	
		currentfoto = $(this).attr('rel');
		var newLeft = (currentfoto-1)*242*-1;
			
			$(".fotolong").animate({"left" : newLeft},function() {
				fotoanimating = false;
			});
			
			$(".caption").fadeOut();
			$(".caption"+currentfoto).fadeIn();
			
			$(".button").not($(".button"+currentfoto)).removeClass("selected");
			$(".button"+currentfoto).addClass("selected");				
		
	
	});
	
	
});
