//
// Rounded Corners for content images
//

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


// Add markup to supply the rounded corner classes.
function insertCorners(img) {	
	if (!img.getAttribute("width")) return false;
	var w = img.getAttribute("width");	
	// Create container and corner divs
	var rc = document.createElement("div");
	rc.className = "rc"+" "+img.className;
	rc.style.width = w+"px";
	var corners = new Array("r1","r2","r3","r4");
	for (var i=0; i<corners.length; i++) {
	    var div = document.createElement("div");
	    div.className = corners[i];
	    rc.appendChild(div);
	}
	// Swap the image into the new container
	img.className = '';
	img.parentNode.replaceChild(rc,img);
	rc.appendChild(img);
}

// Find images with `photo` class and call the rounding function.
function prepareCorners() {
	if (!document.getElementsByTagName) return false;
	if (!document.createElement) return false;
	var elems = document.getElementById("m-content").getElementsByTagName("img");
	for (var i=0; i<elems.length; i++) {
		if (elems[i].className.indexOf("photo") != -1) {
			insertCorners(elems[i]);
		}
	}
}

addLoadEvent(prepareCorners);