//<script>
//window.onload=initMenus;

// zalozky
function initMenus()  { 
  var d=new Date(); 
  var today = d.getDay(); 
  if (today==0) today=7; 
  test();
  show('videoMenu', 'videoContent', 0,1);
  //show('programMenu', 'program', today-1, 6); 
  //show('videoMenu', 'videoContent', 0, 2); 
  //show('watchMenu', 'watchList', 0, 1); 
  setInterval("displaytime()", 1000);
}

function setSelected(_menu, _id, _max) {

  for (var i = 0; i<=_max; i++) 
  {
    var menu = document.getElementById(_menu+i);
    if (menu) {
      menu.className='inactive';
    }
  }
  
  var menu = document.getElementById(_menu+_id);
  menu.className='active';   
}

function hideAll(_block, _max) {

  for (var i = 0; i<=_max; i++) {
		var block=document.getElementById(_block+i);
    if (block)
    {
      block.style.display='none'; 
    }
  }
}

function showContent(){

  alert(this.firstChild.toString()());
}

function test(){
  var objects = document.getElementsByTagName('UL');
  for (var i =0  ; i<= objects.length; i++) {
    if ((objects[i]!= null) && (
      objects[i].parentNode.className == "moduleMenu" || objects[i].parentNode.className == "moduleMenu moduleMenuGeneral"
      )) {
      for ( var j = 0; j<=objects[i].childNodes.length; j++) {
        _this = objects[i].childNodes[j];
        if (_this!= null){
          if ((_this.nodeName != null) && (_this.nodeName=='LI')){
           var myId = _this.id.toString();
           var str = 'Menu';
            proc_id = myId.substr(0, myId.indexOf(str));
            proc_id += "Content"+(myId.substr(proc_id.length+str.length, myId.length - (proc_id.length +str.length))); 
            if ((_this.className != null) && (_this.className =='inactive')) {
              help_obj = document.getElementById(proc_id.toString());
              if (help_obj != null){
                  help_obj.style.display = 'none';
              }
            }
          }
        }
     }
   }
  }
}
/*  var myItem = null;
  var count =0;
  for (var i = 0; i<=object.childNodes.length; i++) {
       if(object.childNodes[i].nodeName=='LI') {
                count++;
                myItem = document.getElementById(_object+"Menu"+(count-1));
                if (myItem.className=="moduleMenuInactive") {
                   myItem.className="moduleMenuActive"
                } else 
                { if (myItem.className=="moduleMenuActive") {
                  myItem.className="moduleMenuInactive"
                  }
                }
                }
   
   }  */ 



function show(_menu, _block, _id, _max) {

  var block = document.getElementById(_block+_id);
  var menu = document.getElementById(_menu+_id);

  hideAll(_block,_max);
  
  if (block) { 
    block.style.display='block';
  }
  if (menu) {  
    setSelected(_menu,_id,_max);
  }
  if (_menu == 'videoMenu') {
    preskladejMenu(_id);
  }
}

// datum a cas
var montharray=new Array ("Január","Február","Marec","Apríl","Máj","Jún","Júl","August","September","Október","November","December")

function padlength(what){
  var output=(what.toString().length==1)?"0"+what:what
  return output
}

function displaytime() {
  var clock=document.getElementById('clock').innerHTML
  var clockfields=clock.split(' ');
  var day=clockfields[0]
  var month=clockfields[1]
  for (i=0; i<montharray.length; i++) {
    if (month==montharray[i]) month=i;
  }
  var year=clockfields[2]
  var time=clockfields[3]
  var timefields=time.split(':')
  var hour=timefields[0]
  var minute=timefields[1]
  var second=timefields[2]
  
  var serverdate=new Date(year,month,day,hour,minute,second)
  serverdate.setSeconds(serverdate.getSeconds()+1)
  var datestring=serverdate.getDate()+'. '+montharray[serverdate.getMonth()]+" "+serverdate.getFullYear()
  var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds())
  document.getElementById("clock").innerHTML=datestring+" "+timestring
}

function openPage(itemHref, width, height) {

   width = width || 350;
   height = height || 520;
  var left = Math.floor((screen.width - width)/2);
  var top = Math.floor((screen.height - height)/2);

  newWindow=window.open(itemHref,'newwin','toolbar=no,width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=yes,resizable');
  if (newWindow) {
    if (parseInt(navigator.appVersion) >= 4) { newWindow.focus(); }
    return false;
  }
  return true;
}

function openPageAndRedirectParent(itemHref, parentHref, width, height) {

   width = width || 350;
   height = height || 520;
  var left = Math.floor((screen.width - width)/2);
  var top = Math.floor((screen.height - height)/2);
   newWindow=window.open(itemHref,'newwin','toolbar=no,width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=yes,resizable');
 if (newWindow) {
    parent.location = parentHref;
    if (parseInt(navigator.appVersion) >= 4) { newWindow.focus(); }
    return false;
  }
  return true;
}


function openimage(picName) {
  var winl, wint;
  
  winl = screen.width/2 - 250;
  wint = screen.height/2 - 200;

  newWindow=window.open('','newwin','statusbar=no,toolbar=no,width=500,height=500,top='+wint+',left='+winl+',scrollbars=no,resizable');

  if (newWindow) {

    newWindow.document.writeln('<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN"` "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd">');
    newWindow.document.writeln('<html xml:lang="en" lang="en" xmlns="http:\/\/www.w3.org\/1999\/xhtml">');
    newWindow.document.writeln('<head><title>TA3 - realita v súvislostiach - správy, relácie, živé vysielanie, diskusiek<\/title>');
    newWindow.document.writeln('<link rel="stylesheet" type="text\/css" href="/design/display/style_screen.css" media="screen" >');
    newWindow.document.writeln('<style type="text\/css">');
    newWindow.document.writeln('<!--');
    newWindow.document.writeln('BODY {margin:0;}');
    newWindow.document.writeln('img  {margin:0;');
    newWindow.document.writeln('      border:0;}');
    newWindow.document.writeln('-->');
    newWindow.document.writeln('<\/style>');
    newWindow.document.writeln('<script LANGUAGE="JavaScript" type="text\/javascript">');
    newWindow.document.writeln('<!-- Begin');
    newWindow.document.writeln('var isNav4, isIE4;');
    newWindow.document.writeln('if (parseInt(navigator.appVersion.charAt(0)) >= 4) {');
    newWindow.document.writeln('  isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;');
    newWindow.document.writeln('}');
    newWindow.document.writeln('function fitWindowSize() {');
    newWindow.document.writeln('width =  document.images[0].width;');
    newWindow.document.writeln('height = document.images[0].height;');
    newWindow.document.writeln('window.resizeTo(width, height);');
    newWindow.document.writeln('if (isIE4) {');
    newWindow.document.writeln('window.resizeTo(width + (width - document.documentElement.clientWidth), height + (height - document.documentElement.clientHeight));');
    newWindow.document.writeln('} else {');
    newWindow.document.writeln('window.resizeTo(width + (width - document.body.clientWidth), height + (height - document.body.clientHeight));');
    newWindow.document.writeln('}');
    newWindow.document.writeln('window.moveTo(screen.width/2 - width/2, screen.height/2 - height/2);');
    
//    newWindow.document.writeln('   } else {');
//    newWindow.document.writeln('window.innerHeight =  document.images[0].height+10;');
//    newWindow.document.writeln('window.innerWidth =  document.images[0].width+10;');
//    newWindow.document.writeln('   }');
    newWindow.document.writeln('}');
    newWindow.document.writeln('\/\/  End -->');
    newWindow.document.writeln('<\/script>');
    newWindow.document.writeln('<\/head><body onload="fitWindowSize();">');
    newWindow.document.writeln('<div style="margin: auto; text-align:center;"><a href="javascript:self.close();" title="[ Zavrieť okno ]"><img src="'+picName+'"><\/div><\/div>');
    newWindow.document.writeln('<\/body><\/html>');
    newWindow.document.close();
    if  (parseInt(navigator.appVersion)  >= 4) {
        newWindow.focus();
    }
    return false;
  }
  return  true;
}

// Jebatko s menu dynamicka zmena velikosti
function najdiPozici(nazev,tag,mnozina) {
 /* Najde vsechny tagy s className uvedenym v parametru */
  var r = [];
  obal = najdiObal(mnozina);
  var e = obal.getElementsByTagName(tag || "*");
  for ( var j = 0; j < e.length; j++)
  if ( e[j].className == nazev || !nazev)
    r.push(j);
  
  return r;
}
function najdiObal( mnozina ) {
  if ( ! mnozina ) mnozina = document;
  else mnozina = document.getElementById(mnozina);
  return mnozina
}
function vratElement( pozice, mnozina ) {
  vystup = mnozina;
  for (var j = 0; j < pozice-1; j++ ) {
    vystup = dalsi(vystup);
  }
  return vystup;
}
function dalsi( elem ) {
  do {
    elem = elem.nextSibling;
  } while ( elem && elem.nodeType != 1 );
  return elem;
}

function preskladejMenu( _id ) {
  pozice = najdiPozici('moduleMenu','div','shortMessages');

  celeMenu = vratElement(pozice,najdiObal('shortMessages')).getElementsByTagName("ul"); 
  
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
    var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
    if (ieversion=6)
      var max_sirka = document.getElementById('shortMessages').clientWidth-1;
  }
  else var max_sirka = document.getElementById('shortMessages').clientWidth;

     
  
  for (var j =0; j<celeMenu.length; j++) {
    polozky = celeMenu[j].getElementsByTagName("li");
    var sirka = 0;
    var pozice = 0;
    var zacatek_radku = 0;
    var konec_radku = 0;
    var presun_radek = false;
    
    for (var i=0; i < polozky.length; i++){
      
      var aktualni = sirka;
      var marginRight = 0;
      if (polozky[i].style.marginRight == '') marginRight=0;
      else marginRight = parseInt(polozky[i].style.marginRight);
      sirka += polozky[i].offsetWidth+marginRight;
      var suma = 0;
      if (polozky[i].id == 'videoMenu'+_id) {
        presun_radek=true;
        var presouvana_polozka = i;
      }
      if (sirka > max_sirka) {
        if ( !presun_radek || presouvana_polozka == i) {
          zacatek_radku=i;
        }
        else if( konec_radku == 0 ) {
          konec_radku = i;
          }
        var offset = max_sirka - aktualni;
        var dilek = Math.floor(offset / (i - pozice));
        var rest = offset
        for (var h = pozice; h < i; h++) {
          var korekce = 0;
          var puvodni = 0;
          var navyseni = 0;
          puvodni = polozky[h].clientWidth; 
          if ( h == (i-1) ) {
           polozky[h].style.width = puvodni + rest+'px';
           korekce = polozky[h].clientWidth - puvodni - rest;
           navyseni = puvodni + rest - korekce;
          }
          else {
           polozky[h].style.width = puvodni + dilek+'px';
           korekce = polozky[h].clientWidth - puvodni - dilek;
           navyseni = puvodni+dilek - korekce;
          }
          polozky[h].style.width = navyseni + 'px';
          suma += navyseni;
          rest -= dilek;
        }
        sirka = polozky[i].offsetWidth;
        pozice = i;
      }
    }
    if (sirka < max_sirka) {
      
      var offset = max_sirka - sirka;
      i--;
      polozky[i].style.marginRight = offset + 'px';
    }
    if ( konec_radku == 0 ) konec_radku = polozky.length;
    for (var i=zacatek_radku; i < konec_radku; i++){
      pripoj(celeMenu[j], polozky[zacatek_radku]);
    }
  }
}

function pripoj( rodic, elem ) {
  rodic.appendChild( overElem( elem ) );
}
// Odstraní jeden uzel z DOM.
function odstran( elem ) {
  if ( elem ) elem.parentNode.removeChild( elem );
}
function overElem( elem ) {
  // Pokud byl předán pouze textový řetězec, převedeme ho na textový uzel.
  return elem && elem.constructor == String ?
    document.createTextNode( elem ) : elem;
}


//</script>