//fading menu script

var fadeRate = 0.125,isIE=/MSIE\s\d/.test(navigator.userAgent);
var lastItem,lastSpiel,lastIcon;

// Modified Part of X, a Cross-Browser.com Javascript Library, Distributed under the terms of the GNU LGPL
function xOpacity(e, o)
{
  var set = xDef(o);
  //mod for ideal values
  if(set)
  {
   o='00'+Math.round(o*100);
   o=o.substring(o.length-3);
   o=o.charAt(0)+'.'+o.substring(1);
  }
  if(!(e=xGetElementById(e))) return 2; // error
  if (xStr(e.style.opacity)) { // CSS3
    if (set) e.style.opacity = o + '';
    else o = parseFloat(e.style.opacity);
  }
  else if (xStr(e.style.filter)) { // IE5.5+
    if (set) e.style.filter = 'alpha(opacity='+o.replace(/\./,'').replace(/^0+/,'')+ ')';
    else if (e.filters && e.filters.alpha) { o = e.filters.alpha.opacity / 100; }
  }
  else if (xStr(e.style.MozOpacity)) { // Gecko before CSS3 support
    if (set) e.style.MozOpacity = o + '';
    else o = parseFloat(e.style.MozOpacity);
  }
  else if (xStr(e.style.KhtmlOpacity)) { // Konquerer and Safari
    if (set) e.style.KhtmlOpacity = o + '';
    else o = parseFloat(e.style.KhtmlOpacity);
  }
  return isNaN(o) ? 2 : o; // if NaN, should this return an error instead of 1?
}

function xGetElementById(e)
{
  if(xStr(e)) {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  else e=null;
  return e;
}

function xDef(arg)
{
  return (typeof(arg)!='undefined');
}

function xStr(arg)
{
  return (typeof(arg)=='string');
}

function fadeOut(id)
{
  var o = xOpacity(id);
  var e = xGetElementById(id);
  chkTimer(e.fadeTmr);
  if (o - fadeRate > 0) {
    e.fadeTmr = setTimeout("fadeOut('" + id + "')", 50);
    xOpacity(id, o - fadeRate);
  }
  else {
    xOpacity(id, 0);
    e.style.display = 'none';
    e.fadeTmr = null;
  }
}

function fadeIn(id)
{
  var o = xOpacity(id);
  var e = xGetElementById(id);
  chkTimer(e.fadeTmr);
  if(!e.style.display || e.style.display=='none')
  {
   o=0;
   xOpacity(id,0);
   e.style.display='block';
  }
  if (o + fadeRate < 1) {
    xOpacity(id, o + fadeRate);
    e.fadeTmr = setTimeout("fadeIn('" + id + "')", 50);
  }
  else {
    xOpacity(id, 1);
    e.fadeTmr = null;
  }
}

function chkTimer(timer)
{
  if(timer){
   clearTimeout(timer);
   //timer=null;
  }
}


//other functions

function highlIcon(imgObj)
{
 var i='_idle',temp=imgObj.src;
 if(temp.indexOf(i)>0)
 {
  imgObj.src=temp.replace(i,'');
  if(lastIcon)
  {
   temp=lastIcon.src
   lastIcon.src=temp.substring(0,temp.lastIndexOf('.'))+i+temp.substring(temp.lastIndexOf('.'));
  };
  lastIcon=imgObj;
 };
};

function spiel(id)
{
 var sp;
 if(sp=xGetElementById(lastSpiel))
  sp.style.display='';
 if(sp=xGetElementById(id))
 {
  sp.style.display='block';
  lastSpiel=id;
 };
};

function gallItem(itemId)
{
 var elem;
 if(elem=xGetElementById(lastItem))
  elem.style.display='';
 if(elem=xGetElementById(itemId))
 {
  elem.style.display='block';
  lastItem=itemId;
  if(isIE)//ie bug (:P)
  {
   elem=elem.firstChild;
   if(elem.tagName!='IMG')
    elem=elem.firstChild;
   elem.style.display='block';
  };
 };
};

ie6Fix = function()//fake css :hover
{
 //add other element id's to elems array and use css class 'over' for fake css :hover
 elems=["contact"];
 for(i=0;i<elems.length;i++)
 {
  elems[i]=document.getElementById(elems[i]);
  if(elems[i]!=null)
  {
   elems[i].onmouseover=function()
   {
    this.className+=' over';
   };
   elems[i].onmouseout=function()
   {
    this.className=this.className.replace('over','');
   };
  };
 };
};
if(window.attachEvent && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5))<7){window.attachEvent("onload", ie6Fix)};
