function MCTabs() {
	this.settings = new Array();
};

MCTabs.prototype.init = function(settings) {
	this.settings = settings;
};

MCTabs.prototype.getParam = function(name, default_value) {
	var value = null;

	value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
	
	if (value == "true" || value == "false")
		return (value == "true");

	return value;
};

MCTabs.prototype.displayTab = function(panel_id) {
    var tab_id = panel_id + 'Tab';
	var panelElm = document.getElementById(panel_id);
	var panelContainerElm = panelElm ? panelElm.parentNode : null;
	var tabElm = document.getElementById(tab_id);
	var tabContainerElm = tabElm ? tabElm.parentNode : null;
	var selectionClass = this.getParam('selection_class', 'current');

	if (tabElm && tabContainerElm) {
		var nodes = tabContainerElm.childNodes;

		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeName == "LI")
				nodes[i].className = '';
		}

		tabElm.className = 'current';
	}

	if (panelElm && panelContainerElm) {
		var nodes = panelContainerElm.childNodes;

		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeName == "DIV")
				nodes[i].className = 'panel';
		}

		panelElm.className = 'current';
	}
	
	this.onSelected(panel_id);
};

MCTabs.prototype.getAnchor = function() {
	var pos, url = document.location.href;

	if ((pos = url.lastIndexOf('#')) != -1)
		return url.substring(pos + 1);

	return "";
};

MCTabs.prototype.writeTab = function(text, panelId, isCurrent, style) {
    document.writeln('<li id="' + panelId + 'Tab" ' + (isCurrent ? 'class="current" ' : '') + '><a onmousedown="tabs.displayTab(\'' + panelId + '\'); return false;" class="' + style + '">' + text + '</a></li>');
}

MCTabs.prototype.hover = function() {
    var sfEls = document.getElementsByTagName("a");
	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover=function() { this.className+=" hover"; }
		sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" hover"), ""); }
	}
}

MCTabs.prototype.onSelected = function() {
}


// Global instance
var tabs = new MCTabs();
