

window.addEvent('load', function() { 
  try{nastavTaby();}catch(e){}
  clearPage();
});

window.addEvent('load', function() { 
  
});








var topMenuTimer = null;

function topMenu(co) {  
  // pri prvnim najeti     
  if(!topMenuTimer) {
    var time = 1;
  }else {
    // a dalsich najeti
    var time = 400;
    clearTimeout(topMenuTimer);
  }
  // Pustime fci
  topMenuTimer = setTimeout(function() {topMenuDo(co)}, time);
}

function topMenuDo(co) {
  ulka = co.parentNode.getElementsByTagName('ul');
  for(i=0; i< ulka.length; i++){
    if(ulka[i].className=="sub") { ulka[i].style.visibility = 'hidden';}
  }
  licka = co.parentNode.getElementsByTagName('li');
  
  for(i=0; i< licka.length; i++){
    if(licka[i].className=="subactive") { licka[i].className="subactive"; }
    else { licka[i].className=""; } 
  }  
  co.className="active"
  
  try {
    ulka = co.getElementsByTagName('ul');
    for(i=0; i< ulka.length; i++){
      if(ulka[i].className=="sub") { ulka[i].style.visibility = 'visible';}
    } 
    
  } catch(e) {}
}

var duration = 0.3;
var fromV = 0;
var toV = 0.8;
var flashHeight = 390;
var flashWidth = 400;

var tempvideofile = null;


function StartVideo(videofile, popiska) {
  tempvideofile = videofile;
  
  var windowWidth, windowHeight, showWidth, showHeight ;
  
  windowWidth = getScrollSize().x;
  windowHeight = getScrollSize().y;
  showinWidth = getSize().x;
  showinHeight = getSize().y;   
  
  // var temp = getPageScroll();
  scrLeft = getScroll().x;
  scrTop = getScroll().y;
  
  //alert(window.innerHeight);
  var container = $('videocontainer');
  container.style.height = windowHeight+'px';
  container.style.width = windowWidth+'px';
  
  
  var player = $('videoObal');
  // vycentrovani playeru
  
  
  player.style.top = Math.ceil(scrTop + ((showinHeight - flashHeight) / 2) ) + 'px'; // ( 
  player.style.left = Math.ceil(scrLeft + ((showinWidth - flashWidth) / 2)) + 'px';
  
  // preneseme popis videa do hlavicky
  $('videoHeaderName').innerHTML = popiska;
  
  
  // vypneme FLASHE na strance
  FlashSet('hidden');
  
  
  
  // zobrazime
  // Effect.Appear('videocontainer', { duration: duration, from : fromV, to : toV});
   $('videocontainer').setStyle('opacity', fromV);
   $('videocontainer').setStyle('display', 'block');
   $('videocontainer').fade(toV);
  
  
  
  // Tady je funkce pro zavreni
  $('videoCloseButt').onclick = function() {
    this.onclick = function(){return;}
    $('videoplayer').innerHTML = '';
    $('videocontainer').fade(fromV);
    $('videocontainer').setStyle('opacity', toV);
    
    window.setTimeout('FlashSet(\'visible\');', duration * 1000)
    // window.setTimeout('FlashSet(\'visible\');', duration * 1000);
    // $('videocontainer').setStyle('display', 'none');
  }
  
  $('videocontainer').onclick = function() {
    this.onclick = function(){return;}
    $('videoplayer').innerHTML = '';
    $('videocontainer').fade(fromV);
    $('videocontainer').setStyle('opacity', toV);
    
    window.setTimeout('FlashSet(\'visible\');', duration * 1000)
    // window.setTimeout('FlashSet(\'visible\');', duration * 1000);
    // $('videocontainer').setStyle('display', 'none');
  }
  
  window.setTimeout(showVideo, duration * 1000);
}




function showVideo() {

  var so = new Swiff('/graphics/flash/NonverBlaster.swf', {
                            id : so,
                            width: 400,
                            height: 300,
                            params: {
                                wMode: 'solid',
                                bgcolor: '#000000',
                                allowFullScreen: 'true' 
                            },
                            vars: {
                                mediaURL : tempvideofile,
                                teaserURL : '/graphics/atnlogo.png',
                                controlColor : '#ffffff',
                                scaleIfFullScreen : 'true',
                                showScalingButton : 'true',
                                autoPlay : 'true'
                            } 
      });
      $('videoplayer').adopt(so);  
}

function FlashSet(to) {
  // Napred vypnem objekty a embedy
  var temps = document.getElementsByTagName('embed');
  for(var i=0;i<temps.length;i++) {
    temps[i].style.visibility = to;
  }
  var temps = document.getElementsByTagName('object');
  for(var i=0;i<temps.length;i++) {
    temps[i].style.visibility = to;
  }
}


function clearPage() {
  
  taby = $$('.tabLong .tab_inner');
  if(taby != '') {
    tablong = 80;
    var delkaTabu = Array();

    $each(taby,
      function(value, key) {
        if(value.style.display == 'none') {
          value.setStyle('display', 'block');
          delkaTabu.push(value.getSize().y);
          value.setStyle('display', 'none');
        } else {
          delkaTabu.push(value.getSize().y);
        } 
      }
    );
    
    $each(delkaTabu, function(value) { if(value > tablong) { tablong = value; }   }  );
    
    if (Browser.Engine.trident) {
      $$('.tabMain .tabLong')[0].setStyle('height', tablong+'px' );
    } else {
      $$('.tabMain .tabLong')[0].setStyle('min-height', tablong+'px' );
    }
  }
  
  lmheight = $('leftmenu').getSize().y;
  mainheight = $$('#main div.cont')[0].getSize().y;
  
  
  
  if(lmheight > mainheight ) { // kdyz je delsi levy sloupec - prodlouzime pravy
    if (Browser.Engine.trident) {
      $$('#main div.long')[0].setStyle('height', (lmheight - 135)+'px' );
    } else {
      $$('#main div.long')[0].setStyle('min-height', (lmheight - 135)+'px' );
    }
  } else { // nebo prodlouzime ten levy
    var dopDef = $('doporucene').getSize().y; 
    
    
    
    $('doporucene').setStyle('height',( dopDef + (mainheight - lmheight) + 25  )+'px' );
    $('doporucene').setStyle('overflow', 'hidden');
    
    var dopRozdil = $('doporucene').getSize().y - dopDef;
    
    if (dopRozdil > 80) {
      var docist = Math.floor(dopRozdil / 77);
      var notin = '';
      
      $each($$('#doporucene a.tipthumb'), function(value) { notin = notin+','+value.rel; } );
      if(notin.length > 1) {
        notin = notin.substr(1)
      }
      var readurl = '/dalsidoporucene/'+ docist +'/'+ notin +'/';
      
      var htmlReq = new Request(
                      { method : 'get',
                        url : readurl,
                        onSuccess : function(response) {
                          $('doporucene').set('html', $('doporucene').get('html') + response );                         
                        }
                      
                      }
                    );
      htmlReq.send();  
    } 
  } 
}




// function FlashSet(to) {
  // Napred vypnem objekty a embedy
  // $each( $$('embed') , function(co) { co.setStyle('visibility', to); }  ); // flash enable
	// $each( $$('object') , function(co) { co.setStyle('display', 'none'); }  );
// }



