//http://dean.edwards.name/weblog/2006/06/again/
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, null);
}
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		init(); // call the onload handler
	}
};
/*@end @*/
if (/WebKit/i.test(navigator.userAgent)) {
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			clearInterval(_timer);
			init();
		}
	}, 10);
}
function init() {
	if (arguments.callee.done) return;
  arguments.callee.done = true;
	if (self.pageLoaded) pageLoaded();
	addCaption("vasen");
  addCaption("oikea");
}
window.onload = init;

// original from:
// http://www.boagworld.com/archives/2006/07/styled_images_with_caption.html
function addCaption(xClass) {
var allImages = getElementsByClassName(xClass, "img", document);
for ( var i=0; i < allImages.length; i++) {
if (!allImages[i].title) continue;
var imageCaption = document.createTextNode(allImages[i].title);
var imageContainer = document.createElement("div");
var imagePara = document.createElement("span");
var imageWidth = allImages[i].getAttribute("width");
imagePara.appendChild(imageCaption);
allImages[i].parentNode.insertBefore(imageContainer, allImages[i]);
imageContainer.appendChild(allImages[i]);
var br = document.createElement("br");
imageContainer.appendChild(br);
if ( allImages[i].title != "" ) {
imageContainer.appendChild(imagePara);
}
imageContainer.className = xClass
allImages[i].className = "img"
imageContainer.style.width = imageWidth + "px";
}
}
