var img;

$(document).ready(function() { 	
	$("#gallery").scrollable({
		size:7					   
	});
	
	$("#img").hover(function() {
		$("#bar").fadeIn("fast");
	}, function() {
		$("#bar").fadeOut("fast");
	});
	
	rotate($("#slideshow"));
	
	$("#img .title").html($(".scrollable img:first-child").attr("title").replace("/ ","<br />"))
	
	var src="";
	
	$(".scrollable img").mouseover(function() {
		$("#img .title").html($(this).attr("title").replace("/ ","<br />"))
	});
	
	$(".scrollable img").click(function() {
		src=$(this).attr("src").replace("/thumbs","");
		$("#img").addClass("loading");
		$("#toshow").fadeOut(250, function() {
			img = $("<img>").attr("src", src);
			img.load(function() {
				$("#toshow").html($(this)).fadeIn(250, function() {
					$("#img").removeClass("loading");
				});
			});
		});
	});
});

function rotate(div) {
	var counter=0;
	var slides=[];
	div.find("img").each(function() {
		slides[counter]=$(this);
		counter++;
	});
	counter=0;
	
	var t=setInterval(function() {
		slides[counter].fadeOut(1000);
		counter++;
		if(counter>slides.length-1) {
			counter=0;
		}
		slides[counter].fadeIn(1000);
	}, 3000)
}
