document.observe('dom:loaded', function() {
	$$('div.figure a').each(function(element) {
		var fileName = element.readAttribute('href');
		element.writeAttribute({
			href: '#enlarge_this_image'
		}).observe('click', function(event) {
			event.stop();
			$('overlay').addClassName('show').update(
				new Element('p', {
					className: 'caption'
				}).update(element.innerHTML.stripTags())
			).insert(
				new Element('p', {
					className: 'close'
				}).update(
					new Element('a', {
						href: '#close'
					}).update('閉じる').observe('click', function(event) {
						event.stop();
						$('overlay').removeClassName('show').update();
					})
				)
			).insert(
				new Element('p', {
					className: 'image'
				}).update(
					new Element('img', {
						src: fileName
					})
				)
			).centering();
		});
	});
});

