/* <![CDATA[ */


function image_zoom(obj, imgMaxW, imgMaxH) {
    var ElShowbox_el = document.getElementById('showbox_el');
    var ElShowbox = document.getElementById('showbox');

    show_layer2();
    ElShowbox_el.style.display = 'block';

    var imgSrc = obj.src;
    var imgWidth = obj.width;

    var BoxStartPosTop = get_top_pos_inpage(obj)-10;
    var BoxStartPosLeft = get_left_pos_inpage(obj)-10;


    var winW = get_win_w();
    var winH = get_win_h();
    var ScrlTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);


    if (imgMaxW > winW-200) {
      var newImgMaxW = winW-200;
      var koef = newImgMaxW / imgMaxW;
      imgMaxW = newImgMaxW;
      imgMaxH = imgMaxH * koef;
    }

    if (imgMaxH > winH-80) {
      var newImgMaxH = winH-80;
      var koef = newImgMaxH / imgMaxH;
      imgMaxH = newImgMaxH;
      imgMaxW = imgMaxW * koef;
    }


    BoxPosTop = parseInt(ScrlTop+((winH - imgMaxH)/2.6));
    BoxPosLeft = ((winW - imgMaxW)/2)-10;

    var strZoomVars = BoxStartPosTop+":"+BoxStartPosLeft+":"+imgWidth+":"+BoxPosTop+":"+BoxPosLeft+":"+imgMaxW+":"+ScrlTop;

    ElShowbox.innerHTML = "<img id='showedimg' alt='' src='"+imgSrc+"' /><div id=\"zoomvars\" class=\"text_version\">"+strZoomVars+"</div>";

    set_box_position(BoxStartPosTop, BoxStartPosLeft);
    set_img_box_sizes(imgWidth);

    image_zoom_in( BoxStartPosTop, BoxStartPosLeft, imgWidth, BoxPosTop, BoxPosLeft, imgMaxW, 0);


  }




  function image_zoom_in( BoxStartPosTop, BoxStartPosLeft, imgWidth, BoxPosTop, BoxPosLeft, imgMaxW, intLoop ) {
    timer = null;
    intLoop++;
    var intStepImgW = 25;
    var intStepPosTop = 0;
    var intStepPosLeft = 0;

    var moveImgW = imgMaxW - imgWidth;
    var koef = intStepImgW / moveImgW;

    var moveTop = BoxPosTop - BoxStartPosTop;
    intStepPosTop = koef * moveTop;

    var moveLeft = BoxPosLeft - BoxStartPosLeft;
    intStepPosLeft = koef * moveLeft;

    var NewImgWidth = imgWidth + (intStepImgW * intLoop);
    var NewBoxPosTop = BoxStartPosTop + (intStepPosTop * intLoop);
    var NewBoxPosLeft = BoxStartPosLeft + (intStepPosLeft * intLoop);

    set_img_box_sizes(NewImgWidth);

    if (isFinite(NewBoxPosLeft)) {
      set_box_position(NewBoxPosTop, NewBoxPosLeft);
    }


    //podminka pro porovnani velikosti  
    if(NewImgWidth < imgMaxW ) {
        timer = setTimeout("image_zoom_in( "+BoxStartPosTop+", "+BoxStartPosLeft+", "+imgWidth+", "+BoxPosTop+", "+BoxPosLeft+", "+imgMaxW+", "+intLoop+" );", 20);
    } else {
      set_img_box_sizes(imgMaxW);
      set_box_position(BoxPosTop, BoxPosLeft);
      closeBut = document.getElementById('close_prev');
      closeBut.style.display = 'block';
      clButLeft = imgMaxW - 75;
      closeBut.style.left = clButLeft+"px";
      setTimeout("repair_zoombox_position();", 200);
      return true;  
    }  
  }

  function repair_zoombox_position() {

    var strZoomVars = document.getElementById('zoomvars').innerHTML;
    if (strZoomVars!="") {
      var zoomVars = strZoomVars.split(":");

      var BoxStartPosTop = zoomVars[0];
      var BoxStartPosLeft = zoomVars[1];
      var imgWidth = zoomVars[2];
      var BoxPosTop = zoomVars[3];
      var BoxPosLeft = zoomVars[4];
      var imgMaxW = zoomVars[5];
      var prevScrl = zoomVars[6]; 
      var ScrlTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);

      var moveScrl = prevScrl - ScrlTop;
      var BoxPosTop = parseInt(BoxPosTop) - moveScrl;

      set_box_position(BoxPosTop, BoxPosLeft);

      var strZoomVars = BoxStartPosTop+":"+BoxStartPosLeft+":"+imgWidth+":"+BoxPosTop+":"+BoxPosLeft+":"+imgMaxW+":"+ScrlTop;
      document.getElementById('zoomvars').innerHTML = strZoomVars;
      setTimeout("repair_zoombox_position();", 100);
    }  
  }


  function image_zoom_out( BoxStartPosTop, BoxStartPosLeft, imgWidth, BoxPosTop, BoxPosLeft, imgMaxW, intLoop ) {
    timer = null;
    intLoop++;
    var intStepImgW = 18;
    var intStepPosTop = 0;
    var intStepPosLeft = 0;

    var moveImgW = imgMaxW - imgWidth;
    var koef = intStepImgW / moveImgW;

    var moveTop = BoxPosTop - BoxStartPosTop;
    intStepPosTop = koef * moveTop;

    var moveLeft = BoxPosLeft - BoxStartPosLeft;
    intStepPosLeft = koef * moveLeft;

    var NewImgWidth = imgMaxW - (intStepImgW * intLoop);
    var NewBoxPosTop = BoxPosTop - (intStepPosTop * intLoop);
    var NewBoxPosLeft = BoxPosLeft - (intStepPosLeft * intLoop);


    set_img_box_sizes(NewImgWidth);

    if (isFinite(NewBoxPosLeft)) {
      set_box_position(NewBoxPosTop, NewBoxPosLeft);
    }

    //podminka pro porovnani velikosti  
    if(NewImgWidth > imgWidth ) {
        timer = setTimeout("image_zoom_out( "+BoxStartPosTop+", "+BoxStartPosLeft+", "+imgWidth+", "+BoxPosTop+", "+BoxPosLeft+", "+imgMaxW+", "+intLoop+" );", 18);
    } else {

//      set_img_box_sizes(imgWidth);
      set_box_position(BoxStartPosTop, BoxStartPosLeft);
      setTimeout("hide_layer2();", 250); 
      return true;  
    }  
  }







  function get_win_w() {
    var winW = 630;
    if (document.body && document.body.offsetWidth) {
      winW = document.body.offsetWidth;
    }
    if (document.compatMode=='CSS1Compat' &&
        document.documentElement &&
        document.documentElement.offsetWidth ) {
      winW = document.documentElement.offsetWidth;
    }
    if (window.innerWidth) {
      winW = window.innerWidth;
    }
  return winW;
  }

  function get_win_h() {
    winH = 460;
    if (document.body && document.body.offsetHeight) {
      winH = document.body.offsetHeight;
    }
    if (document.compatMode=='CSS1Compat' &&
        document.documentElement &&
        document.documentElement.offsetHeight ) {
      winH = document.documentElement.offsetHeight;
    }
    if (window.innerHeight) {
      winH = window.innerHeight;
    }
  return winH;
  }


  function set_box_position(BoxPosTop, BoxPosLeft) {
    ElShowbox_el = document.getElementById('showbox_el');
    ElShowbox_el.style.top = BoxPosTop+"px";
    ElShowbox_el.style.left = BoxPosLeft+"px";
  }


  function get_top_pos_inpage(obj) {
    var StartPosTop = 0;
    var testObj = obj;
    while (testObj.tagName != "BODY") {
      StartPosTop += testObj.offsetTop;
      testObj = testObj.offsetParent;
    }
  return StartPosTop;
  }

  function get_left_pos_inpage(obj) {
    var StartPosLeft = 0;
    var testObj = obj;
    while (testObj.tagName != "BODY") {
      StartPosLeft += testObj.offsetLeft;
      testObj = testObj.offsetParent;
    }
  return StartPosLeft;
  }

  function getBrowserHeight(){
	  if (document.body){
		  return document.body.clientHeight;}
    else if (document.documentElement && document.documentElement.clientHeight != 0){
		  return document.documentElement.clientHeight;}
	  else if (window.innerHeight){
		  return window.innerHeight;	}
    return 0;
  };

/*
  function getBrowserWidth(){
	  if (document.body){
		  return document.body.clientWidth; }
	  else if (window.innerWidth){
		  return window.innerWidth; }
    else if (document.documentElement && document.documentElement.clientWidth != 0){
		  return document.documentElement.clientWidth;}
    return 0;
  };
*/

  function show_layer2() {
    ElLayer_2_bkg = document.getElementById('layer_2_bkg');
    br_height = getBrowserHeight();
    ElLayer_2_bkg.style.height = br_height+"px";
    ElLayer_2_bkg.style.display = 'block';
  }

  function set_img_box_sizes(imgWidth) {
    boxWidth = imgWidth+20;
    ElShowedimg = document.getElementById('showedimg');
    ElShowbox_el = document.getElementById('showbox_el');
    ElShowedimg.style.width = imgWidth+"px";
    ElShowbox_el.style.width = boxWidth+"px";
  }



  function hide_showbox() {

    closeBut = document.getElementById('close_prev');
    closeBut.style.display = 'none';

    var strZoomVars = document.getElementById('zoomvars').innerHTML;
    document.getElementById('zoomvars').innerHTML = "";
    var zoomVars = strZoomVars.split(":");

    var BoxStartPosTop = zoomVars[0];
    var BoxStartPosLeft = zoomVars[1];
    var imgWidth = zoomVars[2];
    var BoxPosTop = zoomVars[3];
    var BoxPosLeft = zoomVars[4];
    var imgMaxW = zoomVars[5];

    image_zoom_out( BoxStartPosTop, BoxStartPosLeft, imgWidth, BoxPosTop, BoxPosLeft, imgMaxW, 0 );

  }


  function hide_layer2() {
      showbox_elmt = document.getElementById('showbox_el');
      layer2bkg = document.getElementById('layer_2_bkg');  
      showbox_elmt.style.display = 'none';
      layer2bkg.style.display = 'none';
  }


function open_hiding_el(n){
  el_par = 'hiding_el_'+n;
  el_btn_open = 'hiding_btn_open_'+n;
  el_btn_close = 'hiding_btn_close_'+n;
  if (document.getElementById(el_par)) {
    document.getElementById(el_par).style.display = "block";
    document.getElementById(el_btn_open).style.display = "none";
    document.getElementById(el_btn_close).style.display = "block";
  }
}

function close_hiding_el(n){
  el_par = 'hiding_el_'+n;
  el_btn_open = 'hiding_btn_open_'+n;
  el_btn_close = 'hiding_btn_close_'+n;
  if (document.getElementById(el_par)) {
    document.getElementById(el_par).style.display = "none";
    document.getElementById(el_btn_open).style.display = "block";
    document.getElementById(el_btn_close).style.display = "none";
  }
}

function emadr_code(el,user,server){
  code = "<a href='mai"+"lto"+":"+user+"@"+server+"'>"+user+"@"+server+"</a>";
  document.getElementById(el).innerHTML = code;
}


/* ]]> */
