/* -------------------------------------------------------------------------------------------------------------------------

		GET ELEMENTS BY CLASS - written by Dana Woodman

------------------------------------------------------------------------------------------------------------------------- */
function getElementsByClass(className) {
	var all = document.all ? document.all : document.getElementsByTagName('*');
	var elements = new Array();
	for (var e = 0; e < all.length; e++)
		if (all[e].className == className)
			elements[elements.length] = all[e];
	return elements;
}



/* -------------------------------------------------------------------------------------------------------------------------

		ROUNDED BOX - written by Dana Woodman

------------------------------------------------------------------------------------------------------------------------- */
function roundedBox(objClass) {
	
	// Check to see if DOM methods are available
	if (!document.createElement) {return false;}
		
	// Set classes
	var boxNewClass = 'box-container'; // Class that replaces the default class for the box
	var boxBrClass = 'box-br'; // Class for the bottom right image
	var boxBlClass = 'box-bl'; // Class for the bottom left image
	var boxTrClass = 'box-tr'; // Class for the top right image
	var boxTlClass = 'box-tl'; // Class for the top left image
	var boxContClass = 'box-content'; // Class for the inner padding
	
	// Find box occurances
	var box = getElementsByClass(objClass);
	
	// Loop through all the occurances of the class
	for (var i=0; i < box.length; i++) {
		
		// Turn the box into a more pleasing variable to work with
		var theBox = box[i];
		
		var contentNodes = [];
		for(var k=-1, elm; elm = theBox.childNodes[++k];) {
        	contentNodes.push(elm);
		}
		
		// If ther is JS enabled, change the box's class to the new class
		theBox.className = boxNewClass;
		
		// Create and append new elements to the box
		var elm = document.createElement("div");
		elm.className = boxBrClass;
		theBox = theBox.appendChild(elm);
		// box-br appended
		elm = document.createElement("div");
		elm.className = boxTlClass;
		theBox = theBox.appendChild(elm);
		// box-tl appended
		elm = document.createElement("div");
		elm.className = boxTrClass;
		theBox = theBox.appendChild(elm);
		// box-tr appeneded
		elm = document.createElement("div");
		elm.className = boxContClass;
		theBox = theBox.appendChild(elm);
		// box-cont appended
		
		// Append content nodes
		for(var k=0; k < contentNodes.length; k++) {
			theBox.appendChild(contentNodes[k]);
		}	
	}
}




/* -------------------------------------------------------------------------------------------------------------------------

		Onload Event Handler - (Call all the functions on page load)

------------------------------------------------------------------------------------------------------------------------- */
window.onload = function() {
	roundedBox('box');
}