function ucfirst(word){
	fstLetter = word.substr(0,1);
	rest = word.substr(1, word.length);
	fstLetter = fstLetter.toUpperCase();
	return fstLetter + rest;
}

document.getElementsByIdMatch = function(regex, tagname){
	var elems = document.getElementsByTagName(tagname)
	var matches = new Array();
	for(i=0; i<elems.length; i++){
		if(elems[i].id.search(regex) != -1) matches.push(elems[i]);
	}
	return matches;
}

function hide_all(){
	var divs = document.getElementsByTagName('div');
	
	var matches = document.getElementsByIdMatch(/^this.namespace/, 'div');
	for(i=0; i<matches.length; i++)
		matches[i].style.display = "none";
}

function show_elem(id){
	document.getElementById(id).style.display = "block";
}

function hide_elem(id){
	document.getElementById(id).style.display = "none";
}


/* MainInfo Class */
var MainInfo = function(namespace,defaultTab){
	
	this.namespace = namespace;
	this.init = function(){
		hide_all();
		this.hideTabs();
		if(defaultTab.length > 0 )
			this.raiseTab(defaultTab);
	}

	this.hideTabs = function(){
		// Get all elements whose IDs extend the this.namespace namespace.
		regex = new RegExp("^" + this.namespace + "[^$]+");
		matches = document.getElementsByIdMatch(regex, 'div');
		for(i in matches) matches[i].style.display = "none";		
		regex = new RegExp("^" + this.namespace + "Tab[a-zA-Z0-9]+$");
		matches = document.getElementsByIdMatch(regex, 'li');
		for(i in matches) matches[i].className = "";		
	}

	this.dehoverTabs = function(){
		regex = new RegExp("^" + this.namespace + "Tab[a-zA-Z0-9]+$");
		matches = document.getElementsByIdMatch(regex, 'li');
		for(i in matches)
			if(matches[i].className == "over")
				matches[i].className = "";		
	}
	
	this.showTab = function(tabname) {
		show_elem(this.namespace + ucfirst(tabname));
	}

	this.raiseTab = function(tabname){
		this.hideTabs();
		
		var e = document.getElementById(this.namespace + "Tab" + tabname);
		if(e) {
			e.className = "active";
		}
		
		this.showTab(tabname);
	}

	this.hover = function(tabname){
		tab = document.getElementById(this.namespace + "Tab" + tabname);
		this.dehoverTabs();
		if(tab.className != "active") tab.className = "over";
	}

	this.restoreBg = function(tabname){
		tab = document.getElementById(this.namespace + "Tab" + tabname);
		this.dehoverTabs();
	}
}