
/** 
 * schovávač políčok - up 
 */
function showHide(elementid, hideClass, type) {

  if (type !== undefined && type == 'click') {
    showHide_click(elementid, hideClass);

  } else {
    showHide_slide(elementid, hideClass);

  }
}
  
function showHide_click(elementid, hideClass) {

  // skryje vsetky objekty ktore maju triedu class="[hideClass]"
  if (hideClass != undefined && hideClass != "") {
    $("."+hideClass).slideUp("fast");
  }

  // otvori/zatvori konkretny prvok id="[elementid]"
  if ($("#"+elementid).is(":hidden")) {
    $("#"+elementid).slideDown("fast");
  } else {
    $("#"+elementid).slideUp("fast");
  }
};

function showHide_click2(elementid, hideClass) {
if (document.getElementById(elementid).style.display == 'none'){
  // skryje vsetky objekty ktore maju triedu class="[hideClass]"
  if (hideClass != undefined && hideClass != "") {
    $("."+hideClass).slideUp("fast");
  }

  // otvori/zatvori konkretny prvok id="[elementid]"
  if ($("#"+elementid).is(":hidden")) {
    $("#"+elementid).slideDown("fast");
  } else {
    $("#"+elementid).slideUp("fast");
  }
}
};

function showHide_click3(elementid, hideClass) {
if (document.getElementById(elementid).style.display == 'none'){
  // skryje vsetky objekty ktore maju triedu class="[hideClass]"
  if (hideClass != undefined && hideClass != "") {
    $("."+hideClass).slideUp("fast");
  }

  // otvori/zatvori konkretny prvok id="[elementid]"
  if ($("#"+elementid).is(":hidden")) {
    $("#"+elementid).slideDown("fast");
  } else {
    $("#"+elementid).slideUp("fast");
  }
}
};

function showHide_slide(elementid, hideClass) {

  // skryje vsetky objekty ktore maju triedu class="[hideClass]"
  if (hideClass != undefined && hideClass != "") {
    $("."+hideClass).slideUp("fast");
  }

  // otvori/zatvori konkretny prvok id="[elementid]"
  if ($("#"+elementid).is(":hidden")) {
    $("#"+elementid).slideDown("fast");
  } else {
    $("#"+elementid).slideUp("fast");
  }
};

/** 
 * schovávač políčok - blik 
 */
function showHide2(elementid){
  if (document.getElementById(elementid).style.display == 'none'){
    document.getElementById(elementid).style.display = '';
  } else {
    document.getElementById(elementid).style.display = 'none';
  }
};

/** 
 * zmena class-y pre HNTV 
 */
function shine(elementid) {
  document.getElementById("tv01").setAttribute("className", "");
  document.getElementById("tv02").setAttribute("className", "");
  document.getElementById("tv03").setAttribute("className", "");
  document.getElementById("tv04").setAttribute("className", "");
  document.getElementById("tv05").setAttribute("className", "");
  document.getElementById("tv06").setAttribute("className", "");
  document.getElementById("tv07").setAttribute("className", "");
  document.getElementById("tv08").setAttribute("className", "");
  document.getElementById(elementid).setAttribute("className", "current");
};

// tieto operacie sa inicializuju az po nacitani stranky
$(document).ready(function() {
  
  /**
   * Nazov podstranky musi byt zabaleny v <div> boxe headline spravy.
   * Kedze headline sa vykresluje suborom sablony, v ktorom nemozno menit dynamicky popisky, ako nazvy a podobne.
   * robime tak prostrednictvom JS.
   * 
   */            
  if ($("#top-udalost").length > 0) {
    var content = $("#top-udalost .lajnapodstr").html();
    var imgW = $("#top-udalost .image img").width() + 20; 
    $("#top-udalost .lajnapodstr").remove();
    $("#top-udalost #headline-tema .content").prepend('<div class="lajnapodstr" style="margin-left: '+imgW+'px;">'+content+'</div>');
    $("#top-udalost .content ul").css("padding-left", (imgW + 4) + "px");   
  }
  
  /**
   * Prida triedu .thickbox ku vsetkym odkazom na obrazky.
   * Tym zabezpeci, ze pri kliknuti na odkaz sa inicializuje objekt Thickbox.
   * Obrazok sa zobrazi v inline okne priamo na stranke a uzivatelovi sa neotvori nove okno prehliadaca.
   * 
   */              
  $(".detail-text a[href^='http://img.ihned.cz/']").addClass("thickbox").attr("rel", "gallery-plants");
  
});

/**
 * odpocet kvoli MS v hokeji 2011
 **/

//predelavka http://www.geocities.com/SiliconValley/Lakes/8620/countdown.html
function toSt(n){
  var s='';
  if(n<10){s+='0';}
  return s+n.toString();
}

function odpocet(){
  var kdy=new Date("April 29, 2011 15:15:00 GMT+1");
  var ted=new Date();
  var jedu=Math.floor((kdy.getTime()-ted.getTime())/1000);
  var den,hodin,minut,sekund;
  if(jedu<=0){
    document.getElementById('vystup_940').innerHTML='<span style="font-size: 20px; color: white;">Kompletné výsledky, rozhovory a videá na hnonline.sk/hokej</span>';
    return;
  }
  var sec=toSt(jedu%60);
  jedu=Math.floor(jedu/60);
  var min=toSt(jedu%60);
  jedu=Math.floor(jedu/60);
  var hod=toSt(jedu%24);
  jedu=Math.floor(jedu/24);
  var dnu=jedu;
  if(sec==1){sekund=' sekundu';}
  else if(sec==2||sec==3||sec==4){sekund=' sekundy';}
  else{sekund=' sekúnd';}
  if(min==1){minut=' minúta';}
  else if(min==2||min==3||min==4){minut=' minúty';}
  else{minut=' minút';}
  if(hod==1){hodin=' hodina';}
  else if(hod==2||hod==3||hod==4){hodin=' hodiny';}
  else{hodin=' hodín';}
  if(dnu==1){den=' deň';}
  else if(dnu==2||dnu==3||dnu==4){den=' dni';}
  else{den=' dní';}
  var tmp='<span style="color: white;">do začiatku:</span>  '+min+minut+' '+sec+sekund;
  document.getElementById('vystup_940').innerHTML=tmp;
  setTimeout(odpocet,500);
}

function odpocet_620() {
  document.write('');
  /*document.write('<div><a id="odpocet_620" href="http://hnonline.sk/hokej"><p style="font-size: 16px; color: white;">Kompletné výsledky, rozhovory a videá na hnonline.sk/hokej</p></a></div>');*/
  /*window.onload=odpocet;*/
}

function odpocet_940() {
  document.write('');
  /*document.write('<a id="odpocet_940" href="http://hnonline.sk/hokej"><p style="font-size: 22px; color: white;">Kompletné výsledky, rozhovory a videá na hnonline.sk/hokej</p></a>');*/
  /*window.onload=odpocet;*/
}


/**
 * PIANO media - JS pre zistovanie cookie
 **/
 
    function readCookie(name) {
      var cookieValue = "";
      var search = name + "=";
      if(document.cookie.length > 0)
      { 
        offset = document.cookie.indexOf(search);
        if (offset != -1)
        { 
          offset += search.length;
          end = document.cookie.indexOf(";", offset);
          if (end == -1) end = document.cookie.length;
          cookieValue = unescape(document.cookie.substring(offset, end))
        }
      }
      return cookieValue;
    }

/**
 * pokus na AJAX, zobrazovanie formularov na webe
 **/
 
function loadFragmentInToElement(fragment_url, element_id) {   
    var element = document.getElementById(element_id);   
    element.innerHTML = '<iframe src="http://labs.hnonline.sk/finweb_napiste/index.php" width="270" height="206" frameborder="0" scrolling="no">Your browser does not support iframes.</iframe>';   
    xmlhttp.open("GET", fragment_url);   
    xmlhttp.onreadystatechange = function() {   
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {   
            element.innerHTML = xmlhttp.responseText;   
        }   
    }   
     xmlhttp.send(null);   
 } 
 
function loadFragmentInToElement2(fragment_url, element_id) {   
    var element = document.getElementById(element_id);   
    element.innerHTML = '<iframe src="http://labs.hnonline.sk/finweb_napiste/index2.php" width="270" height="206" frameborder="0" scrolling="no">Your browser does not support iframes.</iframe>';   
    xmlhttp.open("GET", fragment_url);   
    xmlhttp.onreadystatechange = function() {   
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {   
            element.innerHTML = xmlhttp.responseText;   
        }   
    }   
     xmlhttp.send(null);   
 } 

function getCacheStamp() {
  var pupDate = new Date();
  var stamp = ''+ pupDate.getYear() 
    +''+ (pupDate.getMonth()+1)
    +''+ pupDate.getDate()
    +''+ pupDate.getHours();

  return stamp;
}
