var newshow    = '';
var oldshow    = '';
var acttimeout = 0;
var IE7LE      = 0;
var olderIE    = 0;
var newerIE    = 0;
var archiv     = 0;
var lock       = 0;
var animation  = 0;
var interval   = 0;
var bannersmax = 6;
var wuerfler   = new Array(bannersmax+1); 

if((document.all)&&(!self.opera))
{
   var index   = navigator.appVersion.indexOf('MSIE');
   var version = parseInt(navigator.appVersion.substring(index+5));

   if(version < 7)
   {
      olderIE = 1;
   }

   if(version > 7)
   {
      newerIE = 1;
   }
   else
   {
      IE7LE = 1;
   }
}

function changebanner()
{
   if(newshow != oldshow)
   {
      newshow.style.visibility = "visible";
      oldshow.style.visibility = "hidden";

      oldshow = newshow;      
      var img = newshow.getElementsByTagName('img');
      
      if(img)                                    // delayed load of the banner images
      {                                          // to speed up first load time
         if(img[0])
         {
            if(img[0].id != "")
            {  
               img[0].src = 'pic/'+img[0].id 
            }
         }
      }
   }

   acttimeout = 0;
}

function changedefaultbanner()
{
   animation++;

   if(animation > bannersmax) animation = 0;

   if((lock==0)&&(archiv==0))
   {
      newshow = document.getElementById('default'+wuerfler[animation]);

      if(acttimeout) window.clearTimeout(acttimeout);

      acttimeout = window.setTimeout("changebanner()",50);
   }
}

function exit()
{
   if(acttimeout) window.clearTimeout(acttimeout);
   acttimeout = 0;

   if(interval) window.clearInterval(interval);
   interval = 0;
}

function thisover(item)
{
   if(item.id)
   {
      if(acttimeout) window.clearTimeout(acttimeout);

      lock       = 1;
      newshow    = document.getElementById('d_'+item.id);
      acttimeout = window.setTimeout("changebanner()",50);
   }
}

function thisout(item)
{
   if(item.id)
   {
      if(acttimeout) window.clearTimeout(acttimeout);

      if(archiv) newshow = document.getElementById('d_archiv');
      else       newshow = document.getElementById('default'+wuerfler[animation]);

      lock       = 0;
      acttimeout = window.setTimeout("changebanner()",50);
   }
}

// only for the microsoft buggy fucked stuff
function onmouseoverIE()
{
   thisover(this);
}

function onmouseoutIE()
{
   thisout(this);
}

function archiv_focus()
{
   if(acttimeout) window.clearTimeout(acttimeout);

   archiv     = 1;
   newshow    = document.getElementById('d_archiv');
   acttimeout = window.setTimeout("changebanner()",50);
}

function archiv_blur()
{
   if(acttimeout) window.clearTimeout(acttimeout);

   archiv     = 0;
   newshow    = document.getElementById('default'+wuerfler[animation]);
   acttimeout = window.setTimeout("changebanner()",50);
}



function init()
{
   var i;
   
   wuerfler[0] = 0;

   for (i=1;i<=bannersmax;i++)
   {
      wuerfler[i] = i;
   }
   
   for (i=0;i<10;i++)
   {
      var sw1 = 1+Math.round(Math.random()*(bannersmax-1));
      var sw2 = 1+Math.round(Math.random()*(bannersmax-1));

      if(sw1 != sw2)
      {
         var temp = wuerfler[sw1];
         wuerfler[sw1] = wuerfler[sw2];
         wuerfler[sw2] = temp;
      }
      else
      {
         i--;
      }
   }
       
   oldshow    = document.getElementById('default0');
   interval   = window.setInterval("changedefaultbanner()",20000);

   var tables = document.getElementsByTagName("table");

   for(var x=0;x!=tables.length;x++)
   {
      var table = tables[x];

      if(table.className=="menu")
      {
         var tbodies = table.getElementsByTagName("tbody");

         for (var h = 0; h < tbodies.length; h++)
         {
            var tds = tbodies[h].getElementsByTagName("td");

            for (i = 0; i < tds.length; i++)
            {
               if(tds[i].className == "item")
               {
                  var obja = tds[i].firstChild;

                  if(obja)
                  {
                     if(obja.tagName=='A')
                     {
                        var pad = 139 - obja.offsetWidth;

                        if(newerIE) pad -= 4;

                        if(pad > 0)
                        {
                           obja.style.paddingRight = pad + 'px';
                        }

                        if(IE7LE) // IE7 or older ?
                        {
                           obja.onmouseover = onmouseoverIE;
                           obja.onmouseout  = onmouseoutIE;
                        }
                        else
                        {
                           obja.setAttribute('onmouseout' ,'thisout(this)');
                           obja.setAttribute('onmouseover','thisover(this)');
                        }
                     }
                  }
               }
            }
         }
      }
   }
}
