/*
  Author: Techocraft, Uroš Renko
  Dependencies: Prototype library 1.6+
*/

var TcTabControl = Class.create(
{
  tabs: "undefined",
  content: "undefined",
  
	initialize: function()
  {
  },

  create: function()
  {
  },

	destroy: function()
  {
  },

  change: function(index)
  {
    $A(this.tabs[0].childNodes).each(
      function(item)
      {
        var i;
        if (item.tagName!='LI')
        {
          return;
        }
        var i = Element.readAttribute(item, 'index');
        if (i==index)
        {
          Element.addClassName(item, 'selected');
        } else
        {
          Element.removeClassName(item, 'selected'); 
        }
      }
    );
    $A(this.content[0].childNodes).each(
      function(item)
      {
        var i;
        if (item.tagName!='LI')
        {
          return;
        }
        var i = Element.readAttribute(item, 'index');
        if (i==index)
        {
          item.show();
        } else
        {
          item.hide();
        }
      }
    );
  }

});

function TcTabControlInit()
{ 
  objTcTabControl = new TcTabControl();
  objTcTabControl.content = $$('ul.tab-content');
  objTcTabControl.tabs = $$('ul.tab-caption').each(
    function(tab)
    {
      tab.observe(
        'click',
        function(event)
        {
          var sender = Event.findElement(event, 'ul.tab-caption li');
          var index = Element.readAttribute(sender, 'index');
          this.change(index);
          Event.stop(event);
        }.bindAsEventListener(objTcTabControl));
    });
}

Event.observe(window, 'load', TcTabControlInit, false);


