/*
  Image Zooming Utility[imgopen.js]
  Copyright(C) Daisuke SATO 2004
  e-mail: daisuke@iplab.is.tsukuba.ac.jp
*/
var def;
var init_end = false;
var set_end = false;
var isOpen = false;
var isOpenZoom = false;
var isCloseZoom = false;
var oldSrc = null;
var move_delay = 500;
/* s:initial state g:final state */
var os, og;
var cs, cg;
var ot=null, ox=0, oy=0;

function Def(delay, frame, scale, shadow, color, 
	     small, large, align, valign, margin, move, drag){
  this.delay = delay;
  this.frame = frame;
  this.scale = scale;
  this.shadow = shadow;
  this.color = color;
  this.small = small;
  this.large = large;
  this.align = align;
  this.valign = valign;
  this.margin = margin;
  this.move = move;
  this.drag = drag;

  this.toString = function(){
    var disp =  ("DE["+this.delay+"], "+
		 "FR["+this.frame+"], "+
		 "SC["+this.scale+"], "+
		 "SH["+this.shadow+"], "+
		 "CO["+this.color+"], "+
		 "SM["+this.small+"], "+
		 "LA["+this.large+"], "+
		 "AL["+this.align+"], "+
		 "VA["+this.valign+"], "+
		 "MA["+this.margin+"], "+
		 "LA["+this.move+"], "+
		 "DR["+this.drag+"]");
    return disp;
  }
}

def = new Def(30, 10, 2.5, 10, '#333333', 
	      '', '', 'center', 'middle', 30, false, false);

var movex=0, movey=0;
var oldtop = 0, oldleft = 0;
var oldx = 0, oldy = 0;

function moveinit(){
  oldtop = getScrollTop();
  oldleft = getScrollLeft();
  oldx = og.x-oldleft;
  oldy = og.y-oldtop;
}

function movestart(){
  isOpen = true;
  load_check();
  move();
}

function load_check(){
  as = document.getElementsByTagName("A");
  for(i=0; i<as.length; i++){
    var inimgs = as[i].getElementsByTagName("IMG");
    if(inimgs.length == 1){
      if(inimgs[0].complete){
      }
      else{
	inimgs[0].src = inimgs[0].src;
      }
    }
  }
}

var timerID;
function movestop(){
  isOpen = false;
  clearTimeout(timerID);
}


function move(){
  var top = getScrollTop();
  var left = getScrollLeft();
  var x =  getAlign(def.align);
  var y = getVAlign(def.valign);
  if(def.move == false){
    timerID = setTimeout('move()', move_delay);
  }
  else if(isOpen && (top != oldtop || left != oldleft || x != oldx || y != oldy)){
    sh = document.getElementById("openshadow");
    im = document.getElementById("openimg");
    cp = document.getElementById("opencaption");

    if(isDrag.indexOf("move") == -1){
      var max = 1;
      var n = 1, o = 4;
      var t = n+o;
      if(Math.abs(top - oldtop) > max){
	top = (top*n+oldtop*o)/t;
      }
      if(Math.abs(left - oldleft) > max){
	left = (left*n+oldleft*o)/t;
      }
      if(Math.abs(x - oldx) > max){
	x = (x*n+oldx*o)/t;
      }
      if(Math.abs(y - oldy) > max){
	y = (y*n+oldy*o)/t;
      }
    }
    
    setStyle(sh, x+left, y+top, null, null, null);
    setStyle(im, x+left-og.s, y+top-og.s, null, null, null);
    setStyle(cp, x+left, y+top, null, null, null);

    oldtop = top;
    oldleft = left;
    oldx = x;
    oldy = y;
    timerID = setTimeout('move()', def.delay);
  }
  else if(isOpen){
    timerID = setTimeout('move()', move_delay);
  }
}


function set(){
  var disp = "";
  for(i=0; i<arguments.length; i++){
    arg = arguments[i];
    arg = arg.replace(" ", "");
    data = arg.split("=");
    if(data.length == 2){
      if(i!=0){
	disp+= ", ";
      }
      disp = disp+data[0]+"["+data[1]+"]";
      if(data[0].indexOf("delay") != -1){def.delay = data[1];}
      if(data[0].indexOf("frame") != -1){def.frame = data[1];}
      if(data[0].indexOf("scale") != -1){def.scale = data[1];}
      if(data[0].indexOf("shadow") != -1){def.shadow = data[1];}
      if(data[0].indexOf("color") != -1){def.color = data[1];}
      if(data[0].indexOf("small") != -1){def.small = data[1];}
      if(data[0].indexOf("large") != -1){def.large = data[1];}
      if(data[0].indexOf("align") != -1){def.align = data[1].toLowerCase();}
      if(data[0].indexOf("valign") != -1){def.valign = data[1].toLowerCase();}
      if(data[0].indexOf("margin") != -1){def.margin = data[1];}
      if(data[0].indexOf("drag") != -1){
	if(data[1] == "true"){
	  if(init_end){
	    document.getElementById("openshadow").style.cursor = "move";
	  }
	  def.drag = true;
	}
	else{
	  if(init_end){
	    document.getElementById("openshadow").style.cursor = "auto";
	  }
	  def.drag = false;
	}
      }
      if(data[0].indexOf("layout") != -1){
	if(data[1] == "true"){
	  def.move = true;
	}
	else{
	  def.move = false;
	}
      }
    }
  }
}

function frame1(id){
  var fr = document.createElement("IFRAME");
  fr.id = id;
  fr.name = id;
  fr.style.position = "absolute";
  fr.style.left = "-5000px";
  fr.style.top = "-5000px";
  fr.src = "about:blank";
  document.body.appendChild(fr);
  setTimeout('frame2()', 100);
}
function frame2(){
  if(self.buffer){
    self.buffer.name = "buffer";
  }
  else{
    setTimeout('frame2()', 100);
  }
}

function init(){
  if(init_end != true){
    frame1("buffer");
    image1("dummy_img", 100);

    table1("closeshadow", 101);
    image1("closeimg", 102);

    table1("openshadow", 103);
    image1("openimg", 104);
    table2("opencaption", 105);
    if(document.all){
      document.body.onmousemove = dummy_mousemove;
      document.body.onmouseup = dummy_mouseup;
    }
    else{
      window.captureEvents(Event.MouseMove);
      document.body.onmousemove = mousemove;
      window.captureEvents(Event.MouseUp);
      document.body.onmouseup = mouseup;
    }
  }
  init_end = true;
}

function link_ok(href){
  if(href.toLowerCase().match(".jpg$") ||
     href.toLowerCase().match(".jpeg$")||
     href.toLowerCase().match(".bmp$")||
     href.toLowerCase().match(".gif$") ||
     href.toLowerCase().match(".png$") ){
    if(!href.match("\\?")){
      return true;
    }
  }
  return false;
}

function get_doblog_link(href){
    var list = href.split("'");
    return list[1];
}

function link_doblog(href){
  if(href.toLowerCase().match("javascript:mm_open\\(")){
    var list = href.split("'");
    if(link_ok(list[1])){
      return true;
    }
  }
  return false;
}

var openBlank = false;
var old_url="about:blank";
var waitTarget = null;
function loop(){
  try{
    var new_url = self.buffer.location.href;
    
    if(new_url.indexOf("about:blank") != -1){
    }
    else{
      if(new_url.indexOf(old_url) == -1){
	waitTarget = ot;
	waitTarget.style.cursor = "wait";
	waitFor(new_url);
	old_url = new_url;
      }
      else if(openBlank){
	openBlank = false;
	imgclose(null);
      }
    }
    setTimeout('loop()', 50);
  }
  catch(e){
    window.status = "Cannot access to the image.";
  }
}
function getBase(url){
  //url.match("^(.*?)//(.*?)(/.*?|)$");
  //return RegExp.$1+"//"+RegExp.$2;
	return url;
}


var as;
function setEvent(){
  window.status = "setEvent";
  var oneMore = false;
  var selfBase = getBase(self.location.href);
  if(set_end != true){
    as = document.getElementsByTagName("A");
    for(i=0; i<as.length; i++){
      if(as[i].id == "no"){
	continue;
      }
      var inimgs = as[i].getElementsByTagName("IMG");
      if(inimgs.length == 1 && inimgs[0].alt.indexOf("::") == -1){
	if(!inimgs[0].complete){
	  inimgs[0].src = inimgs[0].src;
	}
	if(link_ok(as[i].href)){// PC Watch, AV Watch
	  as[i].name += "::"+as[i].target;
	  as[i].name += "::"+inimgs[0].style.borderWidth;
	  as[i].name += "::"+as[i].href;
	  as[i].target = "_self";
	  as[i].href = "javascript:aimgopen22('"+as[i].href+"');";
	}
	else if(link_doblog(as[i].href)){
	  as[i].name += "::"+as[i].target;
	  as[i].name += "::"+inimgs[0].style.borderWidth;
	  as[i].name += "::"+as[i].href;
	  as[i].target = "_self";
	  as[i].href = "javascript:aimgopen22('"+get_doblog_link(as[i].href)+"');";
	}
	/*	else if(selfBase.indexOf(getBase(as[i].href)) != -1 &&
		!as[i].href.match("javascript")){
	  as[i].name += "::"+as[i].target;
	  as[i].name += "::"+inimgs[0].style.borderWidth;
	  as[i].name += "::"+as[i].href;
	  as[i].target = "_self";
	  as[i].target = "buffer";
	  }*/
	else{
	  continue;
	}
	inimgs[0].style.borderWidth = 0;
	inimgs[0].style.borderStyle = "dashed";
	set_getmouse(as[i]);
      }
      else{
	if(inimgs.length==0 && link_ok(as[i].href)){
	  as[i].name = as[i].target+"::"+as[i].href;
	  as[i].target = "";
	  as[i].href = "javascript:aimgopen22('"+as[i].href+"');";
	  as[i].style.backgroundColor = "yellow";
	  set_getmouse(as[i]);
	}
      }
    }
  }
  set_end = true;
  window.status = "";
}

function set_getmouse(el){
  if(document.all){
    el.onmouseover = dummy_getmouse;
    el.onmousemove = dummy_getmouse;
  }
  else{
    window.captureEvents(Event.MOUSEOVER);
    el.onmouseover = getmouse;
    window.captureEvents(Event.MOUSEMOVE);
    el.onmousemove = getmouse;
  }
}
function dummy_getmouse(){
  getmouse(event);
}
var loop_start = false;
function getmouse(event){
  if(loop_start != true){
    loop_start = true;
    loop();
  }
  ot = getTarget(event);
  ox = getX(event);
  oy = getY(event);
}

function removeEvent(){
  if(set_end == true){
    var as = document.getElementsByTagName("A");
    for(i=as.length-1; i>=0; i--){
      var inimgs = as[i].getElementsByTagName("IMG");
      if(inimgs.length == 1 && as[i].name.indexOf("::") != -1){
	var spl = as[i].name.split("::");
	inimgs[0].style.borderWidth = spl[spl.length-2];
	inimgs[0].style.borderStyle = "solid";
	as[i].target = spl[spl.length-3];
	as[i].href = spl[spl.length-1];
	as[i].name = spl[0];
      }
      else if(as[i].href.indexOf("javascript:aimgopen") != -1){
	var spl = as[i].name.split("::");
	as[i].target = spl[0];
	as[i].href = spl[1];
	as[i].name = "";
	as[i].style.backgroundColor = "white";
      }
    }
  }
  set_end = false;
}

function dummy_imgopen(){
  imgopen(event);
}

function image1(id, z){
  var iim = document.createElement('IMG');
  iim.setAttribute("id", id);
  iim.style.cursor = "pointer";
  iim.style.position = "absolute";
  iim.style.zIndex = z;
  iim.style.backgroundColor = "white";
  setStyle(iim, -5000, -5000, 0, "solid", "white");

  if(document.all){
    iim.onclick = dummy_imgclose;
    iim.onmouseup = dummy_mouseup;
  }
  else{
    window.captureEvents(Event.CLICK);
    iim.onclick = imgclose;
    window.captureEvents(Event.MouseUp);
    iim.onmouseup = mouseup;
  }
  document.body.appendChild(iim);
}
function dummy_imgclose(){
  imgclose(event);
}
function dummy_mousedown(){
  mousedown(event);
}
function dummy_mouseup(){
  mouseup(event);
}
function dummy_mousemove(){
  mousemove(event);
}
function dummy_mouseout(){
  mouseout(event);
}

var isDrag = "stop";
var sx, sy;
var timerID2;
function mousedown(event){
  if(def.drag){
    sx = getX(event);
    sy = getY(event);
    if(isDrag.indexOf("stop") != -1){
      timerID2 = setTimeout('mousedown2()', 0);
    }
    else if(isDrag.indexOf("move") != -1){
      isDrag = "end";
    }
  }
}
function mousedown2(){
  isDrag = "move";
  move_delay = 30;
  setStyle(document.getElementById("openimg"), null, null,
	   1, "dashed", "red");
}
function mouseup(event){
  if(def.drag){
    if(isDrag.indexOf("move") != -1){
      if(getX(event) < 0 || getY(event) < 0){
	movex = movey = 0;
      }
      isDrag = "stop";
      setStyle(document.getElementById("openimg"), null, null,
	       1, "solid", "black");
      move_delay = 500;
      //window.status = "stop";
    }
  }
}
function mouseout(event){
  if(def.drag){
    alert("out");
    mouseup(event);
  }
}
var iv=0;
function mousemove(event){
  if(def.drag){
    if(isDrag.indexOf("move") != -1){
      //window.status = getX(event)+", "+getY(event)+", "+iv;
      iv++;
      if(document.selection){
	document.selection.clear();
      }
      var x = getX(event);
      var y = getY(event);
      movex += x-sx;
      movey += y-sy;
      sx = x;
      sy = y;
    }
    if(isDrag.indexOf("stop") != -1){
      clearTimeout(timerID2);
    }
  }
}

function processDrag(){
  if(isDrag.indexOf("move") != -1){
    return true;
  }
  else if(isDrag.indexOf("end") != -1){
    isDrag = "stop";
    setStyle(document.getElementById("openimg"), null, null,
	     1, "solid", "black");
    move_delay = 500;
    return true;
  }
  return false;
}

function table1(id, z){
  var table = document.createElement('TABLE');
  var tbody = document.createElement('TBODY');
  var tr = document.createElement('TR');
  var td = document.createElement('TD');
  var t =  document.createTextNode(" ");
  table.setAttribute("cellpadding", "0");
  table.setAttribute("cellspacing", "0");
  table.setAttribute("width", "0");
  table.setAttribute("id", id);
  td.setAttribute("id", id+"td");
  table.style.position = "absolute";
  setStyle(table, 0, 0, 0, "solid", "white");
  table.style.backgroundColor = "white";
  table.style.zIndex = z;
  if(document.all){
    table.style.filter = "Alpha(opacity=70)";
  }
  if(def.drag){
    table.style.cursor = "move";
  }
  if(document.all){
    table.onmousedown = dummy_mousedown;
    table.onmouseup = dummy_mouseup;
  }
  else{
    window.captureEvents(Event.MouseDown);
    table.onmousedown = mousedown;
    window.captureEvents(Event.MouseUp);
    table.onmouseup = mouseup;
  }

  td.appendChild(t);
  tr.appendChild(td);
  tbody.appendChild(tr);
  table.appendChild(tbody);

  document.body.appendChild(table);
}

function table2(id, z){
  var table = document.createElement('TABLE');
  var tbody = document.createElement('TBODY');
  var tr = document.createElement('TR');
  var td = document.createElement('TD');
  var t =  document.createTextNode(" ");
  table.setAttribute("cellpadding", "1");
  table.setAttribute("cellspacing", "0");
  table.setAttribute("width", "0");
  table.setAttribute("id", id);
  table.style.position = "absolute";
  setStyle(table, -100, -100, 1, "solid", "white");
  table.style.backgroundColor = "white";
  table.style.zIndex = z;
  if(document.all){
    table.style.filter = "Alpha(opacity=90)";
  }

  td.style.fontSize = "x-small";
  td.setAttribute("id", id+"title");
  td.setAttribute("width", "0");
  td.setAttribute("bgcolor", "white");

  td.appendChild(t);
  tr.appendChild(td);
  tbody.appendChild(tr);
  table.appendChild(tbody);

  document.body.appendChild(table);

}


function Param(x, y, w, h, s, src){
  this.x = x;
  this.y = y;
  this.w = w;
  this.h = h;
  this.s = s;
  this.src = src;
  this.alt;
  this.animation = function(s, g, t, n){
    x = s.x + (g.x-s.x)*n/t;
    y = s.y + (g.y-s.y)*n/t;
    w = s.w + (g.w-s.w)*n/t;
    h = s.h + (g.h-s.h)*n/t;
    s = s.s + (g.s-s.s)*n/t;
    return new Param(x, y, w, h, s);
  }
  this.toString = function(){
    return "x="+this.x+", y="+this.y+", w="+this.w+", h="+this.h+", bw="+this.s;
  }
}


function imgclose(event){
  if(isCloseZoom || isOpenZoom){
    return;
  }
  isCloseZoom = true;

  imgclose2(os.x, os.y);
}

function imgclose2(x, y){
  movestop();
  //openBlank = false;
  self.buffer.location.replace("about:blank");
  old_url = "about:blank";

  oldSrc = null;

  im = document.getElementById("openimg");

  src = im.src.replace(def.large, def.small);

  cs = new Param(oldx+oldleft, oldy+oldtop, im.width, im.height,
		 def.shadow, src);
  cg = new Param(x, y, 1, 1, 0, src);
  
  closezoom(0, def.delay);
}

function imgopen(event){
  if(isOpenZoom){ return; }
  isOpenZoom = true;
  imgopen2(getTarget(event), getX(event), getY(event));
}

function imgopen2(el, x, y){
  init();

  if(el == oldSrc){
    isOpenZoom = false;
    return imgclose2(os.x, os.y);
  }
  else if(oldSrc != null){
    isOpenZoom = false;
    imgclose2(os.x, os.y);
  }
  oldSrc = el;
  
  //alert(el.src+", "+el.width+", "+el.height);

  os = new Param(x+getScrollLeft(), y+getScrollTop(), 1, 1, 0, el.src);
  og = new Param();
  og.w = el.width*def.scale;
  og.h = el.height*def.scale;
  og = new Param(getAlign(def.align)+getScrollLeft(), 
		 getVAlign(def.valign)+getScrollTop(),
		 og.w, og.h, def.shadow,
		 el.src.replace(def.small, def.large));

  og.alt = el.alt;
  moveinit();

  openzoom(0, def.delay);
}

function dummy_aimgopen(){
  aimgopen(event);
}

function aimgopen(event){
  if(isOpenZoom){ return; }
  isOpenZoom = true;
  //alert(event);
  el = getTarget(event);
  spl = el.alt.split("::");
  
  //alert(spl[spl.length-1]);
  aimgopen2(el, spl[spl.length-1], getX(event), getY(event));
}

var times = 0;
function aimgopen24(){
  var doc = window.buffer.document;
  var imgs = doc.getElementsByTagName("IMG");
  var max = 0;
  var url = "";
  //window.status = imgs.length;
  for(i=0; i<imgs.length; i++){
    if(max < imgs[i].width*imgs[i].height){
      max = imgs[i].width*imgs[i].height;
      url = imgs[i].src;
    }
  }
  times++;
  if(max < 50000 && times < 33){
    aimgopen24id = setTimeout('aimgopen24()', 300);
    return;
  }
  else if(times >= 33){
    waitTarget.style.cursor = "auto";
    self.buffer.location.href = "about:blank";
    return;
  }

  //alert(max+", "+times);
  times = 0;
  ot = waitTarget;

  try{
    if(url.indexOf("http://proxy.ymdb.yahoofs.jp/") == -1){
      waitTarget.href = "javascript:aimgopen22('"+url+"');";
      waitTarget.target = ""; 
      waitTarget.parentNode.href = "javascript:aimgopen22('"+url+"');";
      waitTarget.parentNode.target = "";
    }
  }
  catch(e){
    if(url.indexOf("http://proxy.ymdb.yahoofs.jp/") == -1){
      waitTarget.parentNode.href = "javascript:aimgopen22('"+url+"');";
      waitTarget.parentNode.target = "";
    }
  }
  openBlank = true;
  
  isOpenZoom = false;
  aimgopen22(url);
}

function aimgopen23(url){
  if(isOpenZoom){ return; }
  isOpenZoom = true;
  var ifrWin = self.buffer;
  var imgs = self.buffer.document.images;
  for(i=imgs.length-1; i>=0; i--){
    imgs[i].parentNode.removeChild(imgs[i]);
  }
  //window.open(url, "buffer");
  self.buffer.location.replace(url);
  waitFor(url);
}
/*
function aimgopen23(url){
  var ifrWin = self.buffer;
  var html = '';
  html += '<HTML>';
  html += '<BODY ONLOAD="parent.aimgopen24();">';
  html += '<IFRAME SRC="' + url + '">';
  html += '<\/IFRAME>';
  html += '<\/BODY>';
  html += '<\/HTML>';
  ifrWin.document.open();
  ifrWin.document.write(html);
  ifrWin.document.close();
  }*/


var aimgopen24id;
function waitFor(url){
  try{
    var imgs = self.buffer.document.getElementsByTagName("IMG");
    if(imgs.length == 0){
      setTimeout("waitFor('+url+')", 300);
      return;
    }
  }
  catch(e){
    setTimeout("waitFor('+url+')", 300);
  }
  clearTimeout(aimgopen24id);
  aimgopen24();
}

function aimgopen22(url){
  if(isOpenZoom){ return; }
  isOpenZoom = true;
  ot.style.cursor = "wait";
  waitTarget = ot;
  aimgopen2(ot, url, ox, oy);
}

function aimgopen2(el, url, x, y){
  init();

  if(el != null && el == oldSrc){
    isOpenZoom = false;
    ot.style.cursor = "auto";
    return imgclose2(os.x, os.y);
  }
  else if(oldSrc != null){
    isOpenZoom = false;
    imgclose2(os.x, os.y);
  }
  oldSrc = el;
  
  if(el.src){
    if(navigator.userAgent.indexOf("Safari") != -1 ||
       document.addEventListener){
      os = new Param(x, y, 1, 1, 0, url);
    }
    else{
      os = new Param(x+getScrollLeft(), y+getScrollTop(), 1, 1, 0, url);
      //os = new Param(x+getScrollLeft(), y+getScrollTop(), 1, 1, 0, el.src);
    }
  }
  else{
    if(navigator.userAgent.indexOf("Safari") != -1 ||
       document.addEventListener){
      os = new Param(x, y, 1, 1, 0, url);
    }
    else{
      os = new Param(x+getScrollLeft(), y+getScrollTop(), 1, 1, 0, url);
    }
  }
  
  var tt = document.getElementById("dummy_img");
  document.body.removeChild(tt);
  image1("dummy_img", 0);
  tt = document.getElementById("dummy_img");
  tt.src = url;
  if(el.alt && el.alt.length > 0){
    not_found_count = 0;
    aimgopen3(url, el.alt.split("::")[0]);
  }
  else{
    spl = url.split("/");
    not_found_count = 0;
    aimgopen3(url, spl[spl.length-1]);
  }
}

var not_found_count = 0;
function aimgopen3(url, alt){
  var tt = document.getElementById("dummy_img");
  if(tt.complete){
    og = new Param();
    og.w = tt.width;
    og.h = tt.height;
    waitTarget.style.cursor = "auto";

    var maxw = getInnerWidth()*0.98;
    var com = " ("+tt.width+"x"+tt.height+")";
    if(og.w > maxw){
      og.h = Math.round(og.h/(og.w/maxw));
      og.w = Math.round(og.w/(og.w/maxw));
      com = " (Fit to window ["+og.w+"x"+og.h+"] "+tt.width+"x"+tt.height+")";
    }
    var maxh = getInnerHeight()*0.98;
    if(og.h > maxh){
      og.w = Math.round(og.w/(og.h/maxh));
      og.h = Math.round(og.h/(og.h/maxh));
      com = " (Fit to window ["+og.w+"x"+og.h+"] "+tt.width+"x"+tt.height+")";
    }
    alt += com;

    og = new Param(getAlign(def.align)+getScrollLeft(), 
		   getVAlign(def.valign)+getScrollTop(),
		   og.w, og.h, def.shadow,
		   url);
    og.alt = alt;
    moveinit();
    openzoom(0, def.delay);
  }
  else{
    not_found_count++;
    if(not_found_count > 2000){
      alert("File Not Found (Timeout 20sec)");
      ot.style.cursor = "auto";
      isOpenZoom = false;
    }
    else{
      setTimeout("aimgopen3('"+url+"', '"+alt+"')", 10);
    }
  }
}

function copyStyle(e1, e2){
  setStyle(e1, e2.style.left, e2.style.top, 
	   e2.style.borderWidth, e2.style.borderStyle, e2.style.borderColor,
	   e2.style.backgroundColor);
  e1.style.backgroundColor = e2.style.backgroundColor;
  setSize(e1, e2.width, e2.height);
}

function closezoom(frame, delay){
  sh = document.getElementById("closeshadow");
  sh2 = document.getElementById("closeshadowtd");
  im = document.getElementById("closeimg");

  if(frame == 0){
    osh = document.getElementById("openshadow");
    osh2 = document.getElementById("openshadowtd");
    oim = document.getElementById("openimg");
    ocp = document.getElementById("opencaption");
    ocp2 = document.getElementById("opencaptiontitle");
    
    copyStyle(sh, osh);
    copyStyle(sh2, osh2);
    copyStyle(im, oim);

    setStyle(osh, -100, -100, null, null, null, "white");
    
    if(isOpenZoom != true){
      osh2.childNodes[0].nodeValue = " ";
      setSize(osh, 1, 1);
    }
    setStyle(oim, -100, -100, 0, "solid", "white");
    setSize(oim, 0, 0);

    setStyle(ocp, -100, -100, 0, "solid", "white");
    ocp2.childNodes[0].nodeValue = " ";

    im.lowsrc = cs.src;
    im.src = cs.src;
    setStyle(im, cs.x, cs.y, 1, "solid", "black");
    setStyle(sh, cs.x, cs.y, null, null, def.color, def.color);
  }
  if(frame == 1){
    if(navigator.userAgent.indexOf("MSIE") == -1 ||
       navigator.userAgent.indexOf("Opera") != -1){
      sh2.childNodes[0].nodeValue = ".";
    }
  }

  next = frame-0+1;
  if(frame <= def.frame-0){
    a = cs.animation(cs, cg, def.frame, frame);
    setSize(im, a.w, a.h);
    setStyle(im, a.x, a.y);

    if(navigator.userAgent.indexOf("MSIE") != -1 &&
       navigator.userAgent.indexOf("Opera") == -1){
      sh.height = a.h+1;
      setStyle(sh, a.x, a.y);
    }
    else{
      var bh;
      bh = a.h/2 - 10;
      if(bh < 0){
	bh = 0;
      }
      setStyle(sh, a.x+a.s, a.y+a.s, bh+" "+0+" "+bh+" "+0);
    }
    sh.width = a.w+1;

    if(frame == 0){
      setTimeout("closezoom('"+next+"','"+delay+"')", delay);
    }
    else{
      setTimeout("closezoom('"+next+"','"+delay+"')", delay);
    }
  }
  else{
    setStyle(sh, -100, -100, null, null, "white", "white");
    setStyle(sh2, null, null, null, null, "white", "white");

    sh2.childNodes[0].nodeValue = " ";
    setStyle(im, -100, -100, 0, "solid", "white");
    setSize(im, 0, 0);

    isCloseZoom = false;
  }
}


function openzoom(frame, delay){
  sh = document.getElementById("openshadow");
  sh2 = document.getElementById("openshadowtd");
  cim = document.getElementById("closeimg");
  im = document.getElementById("openimg");
  cp = document.getElementById("opencaption");
  cp2 = document.getElementById("opencaptiontitle");

  if(frame == 0){
    im.lowsrc = os.src;
    im.src = os.src;

    setStyle(im, os.x, os.y, 1, "solid", "black");
  }
  if(frame == 1){
    if(navigator.userAgent.indexOf("MSIE") == -1 ||
       navigator.userAgent.indexOf("Opera") != -1){
      sh2.childNodes[0].nodeValue = ".";
    }
  }

  next = frame-0+1;
  if(frame <= def.frame-0){
    a = os.animation(os, og, def.frame, frame);
    setSize(im, a.w, a.h);
    setStyle(im, a.x, a.y);

    sh.width = a.w;
    if(navigator.userAgent.indexOf("MSIE") != -1 &&
       navigator.userAgent.indexOf("Opera") == -1){
      sh.height = a.h;
      setStyle(sh, a.x+a.s, a.y+a.s, null, null, def.color, def.color);
    }
    else{
      var bh;
      bh = a.h/2 - 10;
      if(bh < 0){
	bh = 0;
      }
      setStyle(sh, a.x+a.s, a.y+a.s, bh+" "+0+" "+bh+" "+0, null, def.color, def.color);
    }
	
    if(frame == 0){
      setTimeout("openzoom('"+next+"','"+delay+"')", delay);
    }
    else{
      setTimeout("openzoom('"+next+"','"+delay+"')", delay);
    }
  }
  else{
    movestart();
    cim.lowsrc = os.src;
    cim.src = os.src;
    setStyle(cp, og.x+2, og.y+2, 1, "solid", "black");
    cp2.childNodes[0].nodeValue = unescape(og.alt);
    im.src = og.src;
    isOpenZoom = false;
  }
}

/******************************************************************
Utility
******************************************************************/
function setStyle(el, x, y, w, s, c, b){
  //window.status = x+", "+y;
  if(x != null && x){if(document.all){el.style.left = x;}else{el.style.left = x+"px";}}
  if(y != null && y){if(document.all){el.style.top = y;}else{el.style.top = y+"px";}}
  if(w != null && w){if(document.all){el.style.borderWidth = w;}else{el.style.borderWidth = w+"px";}}
  if(s != null && s){el.style.borderStyle = s;}
  if(c != null && c){el.style.borderColor = c;}
  if(b != null && b){el.style.backgroundColor = b;}
}

function setSize(el, w, h){
  el.width = w;
  el.height = h;
}


/******************************************************************
Cross Browser
******************************************************************/
function getTarget(e){
  var el = null;
  if(e.target){
    el = e.target;
  }
  else if(e.srcElement){
    el = e.srcElement;
  }
  //alert(el.src);
  return el;
}
function getX(e){
  var x=0;
  if(e.pageX){ x = e.pageX; }
  else if(e.clientX){ x = e.clientX; }
  return x;
}
function getY(e){
  var y=0;
  if(e.pageY){ y = e.pageY; }
  else if(e.clientY){ y = e.clientY; }
  return y;
}
function getScrollLeft(){
  if(self.scrollX) return self.scrollX;
  if(self.pageXOffset) return self.pageXOffset;
  if(document.documentElement && document.documentElement.scrollLeft){
   return document.documentElement.scrollLeft;
  }
  else if(document.body && document.body.scrollLeft){
   return document.body.scrollLeft;
  }
  return 0;
}
function getScrollTop(){
  if(self.scrollY) return self.scrollY;
  if(self.pageYOffset) return self.pageYOffset;
  if(document.documentElement && document.documentElement.scrollTop){
   return document.documentElement.scrollTop;
  }
  else if(document.body && document.body.scrollTop){
   return document.body.scrollTop;
  }
  return 0;
}
function getInnerWidth(){
  if(self.innerWidth) return self.innerWidth;
  if(document.documentElement && document.documentElement.clientWidth){
   return document.documentElement.clientWidth;
  }
  else if(document.body && document.body.clientWidth){
   return document.body.clientWidth;
  }
  return 0;
}
function getInnerHeight(){
  if(self.innerHeight) return self.innerHeight;
  if(document.documentElement && document.documentElement.clientHeight){
   return document.documentElement.clientHeight;
  }
  else if(document.body && document.body.clientHeight){
   return document.body.clientHeight;
  }
  return 0;
}

function getVAlign(a){
  var y;
  if(a.indexOf("top") != -1){
    y = def.margin;
  }
  else if(a.indexOf("bottom") != -1){
    y = (getInnerHeight()-og.h)-def.margin;
  }
  else{
    y = (getInnerHeight()-og.h)/2;
  }
  y = y-0+movey;
  if(y < 0){
    y = 0;
  }
  else if(y > getInnerHeight()-og.h){
    y = getInnerHeight()-og.h;
  }
  return y;
}

function getAlign(a){
  var x;
  if(a.indexOf("left") != -1){
    x = def.margin;
  }
  else if(a.indexOf("right") != -1){
    x = (getInnerWidth()-og.w)-def.margin;
  }
  else{
    x = (getInnerWidth()-og.w)/2;
  }
  x = x-0+movex;
  if(x < 0){
    x = 0;
  }
  else if(x > getInnerWidth()-og.w){
    x = getInnerWidth()-og.w;
  }
  return x;
}


function dummy_set(){
  if(this.set){
    this.set();
    if(set_end){
      //var ifrms = self.document.getElementsByTagName("IFRAME");
      //for(i=0;i<ifrms.length;i++){
      //if(ifrms[i].name.indexOf("buffer") == -1)
      //ifrms[i].style.visibility = "visible";
      //}
      //var selects = self.document.getElementsByTagName("SELECT");
      //for(i=0;i<selects.length;i++){
      //selects[i].style.visibility = "visible";
      //}
      removeEvent();
    }
    else{

      //var ifrms = self.document.getElementsByTagName("IFRAME");
      //for(i=0;i<ifrms.length;i++){
      //if(ifrms[i].name.indexOf("buffer") == -1)
      //ifrms[i].style.visibility = "hidden";
	//ifrms[i].style.filter = "Alpha(opacity=40)";
      //}
      //var selects = self.document.getElementsByTagName("SELECT");
      //for(i=0;i<selects.length;i++){
      //selects[i].style.visibility = "hidden";
      //}
      setEvent();
      init();
    }
  }
  else{
    setTimeout('dummy_set()', 10);
  }
}
document.onload = dummy_set;
window.onload = dummy_set;

