// rivistaPhoto.class.js
// automatically creates markup from a photo
// requires prototype.js

Event.observe(window, 'load', function() {
	var photos = $$(".photo-caption");
	for (var i=0; i < photos.length; i++) {
		newPhoto = photos[i].cloneNode(false);
		newPhoto.className = "";
		var photoAltText = photos[i].getAttribute("alt");
		var newDiv = document.createElement("div");
		newDiv.className = photos[i].className;
		newDiv.style.width = (photos[i].width+"px");
		var caption = document.createElement("p");
		var captionText = document.createTextNode(photoAltText);
		caption.appendChild(captionText);
		newDiv.appendChild(newPhoto);
		newDiv.appendChild(caption);
		var parentEl = photos[i].parentNode;
		parentEl.insertBefore(newDiv,photos[i]);
		parentEl.removeChild(photos[i]);
	}
});
