onDomReady(init);

function init() { 
 
  equip.init();
  
       
};







/* DOM ready
--------------------------------------- */
function onDomReady(f){
  var a = onDomReady, b = navigator.userAgent, d = document, w = window, c = "onDomReady", e = "addEventListener", o = "opera", r = "readyState", s = "<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r," == \"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
  a[c] = (function(o){return function(){a[c] = function(){}; for(a=arguments.callee;!a.done; a.done = 1) f(o ? o() : o)}}) (a[c]);
  if(d[e])d[e]("DOMContentLoaded",a[c],false);
  if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9)) (function(){/loaded|complete/.test(d[r])?a[c]() : setTimeout(arguments.callee,1)})();
  else if(/MSIE/i.test(b))d.write(s);
};


/* obj
--------------------------------------- */
function getObj(id) {
  var obj = document.getElementById ? document.getElementById(id) : document.all[id];  
  return obj;
};


/* className
--------------------------------------- */
function cssName(obj) {
  if(!obj) return;    
     
  this.add = function () {
    obj.className += ' ' + this.name;
  };
  
  this.remove = function () {
    var pattern = new RegExp(this.name, 'i');
    if(pattern.test(obj.className)) {
      obj.className = obj.className.replace(pattern,'');
    }
  };
  
};


/* wrap
--------------------------------------- */
function wrapObj(obj,level,tagName) { 
 
  var orig = obj;  
  var content = orig.innerHTML;
  var parent = orig.parentNode;
  var prev;
  var tag = tag ? tag : 'div';
   
  for(var i=level; i>0; i--) {
    var node = document.createElement(tagName);    
    if(i == level) {
      node.innerHTML = content;
    } else {
      node.appendChild(prev);  
    }
    prev = node;
  }  
  
  var origNode = document.createElement(orig.tagName); 
  origNode.href = orig.href;
  origNode.id = orig.id;
  origNode.className = orig.className;
  origNode.appendChild(node);
  
  parent.replaceChild(origNode,orig);
  
};




/* web accesories
--------------------------------------- */
var equip = {  

  init: function () { 
    //this.nav();
    this.print(); 
    this.fprint();  
  },
  
  /* oble rohy - menu */
  nav: function () {   

    var item = getObj('menu').getElementsByTagName('ul')[0].getElementsByTagName('li');
    if(!item) return;
    
    exp = new RegExp("set");
    for(var i=0; i<item.length; i++) {
      if(exp.test(item[i].className)) {
        var link = item[i].getElementsByTagName('a')[0]; 
        link.style.padding = 0; 
        link.className = 'nop';
        
        wrapObj(link, 2, 'span'); 
          
      }     
    }

    
    
  },
  
  /* tisk - content */
  print: function () {    
    var list = getObj('ctrl');
    if(!list) return;
    
    var lastitem = list.lastChild;
    while(lastitem.nodeType != 1)
      lastitem = lastitem.previousSibling;
          
    var link = document.createElement('a');
    link.href = '#';
    link.className = 'print';
    link.innerHTML = 'vytisknout';
    link.onclick = function() {
      window.print();
      return false;
    };
    
    var spacer = document.createElement('span');
    spacer.innerHTML = ' | ';
    
    list.insertBefore(spacer, lastitem);
    list.insertBefore(link, spacer);
  },
  
  /* tisk - footer */
  fprint: function () {    
    var list = getObj('sign');
    if(!list) return;
    
    var lastitem = list.lastChild;
    while(lastitem.nodeType != 1) {
      lastitem = lastitem.previousSibling;
    } 
    lastitem.className = '';
      
    var item = document.createElement('li');
    item.className = 'nob';
    
    var link = document.createElement('a');
    link.href = '#';
    link.innerHTML = 'tisk';
    link.onclick = function () {
      window.print();
      return false;
    };
    
    item.appendChild(link);
    list.appendChild(item);
  }

};













