var ret = -1
function openimage(obj) {
  im = new Image();
  im.src = obj.href;
  im.onload = function () {
  }
  if(im) {
    if(ret != null || ret == -1 || ret.document == null || typeof ret.document == "unknown") {
      if(typeof ret.document == "object" && typeof ret == "object" && typeof ret.close() == "object") {
        ret.close();
        ret = null;
      }
      params = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, rezisable=yes, copyhistory=no";
      ret = window.open('about:blank', 'obrazky', params);
      ret.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"><head><title>Obrazek</title></head><body><div id=\"imagecontainer\"></div></body></hmtl>");
    } else {
      body = ret.document.getElementById("imagecontainer");
      if(body.childNodes)
        for( i = 0 ; i < body.childNodes.length ; i ++ ){
          if(body.childNodes[i].tagName == "IMG")
            body.removeChild(body.childNodes[i]);
        }
    } /*
    alert(typeof ret);
    alert(typeof ret.document);
    alert(typeof ret.document.getElementById("imagecontainer"));
    alert(typeof ret.document.getElementById("imagecontainer").appendChild);//*/
    if(typeof ret.document.getElementById("imagecontainer").appendChild == "function") {
      ret.document.getElementById("imagecontainer").appendChild(im);
    } else {
      ret.document.getElementById("imagecontainer").innerHTML = im.outerHTML;
    }
    if(ret) {
      resizeWidow(ret);
      return true;
    } else {
      return false;
    }
  }
}
function resizeWidow(win) {
  // for Gecko
  if (typeof(self.sizeToContent) == 'function') {
    win.sizeToContent();
    //self.scrollbars.visible = false;
    // give some more space ... to prevent 'fli(pp/ck)ing'
    win.resizeBy(10, 50);
    return true;
  }

  // for IE, Opera
  if (win.document.getElementById && typeof(win.document.getElementById('imagecontainer')) != 'undefined') {

    // get content size
    var newWidth  = win.document.getElementById('imagecontainer').offsetWidth;
    var newHeight = win.document.getElementById('imagecontainer').offsetHeight;

    // set size to contentsize
    // plus some offset for scrollbars, borders, statusbar, menus ...
    win.resizeTo(newWidth + 45, newHeight + 75);
    return true;
  }
}
function parseDocument () {
  as = document.getElementsByTagName("A");
  for(i = 0; i< as.length;i++) {
    e = as[i];
    if(e.href.indexOf("file_imce.php?guid=") > 0) {
      im = new Image();
      im.src = e.href;
      if(im.width > 0 && im.height > 0) {
        e.onclick = function () {
          return !openimage(this);
        }
      }
    }
  }
}
function closeImage() {
  ret.close();
}

