function addHandler(object, event, handler)
{
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
  {
    var handlersProp = '_handlerStack_' + event;
    var eventProp = 'on' + event;
    if (typeof object[handlersProp] == 'undefined')
    {
      object[handlersProp] = [];
      if (typeof object[eventProp] != 'undefined')
        object[handlersProp].push(object[eventProp]);
      object[eventProp] = function(e)
      {
        var ret = true;
        for (var i = 0; ret != false && i < object[handlersProp].length; i++)
          ret = object[handlersProp][i](e);
        return ret;
      }
    }
    object[handlersProp].push(handler);
  }
}

function removeHandler(object, event, handler)
{
  if (typeof object.removeEventListener != 'undefined')
    object.removeEventListener(event, handler, false);
  else if (typeof object.detachEvent != 'undefined')
    object.detachEvent('on' + event, handler);
  else
  {
    var handlersProp = '_handlerStack_' + event;
    if (typeof object[handlersProp] != 'undefined')
    {
      for (var i = 0; i < object[handlersProp].length; i++)
      {
        if (object[handlersProp][i] == handler)
        {
          object[handlersProp].splice(i, 1);
          return;
        }
      }
    }
  }
}


var oInterval = new Array();
var oIntervalo = new Array();


function menuEffectOn(id)
{
	var oCell = document.getElementById('menuCell' + id);
	var oSpan = oCell.childNodes[1].childNodes[0];
	
	var sWidth = oSpan.style.width;
	if ('' == sWidth) sWidth = '25%';
	sWidth = sWidth.replace(/%/ig, '');
	var iWidth = parseInt(sWidth);
	iWidth = iWidth + Math.exp(0.03*(100-iWidth)+0.7);
	if (iWidth >= 100) {
		iWidth = 100;
		window.clearInterval(oInterval[id]);
	}
	oSpan.style.width =  iWidth + '%';
}
function menuEffectOnV(id)
{
	var oCell = document.getElementById('menuCell' + id);
	var oSpan = oCell.childNodes[1].childNodes[0];
	
	var sHeight = oSpan.style.height;
	if ('' == sHeight) sHeight = '6px';
	sHeight = sHeight.replace(/px/ig, '');
	var sHeight = parseInt(sHeight);
	sHeight = sHeight + Math.exp(0.03*(14-sHeight)+0.4);
	if (sHeight >= 14) {
		sHeight = 14;
		window.clearInterval(oInterval[id]);
	}
	oSpan.style.height =  sHeight + 'px';
}
function menuEffectOff(id) 
{
	var oCell = document.getElementById('menuCell' + id);
	var oSpan = oCell.childNodes[1].childNodes[0];
	
	var sWidth = oSpan.style.width;
	if ('' == sWidth) sWidth = '25%';
	sWidth = sWidth.replace(/%/ig, '');
	var iWidth = parseInt(sWidth);
	iWidth = iWidth - Math.exp(0.03*(100-iWidth)+0.7);
	if (iWidth <= 25) {
		iWidth = 25;
		window.clearInterval(oIntervalo[id]);
	}
	oSpan.style.width =  iWidth + '%';
}
function menuEffectOffV(id) 
{
	var oCell = document.getElementById('menuCell' + id);
	var oSpan = oCell.childNodes[1].childNodes[0];
	
	var sHeight = oSpan.style.height;
	if ('' == sHeight) sHeight = '6px';
	sHeight = sHeight.replace(/px/ig, '');
	var sHeight = parseInt(sHeight);
	sHeight = sHeight - Math.exp(0.03*(14-sHeight)+0.4);
	if (sHeight <= 6) {
		sHeight = 6;
		window.clearInterval(oInterval[id]);
	}
	oSpan.style.height =  sHeight + 'px';
}




function handlerOver(e)
{
	var eventSrc = (e.srcElement) ? e.srcElement : e.target;
	
	//alert(eventSrc.className);
	var oCell = eventSrc.parentNode;
	
	var id = oCell.id;
	id = id.replace(/menuCell/ig, '');
	var id = parseInt(id);
	
	if (eventSrc.className != 'current')
	{
		window.clearInterval(oIntervalo[id]);
		oInterval[id] = window.setInterval('menuEffectOn(' + id + ')', 33);
	}
	else
	{
		window.clearInterval(oIntervalo[id]);
		oInterval[id] = window.setInterval('menuEffectOnV(' + id + ')', 33);
	}
}
function handlerOut(e)
{
  	var eventSrc = (e.srcElement) ? e.srcElement : e.target;
	var oCell = eventSrc.parentNode;
	
	var id = oCell.id;
	id = id.replace(/menuCell/ig, '');
	var id = parseInt(id);
	
	if (eventSrc.className != 'current')
	{
		window.clearInterval(oInterval[id]);
		oIntervalo[id] = window.setInterval('menuEffectOff(' + id + ')', 33);
	}
	else
	{
		window.clearInterval(oInterval[id]);
		oInterval[id] = window.setInterval('menuEffectOffV(' + id + ')', 33);
	}
}

onload = function setEventHandlers()
{
	var oBox = document.getElementById('topBox');
	var oLnk = oBox.getElementsByTagName('A');
	for(var i=0; i<oLnk.length; i++)
	{
		if (oLnk[i].id != 'logoLink')
		{
			addHandler(oLnk[i], 'mouseover', handlerOver);
			addHandler(oLnk[i], 'mouseout', handlerOut);
		}
	}
}
