/*** preload obrazku v menu ***/
var obrazky = new Array("uvod_hover.gif","slovnik_hover.gif","e_learning_hover.gif","o_projektu_hover.gif","partneri_hover.gif","kontakt_hover.gif");
var cesta = "http://texsite.omegadesign.cz/fileadmin/template/img/menu_horni/";
var preload = new Array();
for (var i=0; i<obrazky.length; i++) {
  preload[i] = new Image();
  preload[i].src = cesta + obrazky[i];
}
/*** funkce pro odsraneni bilych znaku z koncu retezce ***/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
/*** odsraneni pevnych mezer v prazdnych divech ***/
function odstranitNbsp() {
  var divy=document.getElementsByTagName('div');
  for (var i=0; i<divy.length; i++) {
    if (divy[i].innerHTML.trim()=="&nbsp;") divy[i].innerHTML="";
  }
}
/**
 * Vraci hodnotu vlastnosti stylu v pixelech (pripadne vraci "auto"). Pro IE.
 * Pouziti: IE_computedStyle.get(elementNode, CSS-Style);
 * Priklad: IE_computedStyle.get(el, "width"); IE_computedStyle.get(el, "margin-top");
 */
var IE_computedStyle = function () {
    var isIE = /*@cc_on!@*/0;
    var borderRegex = /thin|medium|thick/i; /* Regex for css border width keywords */
    var styleEl;
    
    /* GET POS */
    var getPos = function (which) {
        var curStyle = styleEl.currentStyle[which];
        return (/auto/i.test(curStyle)) ? "auto" : grabLength(curStyle) + "px";
    };
    
    /* GET MARGIN */
    var getMargin = function (which) {
        var curStyle = styleEl.currentStyle["margin" + which];
        return (/auto/i.test(curStyle)) ? "0px" : grabLength(curStyle) + "px";
    };
    
    /* GET BORDER WIDTH */
    var getBorderWidth = function (which) {
        var borderWidth = styleEl.currentStyle["border" + which + "Width"];
        if (styleEl.currentStyle["border" + which + "Style"] !== "none" && 
                ((/Top|Bottom/i.test(which) && styleEl.offsetHeight > styleEl.clientHeight) || 
                (/Right|Left/i.test(which) && styleEl.offsetWidth > styleEl.clientWidth))) {
            if (!borderRegex.test(borderWidth)) {
                return grabLength(borderWidth) + "px";
            } else if (borderRegex.test(borderWidth)) {
                var temp = document.createElement("DIV");
                temp.style.width = "10px";
                temp.style.border = borderWidth + " " + styleEl.currentStyle["border" + which + "Style"] + " #000000";
                styleEl.parentNode.appendChild(temp);
                borderWidth = Math.round((temp.offsetWidth-10)/2);
                styleEl.parentNode.removeChild(temp);
                return borderWidth + "px";
            }
        } else {
            return "0px";
        }
    };
    
    /* GET PADDING */
    var getPadding = function (which) {
        return grabLength(styleEl.currentStyle["padding" + which]) + "px";
    };
    
    /* GET WIDTH */
    var getWidth = function () {
        var width = styleEl.offsetWidth; /* Currently the width including padding + border */
        width -= parseInt(getPadding("Right"));
        width -= parseInt(getPadding("Left"));
        width -= parseInt(getBorderWidth("Right"));
        width -= parseInt(getBorderWidth("Left"));
        return width + "px";
    };
    
    /* GET HEIGHT */    
    var getHeight = function () {
        var height = styleEl.offsetHeight; /* Currently the height including padding + border */
        height -= parseInt(getPadding("Top"));
        height -= parseInt(getPadding("Bottom"));
        height -= parseInt(getBorderWidth("Top"));
        height -= parseInt(getBorderWidth("Bottom"));
        return height + "px";
    };
    
    /* GRAB LENGTH */
    var grabLength = function (length) {
        var temp = document.createElement("DIV");
        temp.style.width = length;
        styleEl.parentNode.appendChild(temp);
        length = Math.round(temp.offsetWidth);
        styleEl.parentNode.removeChild(temp);
        return length;
    };
    
    return {
        /* GET */
        get : function (el, styleProp) {   
            var rValue;
            styleEl = (typeof(el) === "string") ? document.getElementById(el) : el;	
            var styleProp = (typeof(styleProp) === "string") ? styleProp.toLowerCase() : "";
            styleProp = styleProp.replace(/\-/g, "");
            
            if (!isIE || !/block/i.test(styleEl.currentStyle["display"]))
                return;
            
            switch (styleProp) { /* Run through the valid css properties, return undefined if none match */
                case "top": rValue = getPos("top"); break;
                case "right": rValue = getPos("right"); break;
                case "bottom": rValue = getPos("bottom"); break;
                case "left": rValue = getPos("left"); break;
                case "margintop": rValue = getMargin("Top"); break;
                case "marginright": rValue = getMargin("Right"); break;
                case "marginbottom": rValue = getMargin("Bottom"); break;
                case "marginleft": rValue = getMargin("Left"); break;
                case "bordertopwidth": rValue = getBorderWidth("Top"); break;
                case "borderrightwidth": rValue = getBorderWidth("Right"); break;
                case "borderbottomwidth": rValue = getBorderWidth("Bottom"); break;
                case "borderleftwidth": rValue = getBorderWidth("Left"); break;
                case "paddingtop": rValue = getPadding("Top"); break;
                case "paddingright": rValue = getPadding("Right"); break;
                case "paddingbottom": rValue = getPadding("Bottom"); break;
                case "paddingleft": rValue = getPadding("Left"); break;
                case "width": rValue = getWidth(); break;
                case "height": rValue = getHeight(); break;
            }
            
            return rValue;
        }
    };
}();
/*** Vrati vypocitanou hodnotu vlastnosti elementu ***/
function ziskejVlastnost(element,vlastnost)
{
  var hodnota = 0;

	if (window.getComputedStyle) //firefox, opera...
    var hodnota = document.defaultView.getComputedStyle(element,null).getPropertyValue(vlastnost);
	else if (element.currentStyle) //ie
		//var hodnota = element.currentStyle[vlastnost];
		hodnota = IE_computedStyle.get(element,vlastnost);
	
  reg=new RegExp("((px)$)");
	if (hodnota && hodnota.search(reg)>0) return Math.round(parseFloat(hodnota));
	return false;
}
/*** udela klikaci obrazky v odkazech v levem menu (kvuli ie) ***/
function nastavitOdkazyObr() {
  if (navigator.appName != "Microsoft Internet Explorer") return;
  if (!document.getElementById("menu_leve")) return;
  var odkazy=document.getElementById("menu_leve").getElementsByTagName("a"); //odkazy v levem menu
  for (var i=0; i<odkazy.length; i++) {
    var obrazky=odkazy[i].getElementsByTagName("img"); //obrazky v odkazu
    for (var j=0; j<obrazky.length; j++) {
      obrazky[j].onclick = function() {
        var obj = this;
        do {
          if (obj.parentNode.nodeName == "A") { //hledani nadrazeneho odkazu
            window.location.href = obj.parentNode.href;
            break;
          }
          if (!obj || obj.parentNode.nodeName == "HTML") { //konec, pokud se dojde na tag html
            break;
          }
          obj = obj.parentNode;
        } while (1);
      };
    }
  }
}
/*** obarvi liche polozky leveho menu ***/
function obarvitLeveMenu() {
  var menu = document.getElementById("menu_leve");
  if (!menu) return;
  var polozky = menu.getElementsByTagName("li");
  for (var i = 0; i < polozky.length; i = i+2) polozky[i].className += (polozky[i].className.length > 0 ? " " : "") + "menu_leve_licha";
}

var horniMenuCas=2;
function nastavHorniMenu() {
  var menu = document.getElementById("menu_horni");
  if (!menu) return;
  var polozky = menu.getElementsByTagName("li");
  for (var i = 0; i < polozky.length; i++) {
    var odkaz = polozky[i].getElementsByTagName("a")[0];
    if (!odkaz) odkaz = polozky[i].getElementsByTagName("span")[0];
    var span = odkaz.getElementsByTagName("span")[0];
    var vyska = ziskejVlastnost(span,"height");
    if (!vyska) {
      horniMenuCas = horniMenuCas * 1.1;
      setTimeout("nastavHorniMenu()", horniMenuCas);
    }
    //alert(vyska);
    if (vyska > 28) span.style.bottom = "0";
    else span.style.bottom = "6px";
  }
  
  setTimeout("nastavHorniMenu()", 1000);
}
/*** cekani na nacteni html ***/
function nacteniHtml() {
  if (!document.getElementById("zapati")) {
    htmlCas=htmlCas*2;
    setTimeout("nacteniHtml()", htmlCas);
    return;
  }
  nastavitOdkazyObr();
  obarvitLeveMenu();
  nastavHorniMenu();
  odstranitNbsp();
}
htmlCas=2;
nacteniHtml();
