/*
addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

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

function insertBottom(obj) {
	// Create the two div elements needed for the bottom of the box
	d=createElement("div");
	d.className="bb"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

function insertTop2(obj) {
	// Create the two div elements needed for the top of the box
	d=createElement("div");
	d.className="bt2"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.insertBefore(d,obj.firstChild);
}

function insertBottom2(obj) {
	// Create the two div elements needed for the bottom of the box
	d=createElement("div");
	d.className="bb2"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

function insertTop3(obj) {
	// Create the two div elements needed for the top of the box
	d=createElement("div");
	d.className="bt3"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.insertBefore(d,obj.firstChild);
}
function insertBottom3(obj) {
	// Create the two div elements needed for the bottom of the box
	d=createElement("div");
	d.className="bb3"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

function initCB()
{
	// Find all div elements
	var divs = document.getElementsByTagName('div');
	var cbDivs = [];
	for (var i = 0; i < divs.length; i++) {
	// Find all div elements with cbb in their class attribute while allowing for multiple class names
		if (/\bcbb\b/.test(divs[i].className))
			cbDivs[cbDivs.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv, outer, i1, i2;
	for (var i = 0; i < cbDivs.length; i++) {
	// Save the original outer div for later
		thediv = cbDivs[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'cbb' with 'cb'
		outer = createElement('div');
		outer.className = thediv.className;
		outer.className = thediv.className.replace('cbb', 'cb');
	// Change the original div's class name and replace it with the new div
		thediv.className = 'i3';
		thediv.parentNode.replaceChild(outer, thediv);
	// Create two new div elements and insert them into the outermost div
		i1 = createElement('div');
		i1.className = 'i1';
		outer.appendChild(i1);
		i2 = createElement('div');
		i2.className = 'i2';
		i1.appendChild(i2);
	// Insert the original div
		i2.appendChild(thediv);
	// Insert the top and bottom divs
		insertTop(outer);
		insertBottom(outer);
	}
	var cbDivs2 = [];
	for (var i = 0; i < divs.length; i++) {
	// Find all div elements with cbb in their class attribute while allowing for multiple class names
		if (/\bcbb2\b/.test(divs[i].className))
			cbDivs2[cbDivs2.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv2, outer2, i12, i22;
	for (var i = 0; i < cbDivs2.length; i++) {
	// Save the original outer div for later
		thediv2 = cbDivs2[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'cbb' with 'cb'
		outer2 = createElement('div');
		outer2.className = thediv2.className;
		outer2.className = thediv2.className.replace('cbb2', 'cb2');
	// Change the original div's class name and replace it with the new div
		thediv2.className = 'i32';
		thediv2.parentNode.replaceChild(outer2, thediv2);
	// Create two new div elements and insert them into the outermost div
		i12 = createElement('div');
		i12.className = 'i12';
		outer2.appendChild(i12);
		i22 = createElement('div');
		i22.className = 'i22';
		i12.appendChild(i22);
	// Insert the original div
		i22.appendChild(thediv2);
	// Insert the top and bottom divs
		insertTop2(outer2);
		insertBottom2(outer2);
	}
	var cbDivs3 = [];
	for (var i = 0; i < divs.length; i++) {
	// Find all div elements with cbb in their class attribute while allowing for multiple class names
		if (/\bcbb3\b/.test(divs[i].className))
			cbDivs3[cbDivs3.length] = divs[i];
	}
	// Loop through the found div elements
	var thediv3, outer3, i13, i23;
	for (var i = 0; i < cbDivs3.length; i++) {
	// Save the original outer div for later
		thediv3 = cbDivs3[i];
	// 	Create a new div, give it the original div's class attribute, and replace 'cbb' with 'cb'
		outer3 = createElement('div');
		outer3.className = thediv3.className;
		outer3.className = thediv3.className.replace('cbb3', 'cb3');
	// Change the original div's class name and replace it with the new div
		thediv3.className = 'i33';
		thediv3.parentNode.replaceChild(outer3, thediv3);
	// Create two new div elements and insert them into the outermost div
		i13 = createElement('div');
		i13.className = 'i13';
		outer3.appendChild(i13);
		i23 = createElement('div');
		i23.className = 'i23';
		i13.appendChild(i23);
	// Insert the original div
		i23.appendChild(thediv3);
	// Insert the top and bottom divs
		insertTop3(outer3);
		insertBottom3(outer3);
	}
}

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