function getObj( eid ) {
  if ( document.getElementById )
    return document.getElementById(eid);
  else if ( document.all )
    return document.all[eid];
  else if ( document.layers )
    return document.layers[eid];
  else return null;
}

var quote = new Array( 
/* Jerry Maguire */
'The key to this business is personal relationships',
'It\'s not "show friends." It\'s show business',
'Look at me Laurel, I\'m the oldest 26 year old in the world',
'Yeah, that\'s it brother but you got to yell that shit!',
'Show me the money!',
'You are Jerry Ma-fucken-guire!',
/* he died with a felafel in his hands */
'Do you ever wonder if its all a big con Flip?',
/* Almost famous */
'It\'s all happening!',
'"The chicks are great"? I sound like a dick!',
'Of course I\'m home. I\'m always home. I\'m uncool.',
'Rock stars have kidnapped my son!',
'"That groupie"? She was a Band-Aid!',
'Please don\'t give him any more acid.',
'Wanna see me feed a mouse to my snake?',
'My last words were.. I\'m on drugs!',
'On my better days, I am Russell from Stillwater',
/* High fidelity */
'Let\'em riot. We\'re Sonic-fuckin\'-Death Monkey',
'What if I was doing something that can\'t be cancelled?',
'What\'s the name of your label? -- Top Five Records'
);

var color       = 0;
var identifier  = 0;
var verso       = 1;
var header      = 0;

function sfuma() {
  if(verso > 0) {
    if(color <= 0xffffff - 0x030303) {
      color += 0x030303;
      header.style.color = '#' + ((color < 0x100000) ? 
        ('0' + color.toString(16)):(color.toString(16)));
    } else {
      verso = -1;
    }
  }
  else {
    if(color > 0x030303) {
      color -= 0x030303;
      header.style.color = '#' + ((color < 0x100000) ? 
        ('0' + color.toString(16)):(color.toString(16)));
    }
    else {
      color = 0;
      verso = 1;
      clearInterval(identifier);
      stampaCitazione();
    }
  }
}

function stampaCitazione() {
  var rnd = Math.floor(Math.random()* quote.length);
  header.style.color = color;
  if(header.firstChild)
    header.removeChild(header.firstChild);
  var app = document.createTextNode(quote[rnd]);
  header.appendChild(app);
  identifier = setInterval('sfuma()', 50);
}

var Menu = {

  ShowUl : function(ul, index) {
    return function() {
      for(var idx = 0; idx < ul.length; idx++)
        ul[idx].style.display = 'none';
      ul[index].style.display = 'block';
    };
  },
      
  Initialize : function() {
    getObj('Xmenu').id = 'menu';
  
    a       = getObj('menu').getElementsByTagName('a');
    ul      = getObj('menu').getElementsByTagName('ul');
    
    for ( var i = 0; i < ul.length; i++ )
      ul[i].className = 'inner';
        
    page    = window.location.href;
    
    if ( (mark = page.indexOf('?')) != -1 )
      page = page.substr(0, mark);
      
    if ( (mark = page.indexOf('#')) != -1 )
      page = page.substr(0, mark);
    
    var qs = window.location.search.substr(1).split('&');
    
    for(i in qs) {
      if((/f=.+/).test(qs[i])) {
        page += '?' + qs[i]; 
        break;
      }
    }
    
    /* supermessy.. have to fix this */
    for(i in qs) {
      if((/^gb=.+/).test(qs[i]) || (/^email=.+/).test(qs[i])) {
        page += '&' + qs[i]; 
        break;
      }
    }
    
    var index = 0;
    var menuok = false;
    
    page = unescape(page);
    
    for ( var i = 0; i < a.length; i++ ) {
      if( a[i].className == 'main' ) {
        initMenu = a[i].onmouseover = Menu.ShowUl(ul, index++);
      }
      else if ( a[i] == page ) {
        a[i].style.fontWeight = 'bold';
        initMenu();
        menuok = true;
      }
    }
    if(!menuok) Menu.ShowUl(ul, 0)();
  }
}

var Tabs = {
  
  Show : function(tabs, index, li) {
    return function() {
      for(var idx = 0; idx < tabs.length; idx++) {
        li[idx].id = idx;
        tabs[idx].style.display = 'none';
      }
      li[index].id = 'current';
      tabs[index].className = 'avanti';
      tabs[index].style.display = 'block';
      return false;
    };
  },

  Initialize : function() {
  
    if (!getObj('tab') || !(a  = getObj('tab').getElementsByTagName('a')) )
      return;
  
    var div = document.getElementsByTagName('div');
  
    var tabs = new Array();

    var a = getObj('tab').getElementsByTagName('a');
    for(var c = 0; c < a.length; c++)
      a[c].onfocus = function() { if(this.blur) this.blur(); };

    var li = getObj('tab').getElementsByTagName('li');
      
    for(var i = 0; i < div.length; i++) 
      if ((/tab[0-9]+/).test(div[i].id))
        tabs.push(div[i]);
        
    for(var i = 0; i < tabs.length; i++) {
      tabs[i].style.display = 'none';
      a[i].onclick = Tabs.Show(tabs, i, li);
    }
    li[0].id = 'current';
    tabs[0].className = 'avanti';
    tabs[0].style.display = 'block';
  }

};

window.onload = function()
{
  var lnks = document.getElementsByTagName('a');
  for(var i=0; i < lnks.length; i++ ) {
    if(lnks[i].className == "ext")
      lnks[i].target = '_blank';
  }
  
  Menu.Initialize();
  Tabs.Initialize();
  
  if(getObj('news'))
    GetXmlNews();
  
  if(document.lastModified)
    window.status = 'Gunzip\'s homepage, last modified on ' + document.lastModified;
  
  if(header = getObj('head')) {
    header = header.appendChild(document.createElement('p'));
    stampaCitazione();
  }  
  document.cookie = 'screenwidth=' + screen.width;
}
