function _InitManager()
{
  this.execute_events = function(name)
  {
    if (!this.events[name])
      return;
    for (var k in this.events[name])
    {
      if (k == "length")
        continue;
      if (typeof(this.events[name][k]) == "function")
        this.events[name][k]();
      else if (typeof(this.events[name][k]) == "string")
        eval(this.events[name][k]);
    }
  }
  this.register_event = function(name, callback)
  {
    if (!this.events[name])
    {
      this.events[name] = new Object();
      this.events[name]["length"] = 0;
    }
    this.events[name]["length"]++;
    this.events[name][this.events[name]["length"]]=callback;
  }
  this.unregister_event = function(name, callback)
  {
    if (!this.events[name])
      return;
    for (var k in this.events[name])
    {
      if (k == "length")
        continue;
      if (this.events[name][k]==callback)
      {
        delete this.events[name][k];
        this.events[name]["length"]--;
        return;
      }
    }
  }
  this.events = new Object();
  window.onload = function() {InitManager.execute_events("onload");};
  window.onresize = function() {InitManager.execute_events("onresize");};
  window.onscroll = function() {InitManager.execute_events("onscroll");};
}
var InitManager = new _InitManager();

function _ConnectionManager()
{
  this.pool;
  this.requests;
  this.req_next=1;
  this.createHttpRequest = function()
  {
    req = null;
    if (window.XMLHttpRequest)
    {
      try
      {
        req = new XMLHttpRequest();
      } catch (e){}
    }
    else if (window.ActiveXObject)
    {
      try
      {
        req = new ActiveXObject('Msxml2.XMLHTTP');
      } catch (e)
      {
        try
        {
          req = new ActiveXObject('Microsoft.XMLHTTP');
        } catch (e){}
      }
    }
    return req;
  }
  this.checkLoad = function()
  {
    for (var k=0;k<5;k++)
    {
      if (this.pool[k]["active"])
      {
        if (this.pool[k]["obj"].readyState == 4)
        {
          if (this.pool[k]["obj"].status == 200)
            this.pool[k]["callback"](this.pool[k]["obj"].responseXML);
          delete this.requests[this.pool[k]["req_id"]];
          this.pool[k]["active"]=false;
          this.pool[k]["time"]=0;
          this.pool[k]["req_id"]=0;
        }
        else
        {
          if (((new Date).getTime()-this.pool[k]["time"])>5000)
          {
            this.pool[k]["obj"].abort();
            this.requests[this.pool[k]["req_id"]]["active"]=false;
            this.pool[k]["active"]=false;
            this.pool[k]["time"]=0;
            this.pool[k]["req_id"]=0;
            this.send();
          }
        }
      }
    }
    this.send();
    setTimeout("ConnectionManager.checkLoad()",200);
  }
  this.init = function()
  {
    this.pool = new Object();
    for (var k=0;k<5;k++)
    {
      this.pool[k]=new Object();
      this.pool[k]["obj"]=this.createHttpRequest();
      this.pool[k]["active"]=false;
      this.pool[k]["req_id"]=0;
      this.pool[k]["time"]=0;
    }
    this.requests = new Object();
    setTimeout("ConnectionManager.checkLoad()",200);
  }
  this.send = function()
  {
    for (var k in this.requests)
    {
      if (!this.requests[k]["active"])
      {
        for (var m=0;m<5;m++)
        {
          if (!this.pool[m]["active"])
          {
            this.pool[m]["active"]=true;
            this.pool[m]["req_id"]=k;
            this.pool[m]["callback"]=this.requests[k]["callback"];
            this.pool[m]["time"]=(new Date()).getTime();
            this.requests[k]["active"]=true;
            this.pool[m]["obj"].open("POST", this.requests[k]["url"], true);
            this.pool[m]["obj"].setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
            this.pool[m]["obj"].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            this.pool[m]["obj"].setRequestHeader("Content-length", this.requests[k]["params"].length);
            this.pool[m]["obj"].setRequestHeader("Connection", "close");
            this.pool[m]["obj"].send(this.requests[k]["params"]);
            break;
          }
        }
      }
    }
  }
  this.get = function(url,params,callback)
  {
    if (!this.pool)
      this.init();
    this.requests[this.req_next]=new Object();
    this.requests[this.req_next]["url"]=url;
    this.requests[this.req_next]["params"]=params;
    this.requests[this.req_next]["callback"]=callback;
    this.requests[this.req_next++]["active"]=false;
    this.send();
  }
}
var ConnectionManager = new _ConnectionManager();

function fix_png(el)
{
  if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) return;

  var src;
  if (el.tagName=='IMG')
  {
    if (/\.png$/.test(el.src))
    {
      src = el.src;
      el.src = "/img/high.gif";
      el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
    }
  }
  else
  {
    src = el.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
    if (src)
    {
      src = src[1];
      el.runtimeStyle.backgroundImage="none";
      if (el.currentStyle.backgroundRepeat == "no-repeat")
        el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
      else
        el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
    }
  }
}

function _ImageViewer()
{
  this.handle;
  this.viewarea;
  this.thumbails;
  this.shadow;
  this.loading;
  this.close_button;
  this.prev_button;
  this.next_button;
  this.sce;
  this.images = new Object();
  this.mwidth = 352;
  this.mheight = 200;
  this.tcount;
  this.is_loading = false;
  this.is_slideshow = false;
  this.prev_image = function()
  {
    this.onclick_thumbail(this.images.curr-1);
  }
  this.next_image = function()
  {
    this.onclick_thumbail(this.images.curr+1);
  }
  this.set_nav = function ()
  {
    if (this.images.curr > 1)
      this.prev_button.style.visibility="visible";
    else
      this.prev_button.style.visibility="hidden";
    if (this.images.curr < this.images.length)
      this.next_button.style.visibility="visible";
    else
      this.next_button.style.visibility="hidden";
  }
  this.pos = function()
  {
    if (!this.handle)
      return;
    var atop = 0;
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      atop = document.documentElement.scrollTop;
    this.handle.style.top = ((document.documentElement.clientHeight - this.handle.offsetHeight) / 2) + atop + "px";
    this.handle.style.left = ((document.documentElement.clientWidth - this.handle.offsetWidth) / 2) + "px";
    this.close_button.style.left = this.handle.offsetLeft + this.handle.offsetWidth + "px";
    this.close_button.style.top = this.handle.offsetTop - this.close_button.offsetHeight + "px";
    this.expand_button.style.left = this.handle.offsetLeft - this.expand_button.offsetWidth - 5 + "px";
    this.expand_button.style.top = this.handle.offsetTop + 50 + "px";
    this.slide_button.style.left = this.handle.offsetLeft - this.slide_button.offsetWidth - 5 + "px";
    this.slide_button.style.top = this.handle.offsetTop + 75 + "px";
    this.prev_button.style.left = this.handle.offsetLeft - this.prev_button.offsetWidth - 5 + "px";
    this.prev_button.style.top = this.handle.offsetTop + this.handle.offsetHeight / 2  + "px";
    this.next_button.style.left = this.handle.offsetLeft + this.handle.offsetWidth + 5 + "px";
    this.next_button.style.top = this.handle.offsetTop + this.handle.offsetHeight / 2 + "px";
    this.thumb_prev_button.style.left = this.handle.offsetLeft - this.thumb_prev_button.offsetWidth - 5 + "px";
    this.thumb_prev_button.style.top = this.handle.offsetTop + this.handle.offsetHeight - this.thumbails.offsetHeight + 5  + "px";
    this.thumb_next_button.style.left = this.handle.offsetLeft + this.handle.offsetWidth + 5 + "px";
    this.thumb_next_button.style.top = this.handle.offsetTop + this.handle.offsetHeight - this.thumbails.offsetHeight + 5  + "px";
    this.loading.style.left = this.handle.offsetLeft + (this.viewarea.offsetWidth - this.loading.offsetWidth) / 2 + "px";
    this.loading.style.top = this.handle.offsetTop + (this.viewarea.offsetHeight - this.loading.offsetHeight) / 2 +  "px";
    this.set_nav();
  }
  this.dark_all = function()
  {
    this.shadow = document.createElement("DIV");
    this.shadow.style.cssText = "z-index:1000;background:#000000;left:0px;top:0px;width:100%;height:100%;position:fixed;opacity:0.5;filter:alpha(opacity=50);";
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
    {
      this.shadow.style.position = "absolute";
      this.shadow.style.width = document.documentElement.scrollWidth;
      this.shadow.style.height = document.documentElement.scrollHeight;
    }
    document.body.appendChild(this.shadow);
  }
  this.get_text = function(obj)
  {
    if (/MSIE/.test(navigator.userAgent))
      return obj.text;
    return obj.textContent;
  }
  this.set_thumbail = function(id)
  {
    this.images[id].thumbail.src = this.images[id].thumbail_t.src;
    this.images[id].thumbail.onmouseover = function(id) {return function() {ImageViewer.onmouseover_thumbail(id)}} (id);
    this.images[id].thumbail.onmouseout = function(id) {return function() {ImageViewer.onmouseout_thumbail(id)}} (id);
    if (id == this.images.curr)
    {
      this.images[this.images.curr].thumbail.style.cssText = "margin:0;width:48px;height:48px;border:1px solid #aa0000;filter:alpha(opacity=100);opacity:1;cursor:default;";
      this.images[this.images.curr].thumbail.onclick = function() {};
      return;
    }
    var a = "";
    if (this.images[id].thumbail.style.visibility == "hidden")
      a = "visibility:hidden;";
    this.images[id].thumbail.style.cssText = "margin:5px;width:40px;height:40px;border:0;opacity:0.5;filter:alpha(opacity=50);cursor:pointer;" + a;
    this.images[id].thumbail.onclick = function(id) {return function() {ImageViewer.onclick_thumbail(id)}} (id);
  }
  this.load = function()
  {
    this.is_loading = true;
    this.prev_button.style.visibility = "hidden";
    this.next_button.style.visibility = "hidden"
    this.images[this.images.curr].image = document.createElement("IMG");
    this.images[this.images.curr].image.src = this.images[this.images.curr].src;
    if (!this.images[this.images.curr].image.complete)
    {
      this.loading.style.visibility = "visible";
      this.images[this.images.curr].image.onload = function() {ImageViewer.set_image()};
    }
    else
      this.set_image();
  }
  this.light_image = function()
  {
    if (!this.handle)
      return;
    this.images[this.images.curr].alpha += 10;
    if (/MSIE/.test(navigator.userAgent))
    {
      this.images[this.images.curr].alpha += 10;
      this.images[this.images.curr].image.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.images[this.images.curr].alpha + ");";
    }
    else
      this.images[this.images.curr].image.style.opacity = this.images[this.images.curr].alpha / 100;
    if (this.images[this.images.curr].alpha < 100)
      setTimeout(function() {ImageViewer.light_image()}, 50);
    else
    {
      this.is_loading = false;
      this.images[this.images.curr].image.onclick = function() {ImageViewer.close();};
    }
  }
  this.get_dims = function()
  {
    var maxw = document.documentElement.clientWidth - this.prev_button.offsetWidth - this.next_button.offsetWidth - 50;
    var maxh = document.documentElement.clientHeight - this.close_button.offsetHeight - 40 - this.thumbails.offsetHeight;
    var w = this.images[this.images.curr].w;
    var h = this.images[this.images.curr].h;
    if (h > maxh)
    {
      var old_h = h;
      h = maxh;
      w = Math.round(h / old_h * w);
    }
    if (w > maxw)
    {
      var old_w = w;
      w = maxw;
      h = Math.round(w / old_w * h);
    }
    return [w,h];
  }
  this.set_image = function()
  {
    if (!this.handle)
      return;
    this.loading.style.visibility = "hidden";
    if (this.viewarea.childNodes.length == 1)
      this.viewarea.removeChild(this.viewarea.childNodes[0]);
    if (/MSIE/.test(navigator.userAgent))
      this.images[this.images.curr].image.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0);";
    else
      this.images[this.images.curr].image.style.opacity = 0;
    this.images[this.images.curr].alpha = 0;
    this.viewarea.appendChild(this.images[this.images.curr].image);
    this.images[this.images.curr].w = this.images[this.images.curr].image.offsetWidth;
    this.images[this.images.curr].h = this.images[this.images.curr].image.offsetHeight;
    this.resize();
    this.light_image();
  }
  this.load_thumbails = function()
  {
    this.thumbails.style.height = "52px";
    var dv=document.createElement("DIV");
    dv.style.cssText = "height:50px;margin-top:1px;white-space:nowrap;position:relative;left:0;top:0;";
    this.thumbails.appendChild(dv);
    this.mheight += 52;
    for (var k in this.images)
    {
      if (isNaN(k))
        continue;
      this.images[k].thumbail = document.createElement("IMG");
      this.images[k].thumbail.src = "/img/iviewer/iw_iloading.gif";
      this.images[k].thumbail.style.cssText = "width:40x;height:40px;margin:5px;";
      dv.appendChild(this.images[k].thumbail);
      this.images[k].thumbail_t = document.createElement("IMG");
      this.images[k].thumbail_t.onload = function(k) {return function() {ImageViewer.set_thumbail(k)}} (k);
      this.images[k].thumbail_t.src = this.images[k].thumb_src;
    }
    this.resize();
  }
  this.parse_data = function(obj)
  {
    if (!this.handle)
      return;
    for (var k in this.images)
      delete this.images[k];
    var els = obj.getElementsByTagName("result");
    this.images.length = els.length;
    for (var k = 0;k < els.length;k++)
    {
      this.images[k+1] = new Object();
      this.images[k+1].rpoint = 0;
      this.images[k+1].rdir = 1;
      for (var m = 0;m < els.item(k).childNodes.length;m++)
      {
        var el = els.item(k).childNodes[m];
        var val = this.get_text(el);
        if (el.tagName == "curr")
        {
          if  (val == "1")
            this.images.curr = k + 1;
          continue;
        }
        this.images[k+1][el.tagName] = val;
      }
    }
    if (this.images.length > 0)
    {
      if (this.images.length > 1)
      {
        this.load_thumbails();
        this.slide_button.style.visibility = "visible";
      }
      this.load();
    }
  }
  this.move_thumbail = function(id)
  {
    this.images[id].rtm = setTimeout(function(id) {return function() {ImageViewer.move_thumbail(id)}} (id), 20);
    if (this.images[id].rdir == 1)
      return;
    if ((this.images[id].rdir == 3) && (this.images[id].ron == 1))
      return;
    if (this.images[id].rdir == 2)
    {
      if (this.images[id].rpoint == 0)
      {
        if (/MSIE/.test(navigator.userAgent))
          this.images[id].thumbail.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100);";
        else
          this.images[id].thumbail.style.opacity = 1;
      }
      this.images[id].rpoint++;
      if (this.images[id].rpoint == 6)
      {
        this.images[id].rdir = 3;
        this.images[id].rpoint = 5;
        return;
      }
    }
    if (this.images[id].rdir == 3)
    {
      if (this.images[id].rpoint == 0)
      {
        if (/MSIE/.test(navigator.userAgent))
          this.images[id].thumbail.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50);";
        else
          this.images[id].thumbail.style.opacity = 0.5;
      }
      this.images[id].rpoint--;
      if (this.images[id].rpoint == -1)
      {
        this.images[id].rpoint = 0;
        if (this.images[id].rdir == 3)
          this.images[id].rdir = 1;
      }
    }
    this.images[id].thumbail.style.margin = 5 -this.images[id].rpoint + "px";
    this.images[id].thumbail.style.width = 40 + this.images[id].rpoint * 2 + "px";
    this.images[id].thumbail.style.height = 40 + this.images[id].rpoint * 2 + "px";
  }
  this.onmouseover_thumbail = function(id)
  {
    if (this.images.curr != id)
    {
      this.images[id].rdir = 2;
      this.images[id].ron = 1;
      if (!this.images[id].rtm)
        this.images[id].rtm = setTimeout(function(id) {return function() {ImageViewer.move_thumbail(id)}} (id), 20);
    }
    if ((this.images[id].name) && (!this.is_loading))
    {
      this.name.style.display = "block";
      this.name.innerHTML = this.images[id].name;
      this.name.style.width = this.viewarea.childNodes[0].offsetWidth -40 + "px";
      this.name.style.left = this.handle.offsetLeft + "px";
      this.name.style.top = this.handle.offsetTop + this.viewarea.childNodes[0].offsetHeight - this.name.offsetHeight + "px";
    }
  }
  this.onmouseout_thumbail = function(id)
  {
    if (this.images.curr != id)
      this.images[id].ron = 0;
    this.name.style.display = "none";
  }
  this.onclick_thumbail = function(id,slide)
  {
    if (this.is_loading)
      return;
    if ((this.is_slideshow) && (!slide))
      this.stop_slide_show();
    if (/MSIE/.test(navigator.userAgent))
      this.images[this.images.curr].image.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50);";
    else
      this.images[this.images.curr].image.style.opacity = 0.5;
    this.images.curr = id;
    for (var k = 1;k <= this.images.length;k++)
      this.set_thumbail(k);
    this.is_loading = true;
    this.name.style.display = "none";
    this.load();
  }
  this.thumb_move_right = function()
  {
    if ((this.fthumb + this.tcount - 1) < this.images.length)
    {
      this.fthumb++;
      this.set_thumb_nav();
    }
  }
  this.thumb_move_left = function()
  {
    if (this.fthumb > 1)
    {
      this.fthumb--;
      this.set_thumb_nav();
    }
  }
  this.slide_show = function()
  {
    if (!this.handle)
      return;
    if (!this.is_slideshow)
      return;
    setTimeout(function() {ImageViewer.slide_show();},3000);
    if (this.is_loading)
      return;
    var id = this.images.curr + 1;
    if (id > this.images.length)
      id = 1;
    this.onclick_thumbail(id,true);
  }
  this.stop_slide_show = function()
  {
    this.is_slideshow = false;
    this.slide_button.src = "/img/iviewer/iw_slideshow.png";
    fix_png(this.slide_button);
  }
  this.start_slide_show = function()
  {
    if (this.is_loading)
      return;
    if (this.is_slideshow)
    {
      this.stop_slide_show();
      return;
    }
    this.slide_button.src = "/img/iviewer/iw_slideshow_sel.png";
    fix_png(this.slide_button);
    this.is_slideshow = true;
    this.slide_show();
  }
  this.expand_image = function()
  {
    window.open(this.images[this.images.curr].src);
  }
  this.set_thumb_nav = function()
  {
    for (var k = 1;k <= this.images.length;k++)
      this.images[k].thumbail.style.visibility = "hidden";
    for (var k = this.fthumb;k < (this.tcount + this.fthumb);k++)
    {
      if (k > this.images.length)
        break;
      this.images[k].thumbail.style.visibility = "visible";
    }
    this.thumbails.childNodes[0].style.left = (this.viewarea.offsetWidth - this.tcount * 50) / 2 - (this.fthumb - 1) * 50 + "px";
    if (this.fthumb > 1)
      this.thumb_prev_button.style.visibility = "visible";
    else
      this.thumb_prev_button.style.visibility = "hidden";
    if ((this.fthumb + this.tcount - 1) < this.images.length)
      this.thumb_next_button.style.visibility = "visible";
    else
      this.thumb_next_button.style.visibility = "hidden";
  }
  this.resize = function()
  {
    if (this.viewarea.childNodes.length == 1)
    {
      var dims = this.get_dims();
      this.images[this.images.curr].image.style.width = dims[0] + "px";
      this.images[this.images.curr].image.style.height = dims[1] + "px";
      this.viewarea.style.width = this.viewarea.childNodes[0].offsetWidth + "px";
      this.viewarea.style.height = this.viewarea.childNodes[0].offsetHeight + "px";
    }
    this.thumbails.style.width = this.viewarea.offsetWidth + "px";
    this.handle.style.width = this.viewarea.offsetWidth + "px";
    this.handle.style.height = this.viewarea.offsetHeight + this.thumbails.offsetHeight + "px";
    if (this.images.length > 1)
    {
      var w = this.viewarea.offsetWidth - 2;
      this.tcount = Math.floor(w / 50);
      this.fthumb = 1;
      if (this.tcount < this.images.length)
      {
        this.fthumb = this.images.curr - Math.floor(this.tcount / 2);
        if (this.fthumb < 1)
          this.fthumb = 1;
        if ((this.fthumb + this.tcount - 1) > this.images.length)
          this.fthumb = this.images.length - this.tcount + 1;
      }
      else
        this.tcount = this.images.length;
      this.set_thumb_nav();
    }
    this.pos();
  }
  this.create_self = function()
  {
    this.dark_all();
    this.handle = document.createElement("DIV");
    this.handle.style.cssText = "position:fixed;z-index:1001;background:#ffffff;width:" + this.mwidth + "px;height:" + this.mheight + "px;-webkit-box-shadow:2px 2px 10px #000000;-moz-box-shadow:2px 2px 10px #000000;box-shadow:2px 2px 10px #000000;filter:progid:DXImageTransform.Microsoft.Shadow(color='#000000',Direction=135,Strength=6);";
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.handle.style.position = "absolute";
    document.body.appendChild(this.handle);
    this.viewarea = document.createElement("DIV");
    this.viewarea.style.cssText = "width:" + this.mwidth + "px;height:" + this.mheight + "px;";
    this.handle.appendChild(this.viewarea);
    this.thumbails = document.createElement("DIV");
    this.thumbails.style.cssText = "width:" + this.mwidth + "px;height:0px;overflow:hidden;";
    this.handle.appendChild(this.thumbails);
    this.close_button = document.createElement("IMG");
    this.close_button.src = "/img/iviewer/iw_close.png";
    this.close_button.style.cssText = "position:fixed;z-index:1002;cursor:pointer;width:15px;height:15px;";
    this.close_button.onclick = function() {ImageViewer.close();};
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.close_button.style.position = "absolute";
    document.body.appendChild(this.close_button);
    this.prev_button = document.createElement("IMG");
    this.prev_button.src = "/img/iviewer/iw_nav_prev.png";
    this.prev_button.style.cssText = "position:fixed;z-index:1002;width:20px;height:19px;cursor:pointer;visibility:hidden;";
    this.prev_button.onclick = function() {ImageViewer.prev_image();};
    this.prev_button.onmouseover = function() {this.src = "/img/iviewer/iw_nav_prev_sel.png";fix_png(this);};
    this.prev_button.onmouseout = function() {this.src = "/img/iviewer/iw_nav_prev.png";fix_png(this);};
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.prev_button.style.position = "absolute";
    document.body.appendChild(this.prev_button);
    this.next_button = document.createElement("IMG");
    this.next_button.src = "/img/iviewer/iw_nav_next.png";
    this.next_button.style.cssText = "position:fixed;z-index:1003;width:20px;height:19px;cursor:pointer;visibility:hidden;";
    this.next_button.onclick = function() {ImageViewer.next_image();};
    this.next_button.onmouseover = function() {this.src = "/img/iviewer/iw_nav_next_sel.png";fix_png(this);};
    this.next_button.onmouseout = function() {this.src = "/img/iviewer/iw_nav_next.png";fix_png(this);};
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.next_button.style.position = "absolute";
    document.body.appendChild(this.next_button);
    this.thumb_next_button = document.createElement("IMG");
    this.thumb_next_button.src = "/img/iviewer/iw_tnav_next.png";
    this.thumb_next_button.style.cssText = "position:fixed;z-index:1003;width:20px;height:40px;cursor:pointer;visibility:hidden;";
    this.thumb_next_button.onclick = function() {ImageViewer.thumb_move_right();};
    this.thumb_next_button.onmouseover = function() {this.src = "/img/iviewer/iw_tnav_next_sel.png";fix_png(this);};
    this.thumb_next_button.onmouseout = function() {this.src = "/img/iviewer/iw_tnav_next.png";fix_png(this);};
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.thumb_next_button.style.position = "absolute";
    document.body.appendChild(this.thumb_next_button);
    this.thumb_prev_button = document.createElement("IMG");
    this.thumb_prev_button.src = "/img/iviewer/iw_tnav_prev.png";
    this.thumb_prev_button.style.cssText = "position:fixed;z-index:1003;width:20px;height:40px;cursor:pointer;visibility:hidden;";
    this.thumb_prev_button.onclick = function() {ImageViewer.thumb_move_left();};
    this.thumb_prev_button.onmouseover = function() {this.src = "/img/iviewer/iw_tnav_prev_sel.png";fix_png(this);};
    this.thumb_prev_button.onmouseout = function() {this.src = "/img/iviewer/iw_tnav_prev.png";fix_png(this);};
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.thumb_prev_button.style.position = "absolute";
    document.body.appendChild(this.thumb_prev_button);
    this.expand_button = document.createElement("IMG");
    this.expand_button.src = "/img/iviewer/iw_expand.png";
    this.expand_button.style.cssText = "position:fixed;z-index:1003;width:16px;height:18px;cursor:pointer;v";
    this.expand_button.onclick = function() {ImageViewer.expand_image();};
    this.expand_button.setAttribute("title","Открыть в новом окне");
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.expand_button.style.position = "absolute";
    document.body.appendChild(this.expand_button);
    this.slide_button = document.createElement("IMG");
    this.slide_button.src = "/img/iviewer/iw_slideshow.png";
    this.slide_button.style.cssText = "position:fixed;z-index:1003;width:22px;height:21px;cursor:pointer;visibility:hidden;";
    this.slide_button.onclick = function() {ImageViewer.start_slide_show();};
    this.slide_button.setAttribute("title","Слайдшоу");
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.slide_button.style.position = "absolute";
    document.body.appendChild(this.slide_button);
    this.loading = document.createElement("IMG");
    this.loading.src = "/img/iviewer/iw_loading.gif";
    this.loading.style.cssText = "position:fixed;z-index:1020;width:208px;height:13px;";
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      this.loading.style.position = "absolute";
    document.body.appendChild(this.loading);
    this.name = document.createElement("DIV");
    this.name.style.cssText = "position:fixed;z-index:1030;display:none;background:url('/img/iviewer/iw_pix.png');color:#ffffff;font-weight:bold;font-size:14px;text-align:center;padding-bottom:5px;padding-top:5px;padding-left:20px;padding-right:20px;";
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
    {
      this.name.style.position = "absolute";
      this.name.className = "png";
    }
    document.body.appendChild(this.name);
    this.pos();
    InitManager.register_event("onresize", function() {ImageViewer.resize()});
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      InitManager.register_event("onscroll", function() {ImageViewer.pos()});
  }
  this.show = function(sce,id)
  {
    if (!this.handle)
      this.create_self();
    this.sce = sce;
    ConnectionManager.get(this.sce,"id="+id,function(txt) {ImageViewer.parse_data(txt)});
  }
  this.show_one = function(url)
  {
    if (!this.handle)
      this.create_self();
    this.expand_button.style.visibility = "hidden";
    for (var k in this.images)
      delete this.images[k];
    this.images.curr = 1;
    this.images[1] = new Object();
    this.images[1].src = url;
    this.load();
  }
  this.close = function()
  {
    InitManager.unregister_event("onresize", function() {ImageViewer.resize()});
    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
      InitManager.unregister_event("onscroll", function() {ImageViewer.pos()});
    document.body.removeChild(this.handle);
    document.body.removeChild(this.prev_button);
    document.body.removeChild(this.next_button);
    document.body.removeChild(this.thumb_prev_button);
    document.body.removeChild(this.thumb_next_button);
    document.body.removeChild(this.expand_button);
    document.body.removeChild(this.slide_button);
    document.body.removeChild(this.close_button);
    document.body.removeChild(this.loading);
    delete this.handle;
    document.body.removeChild(this.shadow);
  }
}
var ImageViewer = new _ImageViewer();

var block_max_height, block_x, block_y, cur_obj, old_txt, new_txt, new_script;
function block_smalling(obj)
{
  var el=obj.childNodes[4];
  var ht=el.offsetHeight-20;
  var step=ht/3;
  if (step<1)
  {
    el.style.height="20px";
    obj.childNodes[3].style.height="20px";
    obj.childNodes[5].style.height="20px";
    return;
  }
  el.style.height=el.offsetHeight-step+"px";
  obj.childNodes[3].style.height=el.style.height;
  obj.childNodes[5].style.height=el.style.height;
  setTimeout(function(obj1) {return function() {block_smalling(obj1)}} (obj),30);
}
function block_mediuming(obj)
{
  var el=obj.childNodes[4];
  var ht=160-el.offsetHeight;
  var step=ht/3;
  if (step<1)
  {
    el.style.height="160px";
    obj.childNodes[3].style.height="160px";
    obj.childNodes[5].style.height="160px";
    return;
  }
  el.style.height=el.offsetHeight+step+"px";
  obj.childNodes[3].style.height=el.style.height;
  obj.childNodes[5].style.height=el.style.height;
  setTimeout(function(obj1) {return function() {block_mediuming(obj1)}} (obj),30);
}
function block_larging(obj)
{
  var el=obj.childNodes[4];
  var wt=913-el.offsetWidth;
  var ht=block_max_height-el.offsetHeight-10;
  var x=obj.offsetLeft-block_x;
  var y=obj.offsetTop-block_y;
  var stepw=wt/3;
  var steph=ht/3;
  var stepx=x/3;
  var stepy=y/3;
  if (steph<1)
    el.style.height=block_max_height-10+"px";
  else
    el.style.height=el.offsetHeight+steph+"px";
  obj.childNodes[3].style.height=el.style.height;
  obj.childNodes[5].style.height=el.style.height;
  if (stepw<1)
    el.style.width="913px";
  else
    el.style.width=el.offsetWidth+stepw+"px";
  obj.childNodes[1].style.width=el.style.width;
  obj.childNodes[7].style.width=el.style.width;
  if (stepx<1)
    obj.style.left=block_x+"px";
  else
    obj.style.left=obj.offsetLeft-stepx+"px";
  if (stepy<1)
    obj.style.top=block_y+"px";
  else
    obj.style.top=obj.offsetTop-stepy+"px";
  var td=el.childNodes[2].childNodes[0].rows[0].cells[0];
  td.style.fontSize=td.style.fontSize.substr(0,td.style.fontSize.length-2)*1+1+"px";
  el.childNodes[2].style.width=el.offsetWidth-20+"px";
  el.childNodes[2].style.height=el.offsetHeight-35+"px";
  if ((td.childNodes[0]) && (td.childNodes[0].tagName=="IMG"))
  {
    var el1=td.childNodes[0];
    var ratio=el1.getAttribute("ratio");
    el1.style.height=el.childNodes[2].offsetHeight+"px";
    el1.style.width=el.childNodes[2].offsetHeight*ratio+"px";
  }
  if ((stepw<1) && (steph<1) && (stepx<1) && (stepy<1))
  {
    cur_obj=obj;
    new_txt=old_txt='';
    document.getElementById("close_"+el.childNodes[2].id.substr(5,500)).style.display="inline";
    ConnectionManager.get("/request.php","param=1&id="+el.childNodes[2].id.substr(5,500),block_show_info);
    return;
  }
  setTimeout(function(obj1) {return function() {block_larging(obj1)}} (obj),30);
}
var opacity=100;
function show_video(id,src,video)
{
  flowplayer(id, "/video/flowplayer-3.1.5.swf", {
    playlist : [
    {
      url: src
    }
    ,
    {
      url: video,
      autoPlay: true,
      autoBuffering: true
    }
    ]
  });
}
function block_show()
{
  var el=cur_obj.childNodes[4].childNodes[2];
  if (opacity==100)
  {
    if (new_txt=='')
    {
      return;
    }
    return;
  }
  opacity+=10;
  if (/MSIE/.test(navigator.userAgent))
    el.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ");";
  else
    el.style.opacity = opacity / 100;
  setTimeout("block_show()",100);
}
function block_hide()
{
  var el=cur_obj.childNodes[4].childNodes[2];
  if (opacity==0)
  {
    if (old_txt=='')
    {
      old_txt=cur_obj.childNodes[4].childNodes[2].innerHTML;
      el.innerHTML=new_txt;
      if (new_script!="")
        eval(new_script);
      if (document.getElementById("pwrap"))
      {
        document.getElementById("pwrap").style.height=cur_obj.childNodes[4].childNodes[2].offsetHeight-20+"px";
        block_set_slider();
      }
    }
    else
    {
      el.innerHTML=old_txt;
      new_txt='';
      new_script='';
      var obj1=block_get_prev(cur_obj);
      block_x=obj1.offsetLeft;
      block_y=obj1.offsetTop;
      var td=cur_obj.childNodes[4].childNodes[2].childNodes[0].rows[0].cells[0];
      td.style.fontSize=td.style.fontSize.substr(0,td.style.fontSize.length-2)*1-2+"px";
      setTimeout(function(obj1) {return function() {block_smalling1(obj1)}} (cur_obj),30);
      return;
    }
    block_show();
    return;
  }
  opacity-=10;
  if (/MSIE/.test(navigator.userAgent))
    el.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ");";
  else
    el.style.opacity = opacity / 100;
  setTimeout("block_hide()",50);
}
function block_show_info(txt)
{
  var els=txt.getElementsByTagName("txt");
  new_txt=ImageViewer.get_text(els[0]);
  new_script='';
  var els=txt.getElementsByTagName("script");
  if (els.length>0)
    new_script=ImageViewer.get_text(els[0]);
  opacity=100;
  block_hide();
}
function block_smalling1(obj)
{
  var el=obj.childNodes[4];
  var wt=el.offsetWidth-295;
  var ht=el.offsetHeight-160;
  var x=block_x-obj.offsetLeft;
  var y=block_y-obj.offsetTop;
  var stepw=wt/3;
  var steph=ht/3;
  var stepx=x/3;
  var stepy=y/3;
  if (steph<1)
    el.style.height="160px";
  else
    el.style.height=el.offsetHeight-steph+"px";
  obj.childNodes[3].style.height=el.style.height;
  obj.childNodes[5].style.height=el.style.height;
  if (stepw<1)
    el.style.width="295px";
  else
    el.style.width=el.offsetWidth-stepw+"px";
  obj.childNodes[1].style.width=el.style.width;
  obj.childNodes[7].style.width=el.style.width;
  if (stepx<1)
    obj.style.left=block_x+"px";
  else
    obj.style.left=obj.offsetLeft+stepx+"px";
  if (stepy<1)
    obj.style.top=block_y+"px";
  else
    obj.style.top=obj.offsetTop+stepy+"px";
  var td=el.childNodes[2].childNodes[0].rows[0].cells[0];
  var fs=td.style.fontSize.substr(0,td.style.fontSize.length-2)*1-1;
  if (fs<20)
    fs=20;
  td.style.fontSize=fs+"px";
  el.childNodes[2].style.width=el.offsetWidth-20+"px";
  el.childNodes[2].style.height=el.offsetHeight-35+"px";
  if ((td.childNodes[0]) && (td.childNodes[0].tagName=="IMG"))
  {
    var el1=td.childNodes[0];
    var ratio=el1.getAttribute("ratio");
    el1.style.height=el.childNodes[2].offsetHeight+"px";
    el1.style.width=el.childNodes[2].offsetHeight*ratio+"px";
  }
  if ((stepw<1) && (steph<1) && (stepx<1) && (stepy<1))
  {
    var obj1=block_get_prev(obj);
    obj1.parentNode.removeChild(obj1);
    obj.style.position="static";
    block_show();
    return;
  }
  setTimeout(function(obj1) {return function() {block_smalling1(obj1)}} (obj),30);
}
function block_get_prev(obj)
{
  for (var n=0;n<obj.parentNode.childNodes.length;n++)
  {
    if (obj.parentNode.childNodes[n]==obj)
      return obj.parentNode.childNodes[n-1];
  }
}
function block_make_small(obj)
{
  var dv=obj.parentNode.parentNode.parentNode;
  if (dv.childNodes[4].offsetHeight==160)
    setTimeout(function(obj1) {return function() {block_smalling(obj1)}} (dv),30);
  if (dv.childNodes[4].offsetWidth==913)
  {
    block_hide();
  }
}
function block_make_large(obj)
{
  var dv=obj.parentNode.parentNode.parentNode;
  if (dv.childNodes[4].offsetHeight==20)
    setTimeout(function(obj1) {return function() {block_mediuming(obj1)}} (dv),30);
  if (dv.childNodes[4].offsetHeight==160)
  {
    var el=document.createElement("div");
    el.className="empty_block";
    dv.parentNode.insertBefore(el,dv);
    dv.style.position="absolute";
    dv.style.top=el.offsetTop+"px";
    block_max_height=Math.ceil(block_count/3)*170+(Math.ceil(block_count/3)-1)*5;
    block_x=document.getElementById("main").offsetLeft;
    block_y=el.parentNode.offsetTop;
    var td=dv.childNodes[4].childNodes[2].childNodes[0].rows[0].cells[0];
    td.style.fontSize="20px";
    setTimeout(function(obj1) {return function() {block_larging(obj1)}} (dv),30);
  }
}
var is_dragging=false;
var slider_step, drag_y;
function block_set_slider()
{
  document.getElementById("slider_d").style.display="none";
  if (document.getElementById("page").offsetHeight>document.getElementById("pwrap").offsetHeight)
  {
    document.getElementById("slider_d").style.display="block";
    document.getElementById("slider").style.top="0px";
    slider_step=100*document.getElementById("slider_l").offsetHeight/document.getElementById("page").offsetHeight;
    if (document.getElementById("pwrap").addEventListener)
      document.getElementById("pwrap").addEventListener("DOMMouseScroll", function(event) {block_slider_wheel(event)}, false);
    document.getElementById("pwrap").onmousewheel = function(event) {block_slider_wheel(event)};
    document.onmousedown=function(event) {block_slider_mouse_down(event)};
    document.onmousemove=function(event) {block_slider_mouse_move(event)};
    document.onmouseup=function() {is_dragging=false};
    is_dragging=false;
  }
}
function block_move_slider(e,up)
{
  var el=document.getElementById("slider");
  var newval=get_top(el);
  if (up)
    newval-=slider_step;
  else
    newval+=slider_step;
  if (newval<0)
  newval=0;
  if (newval>(document.getElementById("slider_l").offsetHeight-el.offsetHeight))
    newval=document.getElementById("slider_l").offsetHeight-el.offsetHeight;
  el.style.top=newval+"px";
  block_slider_setpos(newval/(document.getElementById("slider_l").offsetHeight-el.offsetHeight));
  block_event(e);
}
function block_slider_setpos(val)
{
  document.getElementById("page").style.top=-(document.getElementById("page").offsetHeight-document.getElementById("slider_l").offsetHeight)*val+"px";
}
function block_event(event)
{
  if(event.stopPropagation) event.stopPropagation();
    else event.cancelBubble = true;
  if(event.preventDefault) event.preventDefault();
    else event.returnValue = false;
}
function block_slider_wheel(event)
{
  var wheelDelta = 0;
  if (!event)
    event = window.event;
  if (event.wheelDelta)
    wheelDelta = event.wheelDelta/120;
  else if (event.detail)
    wheelDelta = -event.detail/3;
  if (wheelDelta)
  {
    var el=document.getElementById("slider");
    newval=get_top(el)-wheelDelta*this.slider_step;
    if (newval<0)
      newval=0;
    if (newval>(document.getElementById("slider_l").offsetHeight-el.offsetHeight))
      newval=document.getElementById("slider_l").offsetHeight-el.offsetHeight;
    el.style.top=newval+"px";
    block_slider_setpos(newval/(document.getElementById("slider_l").offsetHeight-el.offsetHeight));
  }
  if (event.preventDefault)
    event.preventDefault();
  event.returnValue = false;
  block_event(event);
}
function block_slider_mouse_down(e)
{
  if ((document.all) && (!window.opera)) { if (event.button!=1) {return;};} else {if (e.button!=0){return;};};
  var tg=(document.all)?event.srcElement:e.target;
  if (tg.id=="slider")
  {
    dragy=e.clientY-tg.offsetTop;
    is_dragging=true;
    block_event(e);
    return false;
  }
}
function get_top(el)
{
  var top=el.style.top.substr(0,el.style.top.length-2);
  top=top.replace(/,/,'.')*1;
  return top;
}
function block_slider_mouse_move(e)
{
  if ((document.all) && (!window.opera)) { if (event.button!=1) {return;};} else {if (e.button!=0){return;};};
  if (!is_dragging)
    return;
  var el=document.getElementById("slider");
  var newval=e.clientY-dragy;
  newval=newval-el.offsetTop+get_top(el);
  if (newval<0)
    newval=0;
  if (newval>(document.getElementById("slider_l").offsetHeight-el.offsetHeight))
    newval=document.getElementById("slider_l").offsetHeight-el.offsetHeight;
  el.style.top=newval+"px";
  block_slider_setpos(newval/(document.getElementById("slider_l").offsetHeight-el.offsetHeight));
  block_event(e);
  return false;
}
function block_load_menu(obj,id)
{
  var dv=obj.parentNode;
  for (var k=0;k<dv.childNodes.length;k++)
    dv.childNodes[k].className="";
  obj.className="sel";
  var wrap=document.getElementById("pwrap");
  wrap.innerHTML='';
  wrap.style.background="url('/img/iviewer/iw_loading.gif') no-repeat center center";
  document.getElementById("slider_d").style.display="none";
  ConnectionManager.get("/request.php","param=2&id="+id,block_show_page);
}
function block_show_page(txt)
{
  var els=txt.getElementsByTagName("txt");
  var wrap=document.getElementById("pwrap");
  wrap.innerHTML=ImageViewer.get_text(els[0]);
  wrap.style.background="none";
  var els=txt.getElementsByTagName("script");
  if (els.length>0)
  {
    var new_script=ImageViewer.get_text(els[0]);
    if (new_script!="")
      eval(new_script);
  }
  block_set_slider();
}
