  var Template = ''+
  
  '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td>'+
  
  '<div style="position:relative; width:220; height:295px; overflow:hidden;">'+
  '<div style="position:absolute; width:78; height:55; overflow:hidden; visibility:hidden; border:1px solid;" id="cursor"></div>'+
  '{canvas}'+
  '</div>'+

  '</td><td style="background:url(/company/quality/certificates/img/cert-zoom-back.gif) repeat-x left top" width="100%">'+

  '<div style="width:295; height:295px; overflow:hidden; background:url(/company/quality/certificates/img/cert-zoom.gif) no-repeat">'+
  
  '<div id="zoomarea" style="position:relative; top:9; left:5; width:274; height:275px; overflow:hidden;">'+
  '{zoomimage}'+
  '</div>'+

  '</div>'+

  '</td></tr></tbody></table>';

  //
  //
  //

  function ZoomViewer()
  {
    this.Name = "ZoomViewer"+ (ZoomViewer.Count++);
    this.Alias = "Object"+ this.Name;
    eval(this.Alias + "=this");
    this.Visible = false;
    this.Images = document.images;
    this.VisibleDelay = 100;
    this.TimeOut = null;

    this.Canvas = {Width:220, Height:295, Source:null, Bound:{Top:33, Right:33, Bottom:35, Left:32}};
    this.ZoomImage = {Width:550, Height:789, Source:null};
    this.OffsetY = 10;
    this.OffsetX = 30;
  }

  ZoomViewer.Count = 0;

  ZoomViewer.prototype.SetCanvas = function(sSource, nWidth, nHeight)
  {
    if(nWidth) this.Canvas.Width = nWidth;
    if(nHeight) this.Canvas.Height = nHeight;
    if(sSource) this.Canvas.Source = sSource;
  }

  ZoomViewer.prototype.SetZoomImage = function(sSource, nWidth, nHeight)
  {
    if(nWidth) this.ZoomImage.Width = nWidth;
    if(nHeight) this.ZoomImage.Height = nHeight;
    if(sSource) this.ZoomImage.Source = sSource;
  }

  ZoomViewer.prototype.Build = function()
  {
    var str = this.Template
    str = str.replace(/\{canvas\}/gi, '<img src="'+ this.Canvas.Source+ '" border="0" name="canvas" galleryimg="false" />');
    str = str.replace(/\{zoomimage\}/gi, '<img src="'+ this.ZoomImage.Source +'" border="0" name="zoomimage" style="position:absolute; visibility:hidden; filter:progid:DXImageTransform.Microsoft.Fade(duration=2);">');
    document.write(str)
  }

  ZoomViewer.prototype.Initialize = function()
  {
    if(!this.Images) return false;
    this.AttachEvents();
    this.SetCursorSize();
  }

  ZoomViewer.prototype.AttachEvents = function()
  {
    var c = document.getElementById("cursor");
    //this.Images['canvas'].onmousemove = new Function('e', zoom.Alias+ ".HandlerOnMouseMove(e)");
    this.Images['canvas'].onmouseover = new Function(zoom.Alias+ ".HandlerOnMouseOver()");
    this.Images['canvas'].onmouseout = new Function(zoom.Alias+ ".HandlerOnMouseOut()");
    c.onmouseover = new Function(zoom.Alias+ ".HandlerOnMouseOver()");
    document.body.onmousemove = new Function('e', zoom.Alias+ ".HandlerOnDocumentMouseMove(e)")
  }

  ZoomViewer.prototype.SetCursorSize = function()
  {
    var o = document.getElementById("cursor").style;
    var ca = this.Images['canvas'];
    var za = document.getElementById("zoomarea").style;
    var zi = this.Images['zoomimage'];

    var w = ((parseInt(ca.width) - (this.Canvas.Bound.Left + this.Canvas.Bound.Right)) * parseInt(za.width)) / parseInt(zi.width);
    var h = ((parseInt(ca.height) - (this.Canvas.Bound.Top + this.Canvas.Bound.Bottom)) * parseInt(za.height)) / parseInt(zi.height);

    o.width = w;
    o.height = h;
  }

  ZoomViewer.prototype.HandlerOnDocumentMouseMove = function(e)
  {
    var o = this.Images['canvas'];

    var y = GetOffsetTop(o);
    var x = GetOffsetLeft(o);

    var offsetX = GetEventPageX(e) - x;
    var offsetY = GetEventPageY(e) - y;

    var c = this.MoveCursorTo(offsetX, offsetY);
    this.ZoomTo(c.x, c.y);
  }

  ZoomViewer.prototype.HandlerOnMouseMove = function(e)
  {
    var offsetX = GetEventOffsetX(e);
    var offsetY = GetEventOffsetY(e);
    var c = this.MoveCursorTo(offsetX, offsetY);
    this.ZoomTo(c.x, c.y);
  }

  ZoomViewer.prototype.ZoomTo = function(offsetX, offsetY)
  {
    var za = document.getElementById("zoomarea").style;
    var ca = this.Images['canvas'];
    var o = this.Images['zoomimage'];
    
    var ch = ca.height - this.Canvas.Bound.Top - this.Canvas.Bound.Bottom;
    var y = (parseInt(offsetY) * o.height) / ch;
    y = (parseInt(za.height)/2) - y;

    var cw = ca.width - this.Canvas.Bound.Left - this.Canvas.Bound.Right;
    var x = (parseInt(offsetX) * o.width) / cw;
    x = (parseInt(za.width)/2) - x;

    o.style.top = y - this.OffsetY;
    o.style.left = x - this.OffsetX;
  }

  ZoomViewer.prototype.MoveCursorTo = function(offsetX, offsetY)
  {
    var o = document.getElementById("cursor").style;
    var h = parseInt(o.height);
    var w = parseInt(o.width);
    var hh = h/2;
    var hw = w/2;
    var y = offsetY - hh;
    var x = offsetX - hw;

    with(this.Canvas){
      var nBBottom = Height - Bound.Bottom - h;
      var nBRight = Width - Bound.Right - w;
      var nBTop = Bound.Top;
      var nBLeft = Bound.Left;
    }

    if((y > nBTop) && (y < nBBottom))
      o.top = y;
    else if(y < nBTop)
      o.top = nBTop;
    else if(y > nBBottom)
      o.top = nBBottom;

    if((x > nBLeft) && (x < nBRight))
      o.left = x;
    else if(x < nBLeft)
      o.left = nBLeft;
    else if(x > nBRight)
      o.left = nBRight

    return {x:o.left, y:o.top};
  }

  ZoomViewer.prototype.HandlerOnMouseOver = function()
  {
    if(this.TimeOut) clearTimeout(this.TimeOut);
    else this.OnShow();
  }

  ZoomViewer.prototype.HandlerOnMouseOut = function()
  {
    this.TimeOut = setTimeout(this.Alias+ '.OnHide()', this.VisibleDelay);
  }

  ZoomViewer.prototype.OnShow = function()
  {
    this.Images['zoomimage'].style.visibility = "visible";
    document.getElementById('cursor').style.visibility = "visible";
  }

  ZoomViewer.prototype.OnHide = function()
  {
    this.Images['zoomimage'].style.visibility = "hidden";
    document.getElementById('cursor').style.visibility = "hidden";
    this.TimeOut = null;
  }

  ZoomViewer.prototype.Template = Template

  //
  //
  //

  function GetEventOffsetX(e)
  {
    if(ie) return event.offsetX;
    else return e.layerX;
  }

  function GetEventOffsetY(e)
  {
    if(ie) return event.offsetY;
    else return e.layerY;
  }

  function GetEventPageX(e)
  {
    if(ie) return event.clientX + document.body.scrollLeft;
    else return e.pageX;
  }

  function GetEventPageY(e)
  {
    if(ie) return event.clientY + document.body.scrollTop;
    else return e.pageY;
  }

  function GetOffsetLeft(o)
  {
    var x = 0;
    while(o && (o.tagName.toLowerCase() != "body"))
    {
      x += o.offsetLeft;
      o = o.offsetParent;
    }
    return x;
  }

  function GetOffsetTop(o)
  {
    var y = 0;
    while(o && (o.tagName.toLowerCase() != "body"))
    {
      y += o.offsetTop;
      o = o.offsetParent;
    }
    return y;
  }
      
  //
  //
  //
