/*======================================================================*\
|| #################################################################### ||
|| # TWSD.pl Portal v. 1.0                                            # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2006 Wojciech Żyliński. All Rights Reserved.     # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| #                        http://www.twsd.pl                        # ||
|| #################################################################### ||
\*======================================================================*/

function TWSD_Engine()
{
  this.tabprefix = 'tab';
  this.currenttab = 1;
  this.tabinterval = 10000;
  this.tabscount = 3;

  this.play = function()
  {
    this.switchtab(((this.currenttab == this.tabscount) ? 1 : this.currenttab + 1));

    this.tabprojector = window.setTimeout('twsd.play()', this.tabinterval);
  }

  this.switchtab = function(id)
  {
    this.currenttab = parseInt(id, 10);

    for (i = 1; i <= this.tabscount; i++)
    {
      fetch_object(this.tabprefix + i).className = (this.currenttab == i) ? 'tabselected' : '';
      fetch_object('panel' + i).style.display = (this.currenttab == i) ? 'block' : 'none';
    }
  }

  this.pause = function()
  {
    window.clearTimeout(this.tabprojector);
  }

  this.setmenu = function()
  {
    var sfEls = fetch_tags(fetch_object('nav'), 'li');

    for (var i in sfEls)
    {
      sfEls[i].onmouseover = function()
      {
        this.className = "sfhover";
      }

      sfEls[i].onmouseout = function()
      {
        this.className = '';
      }
    }
  }

  this.log_out = function(phrase)
  {
    ht = fetch_tags(document, 'html');
    ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
    if (confirm(phrase))
    {
      return true;
    }
    else
    {
      ht[0].style.filter = "";
      return false;
    }
  }

  this.init = function(prefix)
  {
    if (fetch_object('tabcontainer'))
    {
      var container = fetch_object('tabcontainer');

      var tabs = fetch_tags(fetch_object('tabs'), 'li');

      for (var i in tabs)
      {
        tabs[i].onclick = function()
        {
          twsd.switchtab(this.id.substr(3));
        }
      }

      container.onmouseover = function()
      {
        twsd.pause();
      }

      container.onmouseout = function()
      {
        twsd.tabprojector = window.setTimeout('twsd.play()', 3000);
      }

      this.play();
    }
    
    if (is_ie)
    {
      this.setmenu();
    }
  }
}

var twsd = new TWSD_Engine();

window.onload = function()
{
  twsd.init('tab');
}

