jQuery(document).ready(function() {
	getRandomPicture();  
});

function getRandomPicture(){
	//make ajax request
	jQuery.post( 'getRandom.php', '', function (xml){
  		gotNewPicture(xml);
  		} 
  	);
  	
  	
	setTimeout('getRandomPicture()', 7500);
}

function gotNewPicture(xml){
	//preload the image
	jQuery("<img>").attr("src", "imgs/db/700x500/" + $("imgName", xml).text()).attr("width", $("imgWidth", xml).text());
	//remove old picture
	$("#main > .content").fadeOut('slow', function(){hidePicture(xml);});
}

function hidePicture(xml){
	$("#main > .content").empty();
	$("#info > .content").empty();
	showPicture(xml);
}

function showPicture(xml){
	//add new picture
	$("#main > .content").append('<img class="painting" src="imgs/db/700x500/' + $("imgName", xml).text() +'" width="' + $("imgWidth", xml).text() + '" height="' + $("imgHeight", xml).text() +'" />');
	$("#info > .content").append("<h2>" + $("title", xml).text() + "</h2>");
	$("#info > .content").append($("infoText", xml).text());
	$("#main > .content").fadeIn('slow');
}
