// _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;
// _mac : true = macintosh, false = other os
_mac=navigator.userAgent.indexOf('Mac')>=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';
  }
  else if(typeof div.style.pixelLeft!="undefined"){ 
    div.style.pixelLeft=left;
    div.style.pixelTop =top;
  }
}
function moveDivBy(div,left,top){
  if(document.layers){ div.moveBy(left,top); return; } 
  if(typeof window.crypto!="undefined" &&
     typeof window.getComputedStyle!="undefined"){ 
    div.style.left=(parseInt(div.style.left)+Math.round(left))+'px';
    div.style.top =(parseInt(div.style.top) +Math.round(top) )+'px';
    return;
  } 
  if(typeof div.style.left!="undefined"&& typeof div.style.left=="string"){
    div.style.left=(div.offsetLeft+Math.round(left))+'px';
    div.style.top =(div.offsetTop +Math.round(top) )+'px';
    return; 
  }
  if(typeof div.style.pixelLeft!="undefined"){
    div.style.pixelLeft+=Math.round(left);
    div.style.pixelTop +=Math.round(top);
    return;
  }
}
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 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 resizeDivTo(div,width,height){
  if(document.layers) { 
   div.resizeTo(width,height);
  }
  else if(typeof div.style.width!="undefined"&& typeof div.style.width=="string"){
   div.style.width =width +'px';
   div.style.height=height+'px';
  }
  else if(typeof div.style.pixelWidth!="undefined"){ 
   div.style.pixelWidth  = width;
   div.style.pixelHeight = height;
  }  
}

if(_bro==1){
  document.write(
     '<style type="text/css">\n'
    +'.item{ padding-bottom:1px; }\n'
    +'<\/style>'
  );
}










blockN = 4;
menuWidth=200;
menu_dy = 5;
interval = 30;
openColor='#000';
closeColor='#000';

var sMenu=new Array();
slideNo = 0;
tid=null;
active=false;

function SlideMenu(div,d,num){
  this.div=div;
  if(document.getElementById) 
   this.itemDiv=getCoDivFromName('b'+num+'_item');
  this.d=d;
  this.opened=false;
  return this;
}  
SlideMenu.prototype.open = function(i){
  var div=this.div;
  if(!document.layers && document.getElementById){
   this.itemDiv.firstChild.firstChild.nodeValue='- ';
   this.itemDiv.firstChild.nextSibling.style.color=openColor;
  }
  this.dx=0; this.dy=this.d;
  if(getDivTop(div)<(itm_h[i]+cnt_h[i])-this.d && !this.opened){
    moveDivBy(div,this.dx,this.dy); 
    return false;
  }
  else{
    moveDivTo(div,0,itm_h[i]+cnt_h[i]); 
    this.opened=true; active=false;
    return true;      
  }
}
SlideMenu.prototype.close = function(i){
  var div=this.div;
  if(!document.layers && document.getElementById){
   this.itemDiv.firstChild.firstChild.nodeValue='+ ';
   this.itemDiv.firstChild.nextSibling.style.color=closeColor;
  }
  this.dx=0; this.dy=-this.d;
  if( getDivTop(div)>(itm_h[i]+this.d) && this.opened ){    
    moveDivBy(div,this.dx,this.dy); 
    return false;
  }
  else{
    moveDivTo(div,0,itm_h[i]);
    this.opened=false; active=false;
    return true;      
  }
}

// 下の関数を単純な２階層版のソースに加える。
SlideMenu.prototype.shut = function(i){ // 開いている別の項目を閉じる関数
  var div=this.div;
  if(!document.layers && document.getElementById){
   this.itemDiv.firstChild.firstChild.nodeValue='+ ';
   this.itemDiv.firstChild.nextSibling.style.color=closeColor;
  }
  this.dx=0; this.dy=-this.d;
  if( getDivTop(div)>itm_h[i] && this.opened ){    
    moveDivTo(div,0,itm_h[i]);
    this.opened=false; 
    return true;      
  }
}

function slideMenuToggle(i){
 if(!sMenu[i]||active) return;
 else {
  active=true;
  slide(i);
 }	
}
// 単純な２階層版の slide関数から、下の関数に変更する。
function slide(i){ 
 if(!sMenu[i].opened){                       
  for(j=0; j<sMenu.length; j++){   // add  
   if(i==j) continue;              // add 
   if(sMenu[j] && sMenu[j].opened) // add
    sMenu[j].shut(j);              // add
  }      				     // add
  if(!sMenu[i].open(i))  tid=setTimeout('slide('+i+')',interval);       
 } else { 
   if(!sMenu[i].close(i)) tid=setTimeout('slide('+i+')',interval);
 }	
}


var itm_h=new Array(); 
var cnt_h=new Array();
var blockDiv=new Array();
var itmDiv=new Array();
var cntDiv=new Array();
subTotal = 0; 

function getCoDivFromName(nm,num,cs){
 if(document.layers){
  var len, s='';
  if(arguments.length>1){
   switch(cs){
    case 0: len=num;   break;    
    case 1: len=num-1; break;
   }
   for(var i=0; i<=len; i++) s+='document.layers.'+'b'+i+'.';    
  } 
  return eval(s+'document.layers.'+nm); 
 }  
 else 
  return document.getElementById?  
       document.getElementById(nm):document.all(nm); 
}
function init(){ 
 for(var i=0; i<blockN-1; i++){
  itmDiv[i]=getCoDivFromName('b'+i+'_item',i,0);
  initDivSize(itmDiv[i]); itm_h[i]=getDivHeight(itmDiv[i]);
  subTotal+=itm_h[i]; 
  cntDiv[i]=getCoDivFromName('b'+i+'_content',i,0);
  initDivSize(cntDiv[i]); cnt_h[i]=getDivHeight(cntDiv[i]); 
  subTotal+=cnt_h[i];
  moveDivTo(cntDiv[i],0,itm_h[i]);
 }
 for(var i=1; i<=blockN-1; i++){
  blockDiv[i]=getCoDivFromName('b'+i,i,1);  
  moveDivTo(blockDiv[i],0,itm_h[i-1]);
  resizeDivTo(blockDiv[i],menuWidth,subTotal-getDivTop(blockDiv[i]));
  sMenu[i-1]=new SlideMenu(blockDiv[i],menu_dy,i-1);
 } 
 blockDiv[0]=getCoDivFromName('b0');
 resizeDivTo(blockDiv[0],menuWidth,subTotal);
 setDivVisibility(blockDiv[0],true);
}
function cancel(){  
  if(tid){ clearTimeout(tid); tid=null; }
} 
