var firstRun = true;
$(document).ready(function(){
	$(".paintings img").css("display","none");
	$(".paintings img[class=nojs]").css("display","inline");
});
$(window).load(function(){
	$(".paintings img").css("display","inline");
	$('.paintings').cycle({ 
		fx: 'scrollLeft',
		timeout: 5000,
		speed: 1000,
		before: doBefore,
		after: doAfter,
		pause: true
	});
});

function doBefore(){
	if(firstRun == false){
		$("#paintingcap p").slideUp(1000);
	}
	else {
		firstRun = false;
	}
	var imgwidth = $(this).width();
	var imgheight = $(this).height();
	var boxwidth = $(this).parent().parent().width();
	var boxheight = $(this).parent().parent().height();
	var moveleft = (boxwidth - imgwidth) / 2;
	var movedown = (boxheight - imgheight) / 2;
	$(this).css("margin-left",moveleft).css("margin-top",movedown);
}

function doAfter(){
	// Do the caption
	var caption = $('img',this).attr("alt");
	if(caption != null && caption != ""){
		$("#paintingcap p").html(caption).slideDown("fast");
	}
}

