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

function insertBottom3(obj) {
	// Create the two div elements needed for the bottom of the box
	g=createElement("div");
	g.className="tb"; // The outer1 div needs a class name
    g2=createElement("div");
    g.appendChild(g2);
	obj.appendChild(g);
}

function initFB()
{
	// Find all div elements
	var divs = document.getElementsByTagName('div');
	var fbDivs = [];
	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 (/\bfbb\b/.test(divs[i].className))
			fbDivs[fbDivs.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv3, outer3, f1, f3;
	for (var i = 0; i < fbDivs.length; i++) {
	// Save the original outer1 div for later
		thediv3 = fbDivs[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'mbb' with 'mb'
		outer3 = createElement('div');
		outer3.className = thediv3.className;
		outer3.className = thediv3.className.replace('fbb', 'fb');
	// Change the original div's class name and replace it with the new div
		thediv3.className = 'f3';
		thediv3.parentNode.replaceChild(outer3, thediv3);
	// Create two new div elements and insert them into the outer1most div
		f1 = createElement('div');
		f1.className = 'f1';
		outer3.appendChild(f1);
		f3 = createElement('div');
		f3.className = 'f3';
		f1.appendChild(f3);
	// Insert the original div
		f3.appendChild(thediv3);
	// Insert the top and bottom divs
		insertTop3(outer3);
		insertBottom3(outer3);
	}
}

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