function zoom(o,param){
 var s = null,d;
 (param)? s = new param(o) : "" ;
 function V(a,b){var d=0;while(a){d+=a[b];a=a.offsetParent;}return d};

 (param)? d="div" : d="img" ;

  var im = document.createElement(d);
      if(d=="div"){
        im.style.border = "black solid 1px";
        im.style.backgroundColor = "rgb(246,246,246)";
/*        im.style.textAlign = "center"; */
        (!s.obj) ? im.innerHTML = s.message : im.innerHTML = s.obj.innerHTML ;
        im.callback =  param;
        im.elm = s.elm;
        o.onclick = function(){return false;}
      }

      var container = createTb(im);
      container.style.left=V(o,"offsetLeft")+"px";
      container.style.top = (d=="div")? V(o,"offsetTop")+o.offsetHeight-1+"px" : V(o,"offsetTop")+"px";
      im.src = o.src;

      (!o.src)   ? im.width = s.width : "";
      (!o.src && s.height != "auto" )   ? im.height= s.height - 100 : "";
      (!o.width) ? o.width = s.width - 100 : "";
      var a = container.style.left.replace("px","")*1 + im.width*1;
      if(a > parseInt(document.body.clientWidth)){
       container.style.left = (container.style.left.replace("px","")*1 - ( a- parseInt(document.body.clientWidth))-20)+"px" ;
      }
   try{
      im.onload = loaded(im,o.width);
   }catch (e){}
  return im;
}

function loaded(o,w){
 if(!o.orig)    o.orig = o.width;
 if(!o.small)   o.small = w;
 if(!this.w)    this.w = w;
 if(!this.h && o.height !="auto" )    this.h = o.height;
 if(!this.cnt)  this.cnt = 0;

if(this.w < o.orig){
   this.cnt++;
   this.w += 15;
   (this.h) ? this.h += 15 : "";
   if(this.w > o.orig)  this.w = o.orig;
   try{
    o.parentNode.offsetParent.style.visibility = "visible";
   }catch (e){
    o.style.visibility = "visible";
   }
    o.style.width=this.w+"px";
   (o.nodeName == "DIV" && this.h )? o.style.height=this.h+"px" : "";
   this.ind = setTimeout(function(){return loaded(o,w)},0);
 }else{
   clearTimeout(loaded.ind);
   o.onclick=function(){uloaded(this)}
   o.arr = this.w+"|"+o.orig+"|"+this.cnt+"|"+o.small;
   try{
     o.position = o.parentNode.offsetParent.style.top+"|"+o.parentNode.offsetParent.style.left;
   }catch (e){}

   (!o.position) ? o.position = o.style.top+"|"+o.left : "";

   o.orig  = null;
   o.small = null;
   this.w  = null;
   this.h  = null;
   this.cnt= null;

 }
}

function uloaded(o){
// alert(o.arr)
// alert(o.position )
 if(o.uloaded_break)  return false ;
 if(o.arr){
  var a = o.arr.split("|");
  o.style.width = a[3]+ "px";
 }
 var callback = o.callback;
 (o.elm) ? o.elm.onclick = function(){return zoom(this,callback)} : "";
 while(o.parentNode){
  o = o.parentNode;
  if(o.nodeName == "BODY") break;
  o.removeChild(o.lastChild);
 }
}

function createTb (_im){
   this.table = document.createElement("table");
   this.table.cellSpacing      = 0;
   this.table.style.visibility = "hidden";
   this.table.setAttribute("style","z-index:1000");
   this.table.style.position   = "absolute";
   this.table.style.top        = 0+"px";
   this.table.style.left       = 0+"px";
   this.table.border           = 0;
   this.table.style.borderCollapse = "collapse";
   this.table.style.background = "transparent";
   this.table.className = "ZoomLaier";
   this.tbody = document.createElement("tbody");

   this.table.appendChild(this.tbody);
   this.td = [];
   for (var i = 0; i <= 8; i++) {
      if (i % 3 == 0){
       tr = document.createElement("tr")
       tr.style.height = "auto";
       this.tbody.appendChild(tr);
      }
      this.td[i] = document.createElement("td");
      tr.appendChild(this.td[i]);
      var style = i != 4 ? { lineHeight: 0, fontSize: 0} : { position : null };
      (style.lineHeight) ? this.td[i].style.lineHeight = style.lineHeight : "";
      (style.fontSize) ? this.td[i].style.fontSize = style.fontSize : "";
      (style.position) ? this.td[i].style.position = style.position : "";
      this.td[i].style.padding = "0px";
   }
 var src = "./img/drop-shadow.png";

 this.graphic = document.createElement("img");
 this.graphic.style.position = "absolute";
 this.graphic.style.left = "-999px";
 this.graphic.style.top  = "-999px";
 this.graphic.src = src;

   var  o = this.offset = this.graphic.width / 4,
//      pos = [[0,0],[0,-4],[-2,0],[0,-8],0,[-2,-8],[0,-2],[0,-6],[-2,-2]],
      pos = [[0,0],[0,-40],[-30, 0],[0 ,-80],0,[-30,-80],[0,-30],[0,-70],[-30,-28]],
//      dim = { height: (2*o) +"px", width: (2*o) +"px" };
      dim = { height: (2) +"px", width: (2) +"px" };

   for (var i = 0; i <= 8; i++) {
      if (pos[i]) {

         if (document.alls && !window.opera) {
            var w = (i == 1 || i == 7) ? "100%" : this.graphic.width +"px";
            var div = document.createElement("div");
                div.style.width    = "100%";
                div.style.height   = "100%";
                div.style.position = "relative";
                div.style.overflow = "hidden";
            this.td[i].appendChild(div);
            var d = document.createElement ("div");
                d.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='"+ this.graphic.src + "')";
                d.style.position = "absolute";
                d.style.width = w;
                d.style.height = this.graphic.height +"px";
                d.style.left = (pos[i][0])+"px";
                d.style.top  = (pos[i][1])+"px";
            div.appendChild(d);
         } else {
         var s = [];
               s[0] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position:  -0px  -0px; background-repeat: no-repeat";
               s[1] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position:   0px -40px;";
               s[2] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position: -30px  -0px; background-repeat: no-repeat";
               s[3] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position:  -0px -80px; background-repeat: no-repeat";
               s[4] = "";
               s[5] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position: -30px -80px; background-repeat: no-repeat";
               s[6] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position:   0px -30px; background-repeat: no-repeat";
               s[7] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position:   0px -70px;";
               s[8] = "padding: 0px; background:transparent url("+this.graphic.src+"); background-position: -30px -28px; background-repeat: no-repeat";

            this.td[i].setAttribute("style",s[i]);
         }
         if (window.opera && (i == 3 || i ==5)){
            var d = document.createElement("div");
                d.style.height = dim.height;
                d.style.width  = dim.width;
                this.td[i].appendChild(d);
           }
            this.td[i].height = "10px"; //dim.height;
            this.td[i].width  = "10px"; //dim.width;
      }
   }
    this.td[4].style.backgroundColor = "white";
    this.td[4].setAttribute("nowrap","true");
    this.td[4].appendChild(_im);
    document.body.appendChild(this.table);
  return this.table;
}
