/*
addEvent function found at http://www.scottandrew.com/weblog/articles/mbs-events
*/
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

/*
createElement function found at http://simon.incutio.com/archive/2003/06/15/javascriptWithXML
*/
function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

function insertTop1(obj) {
	// Create the two div elements needed for the top of the box
	e=createElement("div");
	e.className="mt"; // The outer1 div needs a class name
    e2=createElement("div");
    e.appendChild(e2);
	obj.insertBefore(e,obj.firstChild);
}

function insertBottom1(obj) {
	// Create the two div elements needed for the bottom of the box
	e=createElement("div");
	e.className="nb"; // The outer1 div needs a class name
    e2=createElement("div");
    e.appendChild(e2);
	obj.appendChild(e);
}

function initMB()
{
	// Find all div elements
	var divs = document.getElementsByTagName('div');
	var mbDivs = [];
	for (var i = 0; i < divs.length; i++) {
	// Find all div elements with mbb in their class attribute while allowing for multiple class names
		if (/\bmbb\b/.test(divs[i].className))
			mbDivs[mbDivs.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv1, outer1, m1, m2;
	for (var i = 0; i < mbDivs.length; i++) {
	// Save the original outer1 div for later
		thediv1 = mbDivs[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'mbb' with 'mb'
		outer1 = createElement('div');
		outer1.className = thediv1.className;
		outer1.className = thediv1.className.replace('mbb', 'mb');
	// Change the original div's class name and replace it with the new div
		thediv1.className = 'm3';
		thediv1.parentNode.replaceChild(outer1, thediv1);
	// Create two new div elements and insert them into the outer1most div
		m1 = createElement('div');
		m1.className = 'm1';
		outer1.appendChild(m1);
		m2 = createElement('div');
		m2.className = 'm2';
		m1.appendChild(m2);
	// Insert the original div
		m2.appendChild(thediv1);
	// Insert the top and bottom divs
		insertTop1(outer1);
		insertBottom1(outer1);
	}
}

if(document.getElementById && document.createTextNode)
{
	addEvent(window, 'load', initMB);
}