var menuMgr = {
  showMenu: function(id) 
  {
    this._mnu = document.getElementById ? document.getElementById(id) : null;
    if (!this._mnu) 
      return;
      
    this._mnuID = id;
    var aElement = document.getElementById('a-'+id); 
    this._mnu.style.left = (poziciaX(aElement) + this._xoffs) + 'px';
    this._mnu.style.top = (poziciaY(aElement) + this._yoffs) + 'px';
    this._mnu.onmouseout = menuMouseout;
    this._mnu.onmouseover = menuMouseover;
    this.doShowMenu();
  },
  hideMenu: function (e)
  {
    if(!e) var e=window.event;
    var trg = e.target ? e.target : e.srcElement;
    var te = e.relatedTarget ? e.relatedTarget : e.toElement;
    if((te == this._mnu) || (componentOf(te, this._mnu))) return;
    this._waittimer = setTimeout('menuMgr.doHideMenu()', 200);
  },
  doShowMenu: function()
  {
    if(this._timer != null) clearInterval(this._timer);
    this._mnu.style.visibility = "visible";
    document.getElementById('a-'+this._mnuID).style.backgroundPosition = "0% -35px";
    this._timer = setInterval('menuMgr.slideOpacity()', this._opInterval);
  },
  doHideMenu: function()
  {
    if(this._timer != null) clearInterval(this._timer);
    document.getElementById('a-'+this._mnuID).style.backgroundPosition = "0% 0px";
    this._timer = setInterval('menuMgr.slideOpacityDown()', this._opInterval);
  },
  slideOpacity: function()
  {
    this._op += this._opStep;
    if(this._op >= this._opMax) 
    {  
      clearInterval(this._timer);
      this._timer = null;
      this._op = this._opMax;
    }
    setOpacity(this._op, this._mnuID);
  },
  slideOpacityDown: function()
  {
    this._op -= this._opStep;
    if(this._op <= this._opMin) 
    {  
      clearInterval(this._timer);
      this._timer = null;
      this._mnu.style.visibility = "hidden";
      this._op = this._opMin;
    }
    setOpacity(this._op, this._mnuID);
      
  },
    
  _mnu: null,
  _mnuID: '',
  _timer: null,
  _waittimer: null,
  _xoffs: 10,
  _yoffs: 35,
  
  _op: 0,
  _opStep: 30,
  _opMin: 0,
  _opMax: 90,
  _opInterval: 70
}

var scrlTimer = null;

function menuMouseout(e)
{
  if(!e) var e=window.event;
  var trg = e.target ? e.target : e.srcElement;
  var te = e.relatedTarget ? e.relatedTarget : e.toElement;
  
  var aElement = document.getElementById('a-'+menuMgr._mnuID); 
  if((te == aElement) || (te == menuMgr._mnu) ||(componentOf(te, menuMgr._mnu))) return;  
  menuMgr._waittimer = setTimeout('menuMgr.doHideMenu()', 200);
}

function menuMouseover(e)
{
  if(!e) var e=window.event;
  var trg = e.target ? e.target : e.srcElement;
  var te = e.relatedTarget ? e.relatedTarget : e.fromElement;
  
  var aElement = document.getElementById('a-'+menuMgr._mnuID); 
  if((te == aElement) || (te == menuMgr._mnu) ||(componentOf(te, menuMgr._mnu))) return;
  if(menuMgr._timer != null) clearInterval(menuMgr._timer); 
  menuMgr.doShowMenu();
}

/* **************************************************************** */

function menu1aover(e)
{
  if(!e) var e=window.event;
  var tg = e.relatedTarget ? e.relatedTarget : e.srcElement;
  if(tg.tagName=="A") tg.style.backgroundColor = "#361105"; // bug in IE8? (not changed to a:hover)
}

function poziciaX(obj)
{ 
  var x = 0;
  var obj; 
  do 
  { 
    x += obj.offsetLeft; 
    obj = obj.offsetParent;
  } while (obj);
  return x;
}

function poziciaY(obj)
{ 
  var y = 0;
  var obj; 
  do 
  { 
    y += obj.offsetTop; 
    obj = obj.offsetParent;
  } while (obj);
  return y;
}

function componentOf(element, menu) 
{
  if (!element) 
    return; // in case alt-tab away while hovering (prevent error)
  while ( element = element.parentNode ) 
    if ( element == menu ) 
      return true;
  return false;
}

function setOpacity(opacity, id) 
{ 
  var object = document.getElementById(id).style; 
  object.opacity = (opacity / 100); 
  object.MozOpacity = (opacity / 100); 
  object.KhtmlOpacity = (opacity / 100); 
  object.filter = "alpha(opacity=" + opacity + ")";
}

function ukazSpravu(mm)
{
  document.getElementById('ss').innerHTML += mm+' ';
}

function highlightImage(obj)
{
  obj.style.opacity = 1;
  obj.style.filter = "alpha(opacity=100)";
}
function unhighlightImage(obj)
{
  obj.style.opacity = 0.4;
  obj.style.filter = "alpha(opacity=40)";
}
function imageIdx(fn)
{
  var i=0;
  while((ilist[i] != fn)&&(i<ilist.length)) i++;
  if(ilist[i] != fn) i=0;
  return i;
}

function clickImage(i)
{
  document.getElementById('currimage').src = ilist[i];
  curridx = i;
}

function divscroll(obj)
{
  //document.getElementById('currimgdiv').innerHTML += obj.scrollLeft+' ';
}
function scrollleft()
{
  obj = document.getElementById('scrl');
  if(obj.scrollLeft>=4) obj.scrollLeft -= 4;
  else 
  {
    obj.scrollLeft = 0;
    scrlTimer = null;
    return;
  }
  scrlTimer = setTimeout('scrollleft()', 0);
}

function scrollright()
{
  obj = document.getElementById('scrl');
  if(obj.scrollLeft<=(obj.scrollWidth-4)) obj.scrollLeft += 4;
  else 
  {
    obj.scrollLeft = obj.scrollWidth;
    scrlTimer = null;
    return;
  }
  scrlTimer = setTimeout('scrollright()', 0);
}

function stopScroll()
{
  if(scrlTimer!=null) clearTimeout(scrlTimer);
}
function nextImage()
{
  curridx++;
  if(curridx>=ilist.length) curridx=0;
  document.getElementById('currimage').src = ilist[curridx];
}