/*
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 insertTop2(obj) {
	// Create the two div elements needed for the top of the box
	f=createElement("div");
	f.className="pt"; // The outer1 div needs a class name
    f2=createElement("div");
    f.appendChild(f2);
	obj.insertBefore(f,obj.firstChild);
}

function insertBottom2(obj) {
	// Create the two div elements needed for the bottom of the box
	f=createElement("div");
	f.className="ob"; // The outer1 div needs a class name
    f2=createElement("div");
    f.appendChild(f2);
	obj.appendChild(f);
}

function initPB()
{
	// Find all div elements
	var divs = document.getElementsByTagName('div');
	var pbDivs = [];
	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 (/\bpbb\b/.test(divs[i].className))
			pbDivs[pbDivs.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv2, outer2, p1, p2;
	for (var i = 0; i < pbDivs.length; i++) {
	// Save the original outer1 div for later
		thediv2 = pbDivs[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'mbb' with 'mb'
		outer2 = createElement('div');
		outer2.className = thediv2.className;
		outer2.className = thediv2.className.replace('pbb', 'pb');
	// Change the original div's class name and replace it with the new div
		thediv2.className = 'p3';
		thediv2.parentNode.replaceChild(outer2, thediv2);
	// Create two new div elements and insert them into the outer1most div
		p1 = createElement('div');
		p1.className = 'p1';
		outer2.appendChild(p1);
		p2 = createElement('div');
		p2.className = 'p2';
		p1.appendChild(p2);
	// Insert the original div
		p2.appendChild(thediv2);
	// Insert the top and bottom divs
		insertTop2(outer2);
		insertBottom2(outer2);
	}
}

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