var tabstim;
var tabscont;
var tabswidth;
var tabscontw;
var tabpos  = 0;
var tabstep = 8;

function getValue(s)
{
  if (s=="") return 0;
  return parseInt(s);
}

function storetabpos()
{
  var exp = new Date();
  FixCookieDate(exp); // Correct for Mac date bug - call only once for given Date object!
  exp.setTime(exp.getTime()+(24*60*60*1000)); // 24 hrs from now
  SetCookie('tabpos'+tabsid,tabpos,exp);
}

function retrievetabpos()
{
  c = GetCookie('tabpos'+tabsid);
  if (c==null) return;
  tabpos = parseInt(c);
}

function tabsprev()
{
  tabpos = getValue(tabscont.style.left);
  tabsstep(tabstep);
}

function tabsnext()
{
  tabpos = getValue(tabscont.style.left);
  tabsstep(-tabstep);
}

function tabsstop()
{
  clearTimeout(tabstim);
  storetabpos();
}

function tabsstep(d)
{
  clearTimeout(tabstim);
  tabpos = tabpos+d;
  if (tabpos>0) tabpos = 0;
  if (tabpos+tabscontw<tabswidth) tabpos = tabswidth-tabscontw;
  tabscont.style.left = tabpos+"px";
  tabstim = setTimeout(function() {tabsstep(d); },50);
}

function tabsinit()
{
  retrievetabpos();
  tabsl = document.getElementById("tabsbsel");
  tabs  = tabsl.offsetWidth+
          document.getElementById("tabsisel").offsetWidth+
          document.getElementById("tabsasel").offsetWidth;
  tabp  = tabsl.parentNode.offsetLeft;
//document.getElementById("tabsselpos").offsetWidth;

  if (tabs==null) return;

  tabscont  = document.getElementById("tabscontent");
  tabswidth = document.getElementById("tabscontainer").offsetWidth;
  tabscontw = tabscont.offsetWidth;

  while (tabpos+tabp<0) tabpos++;
  while (tabpos+tabp+tabs>tabswidth) tabpos--;

  tabscont.style.left = tabpos+"px";
  tabscont.style.visibility = 'visible';
  storetabpos();
}

addonload(tabsinit);
