'remmah.widget'.namespace();

remmah.widget.Tabs = function(element)
{
	this.element = (typeof element == 'string') ? document.getElementById(element) : element;
	this.tabs = null;
	if (this.element)
	{
    this.setTabs()
	}
	return this;
}
remmah.widget.Tabs.testedIn = [
	'Firefox v.3.6.18'
];
var proto = remmah.widget.Tabs.prototype;
proto.toString = function()
{
	return 'remmah.widget.Tabs';
};
proto.resetTabs = function()
{
	for (var i=0; i<this.tabs.length; i++)
	{
    var tab = this.tabs[i];
		if (tab.nodeType != 3)
		{
      tab.className = ""
		}
	}
};
proto.setTabs = function()
{
  this.tabs = this.element.childNodes;
  
  var j = 1
	for (var i=0; i<this.tabs.length; i++)
	{
		var tab = this.tabs[i];
		if (tab.nodeType != 3)
		{
      if (j < 2)
      {
        tab.className = "selected"
      }
      if (tab.nodeName == 'DT')
      {
        if (tab.childNodes)
        {
          tab.childNodes[0].onclick = this.tab_onClick.bind(this);
        }
      }
      else if (tab.nodeName == 'DD') 
      {
        j++;
      }
    }
	}
};
proto.tab_onClick = function(e)
{
	this.resetTabs()
	
	if (!e) var e = window.event;
	var target = e.target || e.srcElement;
	
	target.parentNode.className = "selected"
	var page = this.getNextSibling(target.parentNode)
	if (page)
	{
    page.className = "selected"
	}
};
proto.getNextSibling = function(n)
{
  var x = n.nextSibling;
  while (x.nodeType != 1)
  {
    x = x.nextSibling;
  }
  return x;
};

