// relativni pozice submenu
var sm_pos = new Array(1, 50, 134, 205, 271, 340, 420, 0);
var opt_width = 900;

var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

// spocteme optimalni sirku main
function calc_main() {
  if (screen.width<opt_width) {
    opt_width = 780;
    }
  x = document.getElementById('main');
  if (x) {
    x.style.width = opt_width+"px";
    }
  }
function menu_on(mid) {
  x = document.getElementById(mid);
  x.style.display = 'block';
  }

var act_sub_menu;
function menu_toggle(mid, event) {
  x = document.getElementById(mid);
  if (act_sub_menu!=x) {
    hide_active();
    }
  if (x.style.display=='block') {
    x.style.display = 'none';
    } else {
    x.style.display = 'block';
    act_sub_menu = x;
    SkryjSelektitka()
    }
  event.cancelBubble = true;
  return false;
  }
function hide_active() {
  if (act_sub_menu) {
    act_sub_menu.style.display = 'none';
    }
  OdkryjSelektitka()  
  }
function repos_menu_ie() {
  x = document.getElementById('main');
  left_plus = x.offsetLeft;
  for (i=0; i<sm_pos.length; i++) {
    x = document.getElementById('sm'+(i+1));
    if (x) {
      x.style.left = (left_plus+sm_pos[i])+'px';
      }
    }
  }                   
function repos_menu_moz() {
  x = document.getElementById('main');
  w_main = x.style.width.replace('px', '');
  left_plus = (x.offsetWidth - w_main)/2;  
  for (i=0; i<sm_pos.length; i++) {
    x = document.getElementById('sm'+(i+1));
    if (x) {
      x.style.left = (left_plus+sm_pos[i])+'px';
      }
    }
  }
function repos_menu() {
  if (is_ie) {
    repos_menu_ie()
    } else {
    repos_menu_moz() 
    } 
  }
function body_click() {
  hide_active();
  }
function body_resize() {
  //repos_menu();
  //stretch_pool();
  }
function body_load() {
  //repos_menu();
  //stretch_pool();
  }

var pool_plus = 87;
function stretch_pool() {
  x = document.getElementById('pool');
  hpool = x.offsetHeight;  
  hbody = document.body.offsetHeight;
  if (hpool+pool_plus<hbody) {
    x.style.height = (hbody-pool_plus); 
    }  
  }   

function open_win(url, winWidth, winHeight, winRes) {
  if (winRes==1) { stat="resizable=1,scrollbars=1"; }
            else { stat="resizable=0,scrollbars=0"; };
  // calculate centered window position
  winLeft = Math.round((screen.width-winWidth)/2);
  winTop  = Math.round((screen.availHeight-winHeight)/2);
  winDef = "left="+winLeft+",top="+winTop+",height="+winHeight+",width="+winWidth+",directories=no,location=no,menubar=no,status=no,toolbar=no,"+stat;
  window.open(url, "", winDef);
  return true;
  }

function SkryjSelektitka() {
  var S = "";
  for (i=0; i<document.forms.length; i++) {
    for (j=0; j<document.forms[i].elements.length; j++) {
      X = document.forms[i].elements[j];
      if (X.type.indexOf("select")!=-1) {
        X.style.visibility = "hidden";
        }
      }
    }
  }

function OdkryjSelektitka() {
  var S = "";
  for (i=0; i<document.forms.length; i++) {
    for (j=0; j<document.forms[i].elements.length; j++) {
      X = document.forms[i].elements[j];
      if (X.type.indexOf("select")!=-1) {
        X.style.visibility = "visible";
        }
      }
    }
  }

var poc = 0;
var iwinTitle = "Trabant.cz";

function show_image(imgName, imWidth, imHeight) { 
  if (poc!==0) { iwin.close(); }; 
  
  url = imgName;
  resStr = "resizable=0,scrollbars=0";
                                                         
  // define window oversize
  winPlusWidth = 0;
  winPlusHeight = 0;
  // calculate window size
  winHeight = imHeight + winPlusHeight;
  winWidth = imWidth + winPlusWidth;
  // test if the window is not too large
  heightOK = true;
  if (winHeight>screen.availHeight)
    { winHeight = screen.availHeight-80;
  	  resStr=",resizable=1,scrollbars=1";
  	heightOK = false;
  	}
  if (heightOK==false)
    { winWidth = winWidth+22;
  	}								 
  if (winWidth>screen.width)
    { winWidth = screen.width-80;
  	  resStr=",resizable=1,scrollbars=1";
  	}								 
  
  // calculate centered window position
  winLeft = Math.round((screen.width-winWidth)/2);
  winTop  = Math.round((screen.availHeight-winHeight)/2);
  
  iwin = window.open("", "", "left="+winLeft+",top="+winTop+",height="+winHeight+",width="+winWidth+",directories=no,location=no,menubar=no,status=no,toolbar=no"+resStr);
  iwin.document.write("<html><head><title>", iwinTitle, "</title>");
  iwin.document.write("<link rel='stylesheet' type='text/css' href='/imgwin.css' title='formal'>");
  iwin.document.write("</head>");
  iwin.document.write("<body class=ImgShow>");
  iwin.document.write("<a href='' onClick=\"window.close(); return false;\"><img width=", imWidth," height=", imHeight," src=\"", url, "\" alt='' border=0></a>");
  iwin.document.write("</body></html>");
  poc++;
  return true;
    }



