function pageSize() {
  // vrati velikost stranky
  
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return[myWidth,myHeight];
}

function elmHeight(elm) {
    // vrati vysku elementu
    
	var height = (elm.offsetHeight) ? elm.offsetHeight : elm.style.pixelHeight;
	return height;
}

function startPage() {
    // nastavi vychozi zobrazeni stranky
    
    var leftContent = document.getElementById('leftContent');
    var rightContent = document.getElementById('rightContent');
    
    var pSize = new Array;
    pSize = pageSize();
    contentHeight = pSize[1];
    contentHeight = (elmHeight(leftContent) > contentHeight) ? elmHeight(leftContent) : contentHeight;
    contentHeight = (elmHeight(rightContent) > contentHeight) ? elmHeight(rightContent) : contentHeight;
    
    leftContent.style.height = contentHeight+"px";
}

window.onload = startPage;




/* fce pro galerii */

function nastavGalerii() {
    // prohleda linky k detailum snimku a upravi je pro zvetsovani v okne
    
    if (chytniMsie()) return true; // v pripad ze je klientem JESPR, nebudou se linky nahrazovat
    
    var vsechnyLinky = linky = new Array();
    vsechnyLinky = document.getElementsByTagName('a');
    
    for (i = 0; i < vsechnyLinky.length; i++) {
        (vsechnyLinky[i].className == 'gal_img') ? linky.push(vsechnyLinky[i]) : linky;  
    }
    
    for (i = 0; i < linky.length; i++) {
        linky[i].href = "javascript: void(0)";
        linky[i].target = "";
        linky[i].onmousedown = otevriSnimek;   
    }
    
    return true;
};

function otevriSnimek(e) {
    // otevre detail snimku
    
    var nahled, img_id;
    var pozice = new Array;
    
    e = (e) ? e : window.event;
    // e.cancelBubble = true;
    typ = e.type;
    
    // pozice kliknuti
	var posx = 0;
	var posy = 0;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
    
    if (e.target) nahled = e.target;
    else if (e.srcElement) nahled = e.srcElement;
    if (nahled.nodeType == 3) nahled = nahled.parentNode;
    if (nahled.tagName == 'IMG') nahled = nahled.parentNode;
    
    img_src = nahled.id.split('_')[1];
    
    if (img_src.length > 0) {
        
        if (document.getElementById('image_detail')) zavriMne();
        
        var image = document.createElement('img');
        image.alt = 'zavřít / close';
        image.onmousedown = zavriMne;
        var obal = document.createElement('div');
        obal.className = obal.id = 'image_detail';
        obal.style.left = (posx - 200) + 'px';
        obal.style.top = (posy - 300) + 'px';
        var btn = document.createElement('img');
        btn.src = "grafika/btn_close.gif";
        btn.width = btn.height = '13';
        btn.alt = 'zavřít / close';
        btn.className = "close_btn";
        btn.onmousedown = zavriMne;
        obal.appendChild(btn);
        var lineBrake = document.createElement('br');
        obal.appendChild(lineBrake);
        obal.appendChild(image);
        document.getElementsByTagName('body')[0].appendChild(obal);
        image.src = '_vrat_snimek.php?imgId='+img_src+'&size=500_500';
    } else {
        alert('Chyba skriptu! Obraťte se na administrátora');
    }
    
    return true;
};

function zavriMne() {
    document.getElementsByTagName('body')[0].removeChild(document.getElementById('image_detail'));
    
    return true;
}

function chytniMsie() {
    var version = navigator.appVersion;
    return ((version.indexOf('MSIE 5')>0) || (version.indexOf('MSIE 5.5')>0) || (version.indexOf('MSIE 6.0')>0)) ? true : false;
}

