var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.dropdown=function(){
 var p={fade:1,slide:1,active:0,timeout:200},

 init=function(n,o){
  for(s in o){p[s]=o[s]} p.n=n; this.build()
 };

 init.prototype.build=function(){
  var txLn,txLn1, parentLiOld;
  this.h=[]; this.c=[]; this.z=1000;
  var s=T$$('ul',T$(p.id)), l=s.length, i=0; p.speed=p.speed?p.speed*.1:.5;  // pole tagů <ul> pod elementem ID="menu"
/*
     c[] - dceřinné elementy <ul> pod nejvyšším elementem <ul ID="menu">
     h[] - jejich rodiče, tj. elementy <li>
*/
  for(i;i<l;i++){
   var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
   h.onmouseover=new Function(p.n+'.show('+i+',1)');
   h.onmouseout=new Function(p.n+'.show('+i+')');
   s[i].$$wi=0;
  }
//----------- Nastaveni sirky podle delky textu - width will be according to text length:
  var topUL=T$(p.id);
  s=T$$('li',T$(p.id));


/*    Firefox:
//  s=s[0].childNodes;
  l=s.length;
  for(i=0;i<l;i++){
//   alert(s[i].value);
   txs=s[i].childNodes[0];



   alert(typeof(txs.text)+' - '+typeof(txs.nodeValue)+' - '+typeof(txs.data));
 //  Enumerat(s[i]);     //textContent
  }
/* */

 /*
  s=s[0].childNodes;
  l=s.length;
  for(i=0;i<l;i++){
//   alert(s[i].value);
//   txs=s[i].childNodes[0];
//   alert(txs.textContent);
   Enumerat(s[0].childNodes[i]);     //textContent
  }
/* */
/*
  l=s.length;
  for(i=0;i<l;i++){
   xx=s[i].childNodes[0].childNodes[0];
   alert(xx.data+' - '+xx.length);
  }
/* */

  l=s.length;
  for(i=0;i<l;i++){
   txLn=s[i].childNodes[0].childNodes[0].length;


   if(s[i].parentNode==topUL) {   // top (upper) menu line:
    s[i].style.width=txtWiPx(txLn);
    s[i].firstChild.style.width=txtWiPx(txLn);
   } else {                       // drop-down line:
//   alert(s[i].style.width);
//   Enumerat(s[i].style);     //textContent
//    s[i].style.width=''+(txLn*7+20)+'px';
//    s[i].firstChild.style.width=''+(txLn*7+20)+'px';
//   s[i].style.background='#000';
    if(s[i].parentNode.$$wi<txLn) s[i].parentNode.$$wi=txLn;

   }
  }
  parentLiOld=topUL;  //
  for(i=0;i<l;i++){
   if(s[i].parentNode==topUL) continue;
   if(s[i].parentNode != parentLiOld) {
    parentLiOld=s[i].parentNode;
    txLn=parentLiOld.$$wi;
//    txLn1=0;
    if(parentLiOld.parentNode.parentNode.$$wi) {
     parentLiOld.style.left=txtWiPx(parentLiOld.parentNode.parentNode.$$wi);
    }
   }
   s[i].style.width=txtWiPx(txLn);              // <LI>
   s[i].firstChild.style.width=txtWiPx(txLn);   // <A> nebo <span>

  }









 };

 init.prototype.show=function(x,d){     // x: index elementu, d: 1-zobrazit děti, nic- skrýt děti
  var c=this.c[x], h=this.h[x];
  clearInterval(c.t); clearInterval(c.i); c.style.overflow='hidden';
  if(d){  // rozsvítit děti:
   if(p.active&&h.className.indexOf(p.active)==-1){h.className+=' '+p.active}
   if(p.fade||p.slide){
    c.style.display='block';
    if(!c.m){
     if(p.slide){
      c.style.visibility='hidden'; c.m=c.offsetHeight; c.style.height='0'; c.style.visibility=''
     }else{
      c.m=100; c.style.opacity=0; c.style.filter='alpha(opacity=0)'
     }
     c.v=0
    }
    if(p.slide){
     if(c.m==c.v){
      c.style.overflow='visible'
     }else{
      c.style.zIndex=this.z; this.z++; c.i=setInterval(function(){slide(c,c.m,1)},20)
     }
    }else{
     c.style.zIndex=this.z; this.z++; c.i=setInterval(function(){slide(c,c.m,1)},20)
    }
   }else{
    c.style.zIndex=this.z; c.style.display='block'
   }
  }else{   // zhasnout děti:
   c.t=setTimeout(function(){hide(c,p.fade||p.slide?1:0,h,p.active)},p.timeout)
  }
 };



 function hide(c,t,h,s){
  if(s){h.className=h.className.replace(s,'')}
  if(t){c.i=setInterval(function(){slide(c,0,-1)},20)}else{c.style.display='none'}
 }



 function slide(c,t,d){
  if(c.v==t){
   clearInterval(c.i); c.i=0;
   if(d==1){
    if(p.fade){c.style.filter=''; c.style.opacity=1}
    c.style.overflow='visible'
   }
  }else{
   c.v=(t-Math.floor(Math.abs(t-c.v)*p.speed)*d);
   if(p.slide){c.style.height=c.v+'px'}
   if(p.fade){var o=c.v/c.m; c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')'}
  }
 }
 return{init:init}
}();


function txtWiPx(txtLen) {
 return ''+(txtLen*8+18)+'px';
}


function Enumerat(co) {  // jen pro DIAGNOSTIKU, vyhodit
  var tx
  var doc=co
//  doc=document.body.all.MapaTop
     tx=""
   for (var i in doc) {
//     if (doc[i]==null) {}// {tx=tx+"???"}
//     if (i.substr(0,6)=="xxborder") {}// {tx=tx+"???"}
     if (typeof(doc[i])=="function") {}// {tx=tx+"???"}
      else {
       if(doc[i]) { tx=tx+i+'('+typeof (doc[i])+') -> '
//       tx=tx+doc[i]+String.fromCharCode(13)
       tx=tx+doc[i]+';    '; }
     }
     if (tx.length<500) {}//{tx=tx+String.fromCharCode(13)}
     else {
     alert (tx)
     tx=""
     }
   }
alert (tx)
alert ('HOTOVO')
}

