
// _bro: 1=NN6+, 2=NN4, 3=IE, 4=Opera, 0=others
_bro=(window.opera?4:(document.all?3:(document.getElementById?1:(document.layers?2:0))));
// _ie5: true=IE5+
_ie5=(navigator.appName.indexOf('Microsoft Internet Explorer')>=0 && document.getElementById)?true:false;
// _op6: true=Opera 6
_op6=window.opera&&!document.documentElement;
// _mac : true = macintosh, false = other os
_mac=navigator.userAgent.indexOf('Mac')>=0;
if(_op6) window.location.replace('opera_d08.htm');
//=======================================================================

function getDivFromName(nm){
  if(document.getElementById) return document.getElementById(nm); 
  if(document.all) return document.all(nm); 
  if(document.layers){ 
    var s='';
    for(var i=1; i<arguments.length; i++)
      s+='document.layers.'+arguments[i]+'.';
    return eval(s+'document.layers.'+nm);
  }
  return null;
}

function getDivLeft(div){
  if(typeof window.crypto!="undefined" &&
     typeof window.getComputedStyle!="undefined"){ 
    return parseInt(div.style.left);
  }
  else 
   return document.layers?
     div.left:(div.offsetLeft||parseInt(div.style.left)||div.style.pixelLeft||0);
}

function getDivTop(div){
  if(typeof window.crypto!="undefined" &&
     typeof window.getComputedStyle!="undefined"){ 
    return parseInt(div.style.top);
  }
  else 
   return document.layers?
     div.top:(div.offsetTop||parseInt(div.style.top)||div.style.pixelTop||0);
}

function moveDivTo(div,left,top){
  if(document.layers){ div.moveTo(left,top); return; } 
  if(typeof div.style.left!="undefined"&& typeof div.style.left=="string"){ 
    div.style.left=left+'px';
    div.style.top =top +'px';
  }
  if(typeof div.style.pixelLeft!="undefined"){ 
    div.style.pixelLeft=left;
    div.style.pixelTop =top;
  }
}

function initDivSize(div){
  if(document.layers) return;
  if(typeof div.style.width!="undefined"&& typeof div.style.width=="string"){
   div.style.width =div.offsetWidth +'px';
   div.style.height=div.offsetHeight+'px';
  }
  else if(typeof div.style.pixelWidth!="undefined"){ 
   div.style.pixelWidth =div.offsetWidth;
   div.style.pixelHeight=div.offsetHeight;
  }
}

function getDivWidth (div){ 
  return document.layers?
     div.clip.width:(div.offsetWidth||div.style.pixelWidth||0);
}

function getDivHeight(div){
  return document.layers?
     div.clip.height:(div.offsetHeight||div.style.pixelHeight||0);;
}

function setDivVisibility(div,visible){
  (div.style||div).visibility=(visible)?
   ((window.opera && !document.documentElement)?'visible':'inherit'):'hidden';
}

function setDivBackgroundColor(div,color){
  if(document.layers){ 
   div.bgColor=(color=='transparent')?null:color;
  }
  else if(typeof div.style.backgroundColor!="undefined"){ 
   div.style.backgroundColor=(color==null)?'transparent':color;
  }
}

function getEventPageX(e){
  if(!e) var e = window.event;
  if(window.opera){ // Opera
   return (document.documentElement?window.pageXOffset:0)+e.clientX;
  } 
  else if(e.pageX) return e.pageX; // Mozilla, NN4, Safari
  else if(e.clientX){ // IE, others
   var sl=0;
   if(document.documentElement && document.documentElement.scrollLeft)
    sl=document.documentElement.scrollLeft;
   else if(document.body && document.body.scrollLeft)
    sl=document.body.scrollLeft;
   else if(window.scrollX||window.pageXOffset) 
    sl=(window.scrollX||window.pageXOffset);
   return sl+e.clientX;         
  }
  return 0;
}

function getEventPageY(e){
  if(!e) var e = window.event;
  if(window.opera){ // Opera
   return (document.documentElement?window.pageYOffset:0)+e.clientY;
  } 
  else if(e.pageY) return e.pageY; // Mozilla, NN4, Safari
  else if(e.clientY){ // IE, others
   var st=0;
   if(document.documentElement && document.documentElement.scrollTop)
    st=document.documentElement.scrollTop;
   else if(document.body && document.body.scrollTop)
    st=document.body.scrollTop;
   else if(window.scrollY||window.pageYOffset)
    st=(window.scrollY||window.pageYOffset);
   return st+e.clientY;         
  }
  return 0;
}

function setDivClip(div,top,right,bottom,left){
  if(document.layers){ 
     div.clip.top   =top;   div.clip.right=right;
     div.clip.bottom=bottom;div.clip.left =left;
  }
  else if(typeof div.style.clip!="undefined"){ 
     div.style.clip=
        'rect('+top+'px '+right+'px '+bottom+'px '+left+'px)';
  }
}


function addClickHandler(grabObj){

 var div=grabObj;

 if(_bro==1){
   div.addEventListener('click',Click,true);
   document.addEventListener('click',wipeStart,true);
 }
 else if(_bro==2){

   div.captureEvents(Event.MOUSEDOWN);
   div.onmousedown=Click;
   document.captureEvents(Event.CLICK|Event.MOUSEUP);
   document.onclick=wipeStart;
   document.onmouseup=wipeStart; /* NN4の clickイベントに関する問題の対策。*/

 }
 else{    

//   div.onclick=Click;
//   document.onclick=wipeStart;
   document.onclick=Click;

 }

}

function Wipe(nm,div,color,step,interval){
  this.div=div;
  this.name=nm;
  initDivSize(this.div);
  this.w=getDivWidth(this.div); this.h=getDivHeight(this.div);
  this.st=this.h/2; this.sr=this.w/2; this.sb=this.h/2; this.sl=this.w/2; 
  this.et=0; this.er=this.w; this.eb=this.h; this.el=0;
  this.step=step;
  this.t=Math.abs((this.st-this.et)/this.step);   
  this.r=Math.abs((this.sr-this.er)/this.step);
  this.b=Math.abs((this.sb-this.eb)/this.step); 
  this.l=Math.abs((this.sl-this.el)/this.step);
  this.tid=null;
  this.interval=interval;
  this.opened=false;
  this.closed=true;
  setDivClip(this.div,this.h/2,this.w/2,this.h/2,this.w/2);  
  if(!window.opera) setDivBackgroundColor(this.div,color);
  /* for Opera 7+ bug fix
     Opera 7+のクリップ操作に関するバグ対策。     
     elements=div.getElementsByTagName('要素名')で、div要素に含まれる
     要素の配列を返します。
     配列の個々の要素にアクセスするには
     div.getElementsByTagName('要素名')[index値]か
     div.getElementsByTagName('要素名').item(index値)でアクセスします。*/        
  else{
   this.div.getElementsByTagName('div')[0].style.backgroundColor=
   (color==null)?'transparent':color;
  }
  setDivVisibility(this.div,true);
  addClickHandler(this.div);
  return this;
}

Wipe.prototype.cancel = function(){
  if(this.tid){ clearTimeout(this.tid); this.tid=null; }
} 

Wipe.prototype.openLayer = function(){

  if(!this.opened) this.opened=true; 
  if(this.st>this.et) this.st-=this.t; if(this.sr<this.er) this.sr+=this.r;
  if(this.sb<this.eb) this.sb+=this.b; if(this.sl>this.el) this.sl-=this.l;     
  setDivClip(this.div,this.st,this.sr,this.sb,this.sl); 
  if((this.st<=this.et)&&(this.sr>=this.er)&&(this.sb>=this.eb)&&(this.sl<=this.el)){
    setDivClip(this.div,0,this.w,this.h,0);
    if(this.tid){ clearTimeout(this.tid); this.tid=null; }
    this.closed=false;
  }
  else this.tid=setTimeout(this.name+'.openLayer()',this.interval);          

}

Wipe.prototype.closeLayer = function(){
  if(!this.closed) this.closed=true;
  this.st+=this.t; this.sr-=this.r; this.sb-=this.b; this.sl+=this.l; 
  setDivClip(this.div,this.st,this.sr,this.sb,this.sl);    
  if((this.st>this.div.downY)&&(this.sr<=this.div.downX)&&(this.sb<=this.div.downY)&&
(this.sl>=this.div.downX)){
   setDivClip(this.div,this.h/2,this.w/2,this.h/2,this.w/2);
   if(this.tid){ clearTimeout(this.tid); this.tid=null; }         
   this.st=this.h/2; this.sr=this.w/2; this.sb=this.h/2; this.sl=this.w/2; 
   this.t=Math.abs((this.st-this.et)/this.step);    
   this.r=Math.abs((this.sr-this.er)/this.step);
   this.b=Math.abs((this.sb-this.eb)/this.step);
   this.l=Math.abs((this.sl-this.el)/this.step);
   this.opened=false;
  }
  else this.tid=setTimeout(this.name+'.closeLayer()',this.interval);
}

function wipeStart(e){

  if(!wipe||wipe.opened){
     return;
  }else{
//   moveDivTo(wipe.div,getEventPageX(e)-wipe.w/2,getEventPageY(e)-wipe.h/2);
     moveDivTo(wipe.div,getEventPageX(e) + 25,getEventPageY(e) + 18);
     wipe.openLayer(); 
  }

}

function wipe2Start(e){

  if(!wipe2||wipe2.opened){
     return;
  }else{
//   moveDivTo(wipe.div,getEventPageX(e)-wipe.w/2,getEventPageY(e)-wipe.h/2);
     moveDivTo(wipe2.div,getEventPageX(e) + 35,getEventPageY(e) + 18);
     wipe2.openLayer(); 
  }

}

function wipe3Start(e){

  if(!wipe3||wipe3.opened){
     return;
  }else{
     moveDivTo(wipe3.div,getEventPageX(e) + 35,getEventPageY(e) + 18);
     wipe3.openLayer(); 
  }

}

function Click(e){

 closeWie(wipe);
 closeWie(wipe2);

 try{
     if (!e.type){ return; };
     closeWie(wipe3);
 }catch(ec){;}

}

function closeWie(wipe){

 if(wipe != null && !wipe.closed){

  if(!e) var e = window.event;

  /* Opera(少なくともOpera 7)では、event.offsetX/Yも使えますが、レイヤに
     テキストが含まれていた場合にはバギーなため使えません。*/        

  wipe.div.downX=(window.opera)?getEventPageX(e)-getDivLeft(wipe.div):
  e.offsetX?e.offsetX:e.layerX;
  wipe.div.downY=(window.opera)?getEventPageY(e)-getDivTop(wipe.div):
  e.offsetY?e.offsetY:e.layerY; 

  var step=wipe.step;

  var downX=wipe.div.downX, downY=wipe.div.downY;    

  wipe.t=Math.abs(downY/step);             
  wipe.r=Math.abs((wipe.w-downX)/step);
  wipe.b=Math.abs((wipe.h-downY)/step); 
  wipe.l=Math.abs(downX/step);

  wipe.closeLayer();

 }

}

wipe=null;
wipe2=null;
wipe3=null;
function WipeInit(){
  var div=getDivFromName('lyr');
  var div2=getDivFromName('lyr2');
  var div3=getDivFromName('lyr3');
  if(div==null) return;
  wipe=new Wipe('wipe',div,'',20,10);
  if(div2==null) return;
  wipe2=new Wipe('wipe2',div2,'',20,10);
  if(div3==null) return;
  wipe3=new Wipe('wipe3',div3,'',20,10);
} 

function WipeCancel(){

if(wipe)wipe.cancel();
if(wipe2)wipe2.cancel();
if(wipe3)wipe3.cancel();

}

