var SECTIONS = new Array();

window.onload=function() {pageLoad();}

function $(elementID){return document.getElementById(elementID);}
function $create(elementName){return document.createElement(elementName);}

function pageLoad() {

	var sections0 = document.getElementsByTagName("div");
	//var SECTIONS = new Array();
	for(i=0;i<sections0.length;i++) {
		section = sections0[i];
		if(section.className=="section")
			SECTIONS.push(section);
	}

	var inbody = $("inbody");
	inbody.className="xsnazzy";
	
	var header = $("header");
	
	// top corners
	var xtop = $create("b");
	xtop.className = "xtop";
	inbody.insertBefore(xtop,header);

	var b = $create("b");
	b.className = "xb1";
	xtop.appendChild(b);

	var b = $create("b");
	b.className = "xb2 color_a";
	xtop.appendChild(b);

	var b = $create("b");
	b.className = "xb3 color_a";
	xtop.appendChild(b);

	var b = $create("b");
	b.className = "xb4 color_a";
	xtop.appendChild(b);

	// bottom corners
	var xbottom = $create("b");
	xbottom.className = "xbottom";
	inbody.appendChild(xbottom);

	var b = $create("b");
	b.className = "xb4";
	xbottom.appendChild(b);

	var b = $create("b");
	b.className = "xb3";
	xbottom.appendChild(b);

	var b = $create("b");
	b.className = "xb2";
	xbottom.appendChild(b);

	var b = $create("b");
	b.className = "xb1";
	xbottom.appendChild(b);

	// content...
	var content = $("content");
	content.className = "xboxcontent";

	var menu = $create("ul");
	menu.id = "menu";
	//inbody.insertBefore(menu,content);
	header.appendChild(menu);
	
	for(i=0;i<SECTIONS.length;i++) {
		section = SECTIONS[i];
		var id = section.id;
		var item = $create("li");
		menu.appendChild(item);
		var link = $create("a");
		link.innerHTML = id.substring(0,1).toUpperCase()+id.substring(1);
		link.href = "#"+id;
		link.onclick=function() {return onClick(this);}
		item.appendChild(link);
		link.control = section;
		section.control = link;
	}
	var id = getAnchor(document.URL);
	if(id=="") id=SECTIONS[0].id
	showSection(id);

	var loading = $("loading");
	loading.style.display="none";

	var banner = $("banner");
	banner.style.height="110px";
	banner.style.ping="0em";

}
function getAnchor(url) {
	i=url.lastIndexOf("#");
	if(i!=-1) {
		return url.substring(i+1,url.length);
	}
	return "";
}
function onClick(o,e) {
	var id = o.control.id;
	showSection(id)
	//cancelBubble();
	return false;
}
function showSection(id) {
	for(i=0;i<SECTIONS.length;i++) {
		section = SECTIONS[i];
		link=section.control;
		link.className=(section.id==id)?"active":"";
		section.className=(section.id==id)?"section active":"section";
	}
}

