window.onload = init;




function init() {
	
	arrondirBords();
	/*var content = document.getElementById('center_center');
	var elts = getElementsByClass('arrondi',content);
	alert(elts[0]);*/
}

function arrondirBords() {

  var content = document.getElementById('center_center');
  
  var imgs = getElementsByClass('arrondi', content, 'IMG');

	for (var i = 0; i < imgs.length; i++) {
	
		var img = imgs[i];
		var imageWrapper ;
		
		if(img.parentNode.nodeName == 'A'){
			img.parentNode.className = 'WrapImage';
			imageWrapper = img.parentNode ;
			
		} else {
			imageWrapper =  getSpan('WrapImage');
			imageWrapper.appendChild(img.cloneNode(false));
		}
		
		imageWrapper.style.width = img.width + "px";
		imageWrapper.style.height = img.height + "px";
		
		var topLeft = getSpan('topleft');
		imageWrapper.appendChild(topLeft);
		
		 var topRight = getSpan('topright');
		imageWrapper.appendChild(topRight);
		
		var bottomLeft = getSpan('bottomleft');
		imageWrapper.appendChild(bottomLeft);
		
		var bottomRight = getSpan('bottomright');
		imageWrapper.appendChild(bottomRight);
		
		if(img.parentNode.nodeName != 'A'){
			img.parentNode.replaceChild(imageWrapper, img);
		}
	
	}

}

function getSpan(className){
	var spanElt = document.createElement('span');
	spanElt.className = className;
	return spanElt;
}

/* Dustin Diaz's getElementsByClass */
function getElementsByClass(searchClass,node,tag) { 
        var classElements = new Array(); 
        if ( node == null ) 
                node = document; 
        if ( tag == null ) 
                tag = '*'; 
        var els = node.getElementsByTagName(tag); 
        var elsLen = els.length; 
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); 
        for (var i = 0, j = 0; i < elsLen; i++) { 
                if ( pattern.test(els[i].className) ) { 
                        classElements[j] = els[i]; 
                        j++; 
                } 
        } 
        return classElements; 
}
