Menu.arrow_image=[["",""],
　　　　　　　　　["",""],
　　　　　　　　　["",""]];

Menu.back_image=["",""]; 

Menu.parts={ innerBorderWidth:1, innerBorderColor:"#ffffff", cellSpaceWidth:1 }; 

divNum = 0;
function createDiv(){
  divName='dynDiv'+(divNum++);
  divCName="menu_samples";
  if(document.body&&document.body.insertAdjacentHTML){
    txt='<div id="'+divName+'" cont="'+divCName
       +'" style="position:absolute;visibility:hidden"><\/div>';   
    document.body.insertAdjacentHTML('BeforeEnd',txt);
    return document.getElementById?
     document.getElementById(divName):document.all(divName);
  }
  else if(document.createElement){
    document.body.appendChild(div=document.createElement('DIV'));
    div.id=divName; 
    div.setAttribute('cont',divCName);
    with(div.style){
     position = 'absolute';     
     visibility='hidden';
    }
    return div; 
  }
  return null;    
}

var arrow_img=new Array();
var back_img =new Array();
function preArrowLoad(){ 
  for(var i=0; i<Menu.arrow_image.length*2; i++){
    arrow_img[i]=new Image();
    arrow_img[i].src=Menu.arrow_image[Math.floor(i/2)][i%2];
  }    
}
function preBackLoad(){ 
  for(var i=0; i<Menu.back_image.length; i++){
    back_img[i]=new Image();
    back_img[i].src=Menu.back_image[i];
  }    
}
preArrowLoad();
preBackLoad();

Menu.eles=new Array();
Menu.menu_divs=new Array();
 
function mouseOver(e){
  var ele=null;
  if(!e) e=window.event;
  if(e.target) ele=e.target;
  else if(e.srcElement) ele=e.srcElement;
  while(ele.getAttribute("cont")!="menu_samples"){
   if(ele.getAttribute("cont")=="menu_td"&&ele.getAttribute("nm")){
     if(!this.parent_obj) break;
     var p_obj=this.parent_obj;
     var nm=ele.getAttribute("nm");
     ele.itemMouseOver=p_obj.items[nm].menu_over;
     ele.itemMouseOut =p_obj.items[nm].menu_out;
     if(this.preEle){
      var pre_ele=this.preEle;
      pre_ele.className=pre_ele.itemMouseOut;
      if(pre_ele.firstChild) arrowChange(pre_ele.firstChild,true);
    }
     ele.className=ele.itemMouseOver;  
     if(ele.firstChild) arrowChange(ele.firstChild,false);
     if(this.subMenu){
      var sub_menu=this.subMenu;
      setDivVisibility(sub_menu,false);
      if(sub_menu.preEle) {
       sub_menu.preEle.className=sub_menu.preEle.itemMouseOut;
       if(sub_menu.preEle.firstChild) arrowChange(sub_menu.preEle.firstChild,true);
      }      
      while(sub_menu.subMenu){
       sub_menu=sub_menu.subMenu;
       setDivVisibility(sub_menu,false);
       if(sub_menu.preEle) {
        sub_menu.preEle.className=sub_menu.preEle.itemMouseOut;
        if(sub_menu.preEle.firstChild) arrowChange(sub_menu.preEle.firstChild,true);
       } 
      }       
     }         
     this.preEle=ele;
     Menu.eles[Menu.eles.length]=ele;
     if(!this.parent.items[nm].link){
      this.style.cursor="default";
     }
     else{
      if(document.all) this.style.cursor="hand";
      else this.style.cursor="pointer";
     }
     if(this.parent.items[nm].child){
      var child_div=this.parent.items[nm].child.div;
      this.subMenu=child_div;
      setDivVisibility(child_div,true);
      Menu.menu_divs[Menu.menu_divs.length]=child_div;
     } 
    break;
   }
   ele=window.external?ele.parentElement:ele.parentNode;
  }
}

function mouseOut(e){
  var relEle=null;
  if(!e) var e=window.event;
  if(e.relatedTarget) relEle=e.relatedTarget;
  else if(e.toElement) relEle=e.toElement;
  for(; relEle!=null; relEle=window.external?relEle.parentElement:relEle.parentNode){
    if(relEle.parent_obj) break;
  }
  if(relEle==null){
   for(i=0; i<Menu.menu_divs.length; i++)
    setDivVisibility(Menu.menu_divs[i],false);
   Menu.menu_divs=[];
   var on_nodes=Menu.eles;
   for(i=0; i<on_nodes.length; i++){
    var nd=on_nodes[i];
    nd.className=nd.itemMouseOut;
    if(!nd.firstChild||!nd.firstChild.img_on) continue;
    arrowChange(nd.firstChild,true);
   }
   Menu.eles=[]; 
  }
}
function mouseDown(e){
  var ele=null;
  if(!e) e=window.event;
  if(e.target) ele=e.target;
  else if(e.srcElement) ele=e.srcElement; 
  while(ele.getAttribute("cont")!="menu_samples"){
  if(ele.getAttribute("cont")=="menu_td"&&ele.getAttribute("nm")){
   var nm=ele.getAttribute("nm");
   if(this.parent.items[nm].link){
    location.href=this.parent.items[nm].link;
   } 
   break;
  }
  ele=window.external?ele.parentElement:ele.parentNode;
 }
}
function arrowChange(node,def){  
  if(node.className && (node.className=="right_arrow"||node.className=="left_arrow"
     ||node.className=="down_arrow")){
     switch(node.className){
     case 'right_arrow': 
       node.src=def?arrow_img[0].src:arrow_img[1].src; break;
     case 'left_arrow':  
       node.src=def?arrow_img[2].src:arrow_img[3].src; break;
     case 'down_arrow': 
       node.src=def?arrow_img[4].src:arrow_img[5].src; break;
     }
     node.img_on=def?false:true;
  }
}
function getCbWidth(element,prop){
 var num=0;
 if(element.currentStyle){
   switch(prop){
    case "border-top-width":
     num=parseInt(element.currentStyle.borderTopWidth);    break;
    case "border-bottom-width":
     num=parseInt(element.currentStyle.borderBottomWidth); break;
    case "border-right-width":
     num=parseInt(element.currentStyle.borderRightWidth);  break;
    case "border-left-width":
     num=parseInt(element.currentStyle.borderLeftWidth);   break;
    }
  }
  else if(window.getComputedStyle){
     var css=window.getComputedStyle(element,'');
     num=parseInt(css.getPropertyValue(prop));
  }
  if(isNaN(num)) num=0;
  return num;
}

Menu.menuCount = 0;
                            
function Menu(){
  this.id='menu'+(Menu.menuCount++);
  this.menuCount=Menu.menuCount;
  this.marginY = 0; 
  this.marginX = 0;  
  this.div=createDiv();
  this.div.id='menuDiv'+this.menuCount;
  this.div.parent=this.div.parent_obj=this;
  this.w=arguments[0];
  this.total_width=0;
  this.itemH=arguments[1];
  this.dir=arguments[4]?arguments[4]:'vertical';
  this.textPos=arguments[5]?arguments[5]:'center';
  this.arrowPos=arguments[6]?arguments[6]:'right';
  if(!arguments[6]) this.NoArrow=true;
  this.text_margin =(typeof(arguments[7])!="number")?0:arguments[7];
  this.arrow_margin=(typeof(arguments[8])!="number")?0:arguments[8];
  this.arrow_top=(typeof(arguments[9])!="number")?0:arguments[9];
  this.anchor=arguments[10];
  this.menu_out =arguments[11]?arguments[11]:'subMenu';
  this.menu_over=arguments[12]?arguments[12]:'subMenuOver';
  this.div_className=this.menu_out+'DIV';
  this.div.className=this.div_className;
  this.parts_style=arguments[13];
  this.text_arrow=arguments[14];
  if(this.parts_style){
   var par=this.parts_style; 
   this.innerBorderWidth=(typeof(par.innerBorderWidth)=="number")?
                         par.innerBorderWidth:1; 
   this.cellSpaceWidth=(typeof(par.cellSpaceWidth)=="number")?par.cellSpaceWidth:0;                     
　 this.innerBorderColor=par.innerBorderColor?par.innerBorderColor:'#c0c0c0';
  }
  this.borderTopWidth=getCbWidth(this.div,'border-top-width');
  this.borderBottomWidth=getCbWidth(this.div,'border-bottom-width');
  this.borderLeftWidth=getCbWidth(this.div,'border-left-width');
  this.borderRightWidth=getCbWidth(this.div,'border-right-width');
  this.cellBorderWidthTB = 0;
  this.cellBorderWidthLF = 0;
  if(this.dir=='horizon')this.total_width+=this.cellSpaceWidth;
  else this.total_width=this.w+this.cellSpaceWidth*2;
  if(this.menuCount==1) {
    if(typeof(arguments[2])!="number") {
     this.temp_left=arguments[2];
     this.left=0;
    }
    else this.left=arguments[2];
    this.top =arguments[3];
    moveDivTo(this.div,this.left,this.top);
  }
  else{
    this.left=0;
    this.top =0;
    this.marginX=arguments[2];
    this.marginY=arguments[3];     
  }
  this.mtb=document.createElement('table');
  this.mtb.className=this.menu_out+'TABLE';
  this.mtb.style.borderWidth='0px';
  this.mtb.cellPadding='0px';
  this.mtb.cellSpacing=this.cellSpaceWidth+'px';  	
  this.mtbo=document.createElement('tbody');
  if(this.dir=="horizon"){
   this.mtr=document.createElement('tr');
   this.mtbo.appendChild(this.mtr);
  }  	
  this.mtb.appendChild(this.mtbo);						
  this.div.appendChild(this.mtb);
  this.items=new Array();
  this.next_width=this.cellSpaceWidth;
  return this;
}
Menu.prototype.add = function(obj){ 
 obj.parent=this;
 if(this.dir=='vertical') obj.w=this.w;
 else if(this.dir=='horizon') {
  if(obj.w>0){
   this.total_width+=obj.w;
  }else{
   obj.w=this.w;
   this.total_width+=this.w;
  }
  if(this.cellSpaceWidth) this.total_width+=this.cellSpaceWidth;
 }
 obj.h=this.itemH;
 obj.dir=this.dir;
 obj.arrow_pos=this.arrowPos;
 this.items[obj.id]=this.items[this.items.length]=obj;
 this.items[obj.id].link=obj.link;
 this.items[obj.id].menu_out=obj.menu_out?obj.menu_out:this.menu_out;
 this.items[obj.id].menu_over=obj.menu_over?obj.menu_over:this.menu_over;
 var pre_obj=null;
 if(this.items.length>1){
   pre_obj=this.items[this.items.length-2];
   if(pre_obj.separate&&this.innerBorderWidth>0){
    this.next_width=this.innerBorderWidth+this.cellSpaceWidth*2;
    if(this.dir=="horizon") this.total_width+=this.innerBorderWidth+this.cellSpaceWidth;
   }else this.next_width=this.cellSpaceWidth;
 }
 var mtr=document.createElement('tr');
 var mtrl=mtr.cloneNode(false);  	
 var mtd=document.createElement('td');
 var mtdl=mtd.cloneNode(false);
 mtd.setAttribute('cont','menu_td');
 var msp=null;
 if(!this.NoArrow &&!this.text_arrow) msp=document.createElement('p');
 else msp=document.createElement('span');
 if(this.anchor&&obj.link) msp.style.textDecoration='underline';
 var text=obj.text.replace(/\s/g,'&nbsp;');
 msp.innerHTML='<span style="white-space:nowrap">'+text+'<\/span>';
 var nav;    
 if(obj.navImg){
  if(this.text_arrow) {
   nav=document.createElement('span');
   nav.appendChild(document.createTextNode(this.text_arrow));
  }
  else {
    nav=document.createElement('img');
    nav.src=(this.dir=='horizon')?Menu.arrow_image[2][0]:
            (this.arrowPos=='right')?Menu.arrow_image[0][0]:Menu.arrow_image[1][0];
    nav.className=(this.dir=='horizon')?'down_arrow':
              (this.arrowPos=='right')?'right_arrow':'left_arrow'; 
  }
  mtd.appendChild(nav);
 }
 if(!obj.menu_out) mtd.className=this.menu_out;
 else mtd.className=obj.menu_out;
 mtd.appendChild(msp);
 if(this.dir=="horizon") this.mtr.appendChild(mtd);
 else{
  mtr.appendChild(mtd);
  this.mtbo.appendChild(mtr);
 }
 var btw=getCbWidth(mtd,'border-top-width');
 var bbw=getCbWidth(mtd,'border-bottom-width');
 var brw=getCbWidth(mtd,'border-right-width');
 var blw=getCbWidth(mtd,'border-left-width');
 this.cellBorderWidthTB =btw+bbw;
 this.cellBorderWidthLF =brw+blw;
 obj.w+=this.cellBorderWidthLF;
 obj.h+=this.cellBorderWidthTB;
 this.tw=obj.w
 this.itemTH=obj.h;
 if(this.dir=='vertical' && this.items.length<2) this.total_width+=this.cellBorderWidthLF;
 else if(this.dir=='horizon') this.total_width+=this.cellBorderWidthLF;
 var mtw,mth;
 if(navigator.userAgent.match(/Netscape/)&&
   parseFloat(navigator.vendorSub)<7.1) mtw=obj.w;
 else mtw=obj.w-this.cellBorderWidthLF;
 if(window.external&&document.compatMode&&document.compatMode.match(/CSS/)) 
  mth=obj.h-this.cellBorderWidthTB;
 else mth=obj.h;    
 if(this.dir=='horizon'){
   obj.sub_defleft=this.items.length>1?pre_obj.sub_defleft+pre_obj.w+this.next_width
            :this.left+this.borderLeftWidth+this.cellSpaceWidth;
   obj.sub_deftop=this.top+this.itemTH+2*this.cellSpaceWidth+this.borderTopWidth+this.borderBottomWidth; 
   if(this.items.length>1 &&pre_obj.separate && this.innerBorderWidth>0){
     with(mtdl.style){
       backgroundColor=this.innerBorderColor;
       width=this.innerBorderWidth+'px';
       height=mth+'px';
     }
     this.mtr.insertBefore(mtdl,mtd);     
   }
 }else if(this.dir=='vertical'){
   if(this.arrowPos=='right') 
    obj.sub_defleft=this.left+this.tw+2*this.cellSpaceWidth+this.borderLeftWidth+this.borderRightWidth;
   else if(this.arrowPos=='left') obj.sub_defleft=this.left;  
   obj.sub_deftop=this.items.length>1?pre_obj.sub_deftop+pre_obj.h
                 +this.next_width:this.top+this.borderTopWidth+this.cellSpaceWidth;
   if(this.items.length>1 &&pre_obj.separate && this.innerBorderWidth>0){
     with(mtdl.style){
       backgroundColor=this.innerBorderColor;
       width=mtw+'px';
       height=this.innerBorderWidth+'px';
     }
     mtrl.appendChild(mtdl);
     this.mtbo.insertBefore(mtrl,mtr);
   }
 }
 mtd.setAttribute('nm',obj.id);
 with(mtd.style){
  width=mtw+'px';
  height=mth+'px';
  textAlign=this.textPos;
  if(!this.NoArrow && !this.text_arrow) verticalAlign='top';
  else verticalAlign='middle'; 
  padding='0px';
 }
 var thei=msp.offsetHeight;
 if(this.arrowPos=="right"){
   if(obj.navImg){
    if(window.external) nav.style.styleFloat='right';
    else nav.setAttribute('style','float:right');
    nav.style.marginRight=this.arrow_margin+'px';
   }
   msp.style.paddingLeft=this.text_margin+'px';
 }
 else if(this.arrowPos=="left"){
   if(obj.navImg){
      if(window.external) nav.style.styleFloat='left';
      else nav.setAttribute('style','float:left');
      nav.style.marginLeft=this.arrow_margin+'px';
   }
   msp.style.paddingRight=this.text_margin+'px';
 } 
 msp.style.marginBottom='0px';
 if(!this.NoArrow &&!this.text_arrow){
  msp.style.marginTop=Math.floor(((obj.h-this.cellBorderWidthTB)-thei)/2)+'px';
  if(obj.navImg)
   nav.style.marginTop=Math.floor(((obj.h-this.cellBorderWidthTB)-nav.offsetHeight)/2)
                      +this.arrow_top+'px';
 }
}
 
Menu.prototype.build = function(){
 if(window.controllers) this.div.style.width=this.total_width+'px';
 else this.mtb.style.width=this.total_width+'px';    
 var all_width=this.total_width+this.borderLeftWidth+this.borderRightWidth;
 if(this.temp_left=='center')
  this.left=Math.floor((getWindowWidth()-all_width)/2);
 var mx=this.marginX, my=this.marginY; 
 if(this.parent && this.parent.dir=='vertical'
    &&this.parent.arrow_pos=='left'){
     this.left-=all_width;
 }
 for(i=0; i<this.items.length; i++){
  this.items[i].sub_defleft+=mx;
  this.items[i].sub_deftop+=my;
  if(this.temp_left) this.items[i].sub_defleft+=this.left;
 }                 
 moveDivTo(this.div,this.left+mx,this.top+my);
 this.div.onmouseover=mouseOver;
 this.div.onmouseout =mouseOut;
 this.div.onmousedown=mouseDown;
 if(this.menuCount==1) setDivVisibility(this.div,true);
}

function MenuItem(){ 
 this.id=arguments[0];
 this.text=arguments[0];
 this.link=arguments[1];
 this.navImg=arguments[2];
 this.separate=arguments[3];
 this.menu_out =arguments[4];
 this.menu_over=arguments[5];
 this.w=(arguments.length>6)?arguments[6]:0;
 this.h = 0;
 this.sub_deftop=0;
 this.sub_defleft=0;
 this.parent=null;
 return this;
}

MenuItem.prototype.setMenu = function(obj){
 obj.parent=this;
 this.child=obj;
 obj.left=this.sub_defleft; 
 obj.top =this.sub_deftop;  　
}

function init(){
 
 menu_bar=new Menu(100,30,86,221,'horizon','center','',0,0,0,false,'mainMenu','mainMenuOver',Menu.parts,
                   "");
                                      
 menu_bar.add(new MenuItem('お部屋探し',"",false,true,'','',100));
 menu_bar.add(new MenuItem('入居者様向け情報',"",false,true,'','',150));
 menu_bar.add(new MenuItem('入居関連商品',"",false,true,'','',120));
 menu_bar.add(new MenuItem('お問合せ･ご来店予約',"form.html",false,true,'','',150));
 menu_bar.add(new MenuItem('会社情報',"",false,true,'','',100));
 menu_bar.build();
   
 menu1=new Menu(150,20,0,0,'vertical','left','',0,0,0,false,'subMenu','subMenuOver',Menu.parts,
                "");               
 menu_bar.items['お部屋探し'].setMenu(menu1); 　
 menu1.add(new MenuItem(' 賃貸物件',"c-kensaku.html",false,true)); 
 menu1.add(new MenuItem(' 売買物件',"b-kensaku.html",false,true));
 menu1.add(new MenuItem(' 引越しマニュアル',"hikkosi-manu.html",false,true));
 menu1.add(new MenuItem(' お部屋探しマニュアル',"search-manu.html",false,true));
 menu1.build();
 
 menu2=new Menu(150,20,0,0,'vertical','left','',0,0,0,false,'subMenu','subMenuOver',Menu.parts,
                "");
 menu_bar.items['入居者様向け情報'].setMenu(menu2);
 menu2.add(new MenuItem(' 入居のしおり',"siori.html",false,true));
 menu2.build();
 
 menu3=new Menu(150,20,0,0,'vertical','left','',0,0,0,false,'subMenu','subMenuOver',Menu.parts,
                "");
 menu_bar.items['入居関連商品'].setMenu(menu3);
 menu3.add(new MenuItem(' 消毒･殺菌サービス',"shodokuetc.html",false,true));
 menu3.add(new MenuItem(' アパマンショップカード',"a-card.html",false,true));
 menu3.add(new MenuItem(' 引越し王日通',"nittsu.html",false,true));
 menu3.build();
 
 menu4=new Menu(150,20,0,0,'vertical','left','',0,0,0,false,'subMenu','subMenuOver',Menu.parts,
                "");
 menu_bar.items['お問合せ･ご来店予約'].setMenu(menu4);
 menu4.build();
 
 menu5=new Menu(150,20,0,0,'vertical','left','',0,0,0,false,'subMenu','subMenuOver',Menu.parts,
                "");
 menu_bar.items['会社情報'].setMenu(menu5);
 menu5.add(new MenuItem(' 会社概要',"gaiyo.html",false,true));
 menu5.add(new MenuItem(' 個人情報のお取扱について',"privacy.html",false,true));
 menu5.build();
}
