window.onload = function() {
  if (document.getElementById('home-page')) {
    for (var i=2; i<16; i++) {
      var promenna = new Array();
      promenna[i] = new Image();
      promenna[i].src = "images/bg" + i + ".jpg";
    }
  }
  if (document.getElementById('content')) {
    var elm = document.getElementById('content');
    add_show_foto(elm);
    add_target(elm);
  }
  if (document.getElementById('content-3sl')) {
    var elm = document.getElementById('content-3sl');
    add_show_foto(elm);
    add_target(elm);
  }
  if (document.getElementById('content-max')) {
    var elm = document.getElementById('content-max');
    add_show_foto(elm);
  }
  if (document.getElementById('content-a4')) {
    var elm = document.getElementById('content-a4');
    add_show_foto(elm);
  }
  if (document.getElementById('content-songbook')) {
    var elm = document.getElementById('content-songbook');
    add_show_foto(elm);
  }
  if (document.getElementById('noty')) {
    var elm = document.getElementById('noty');
    var anchor = elm.getElementsByTagName("a");
    anchor[0].target = "_blank";
  }
  if (document.getElementById('player')) {
    open_video();
  }
}

function add_target(elm) {
  var anchors = elm.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    if (anchors[i].className == "external") {
      anchors[i].target = "_blank";
    }
    if (anchors[i].className == "fotoshow") {
      anchors[i].target = "_blank";
      anchors[i].setAttribute("rel", "lytebox[foto_page]");
    }
  }
}

function add_show_foto(elm) {
  var anchors = elm.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var odkaz = anchors[i].getElementsByTagName("img");
    if (odkaz[0] && anchors[i].className == "odkaz") {
      //alert(anchors[i].className);
      odkaz[0].name = "o-"+i;
    }
    else if (odkaz[0]) {
      odkaz[0].name = "o-"+i;
      anchors[i].target = "_blank";
    }
  }
  var images = elm.getElementsByTagName("img");
  for (var i=0; i<images.length; i++) {
    var image = images[i];
    if (!image.name) {
      image.onclick = function() {
        img = this.getAttribute("src");
        var win = window.open(img,"nahledimage","width=800,height=600,left=0,top=0,scrollbars");
        win.focus();
        return false;
      }
      image.style.cursor = 'pointer';
    }
  }
}

function add_show_foto2(elm) {
  var anchors = elm.getElementsByTagName("img");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    anchor.onclick = function() {
      img = this.getAttribute("src");
      var win = window.open(img,"nahledimage","width=800,height=600,left=0,top=0,scrollbars");
      win.focus();
      return false;
    }
    anchor.style.cursor = 'pointer';
  }
}

function open_video() {
  so.addParam("allowscriptaccess","samedomain");
  so.addParam("allowfullscreen","true");
  if (so_elm.substring(so_elm.length-3) == "flv") {
    so.addParam("flashvars","file="+so_elm+"&backcolor=000000&frontcolor=AAAAAA&lightcolor=CCCCCC&screencolor=FDEEC3&controlbar=over&autostart=true&stretching=none");
    so.write("player");
  }
  if (so_elm.substring(so_elm.length-3) == "swf") {
    so.addParam("flashvars","file="+so_elm+"&screencolor=FDEEC3&controlbar=none&autostart=true&stretching=none");
    so.write("player");
  }
}

