/*--
PopupmenuClass
--*/

function PopupMenu(element, data){
	this.element = element;
	this.data = data;
}

PopupMenu.prototype.addOnMouseOver = function(id, newfunc){
	var target = document.getElementById(id);
	target.newonmouseover = newfunc;
	if (typeof(target.onmouseover) == "function" ){
		target.oldonmouseover = target.onmouseover;
		target.onmouseover = function(){
			target.oldonmouseover.call(this);
			target.newonmouseover.call(this);
		}
	}else{
		target.onmouseover = newfunc;
	}
}

PopupMenu.prototype.addOnMouseOut = function(id, newfunc){
	var target = document.getElementById(id);
	target.newonmouseout = newfunc;
	if (typeof(target.onmouseout) == "function" ){
		target.oldonmouseout = target.onmouseout;
		target.onmouseout = function(){
			target.oldonmouseout.call(this);
			target.newonmouseout.call(this);
		}
	}else{
		target.onmouseout = newfunc;
	}
}


PopupMenu.prototype.getOffset= function(element){
//	check here !! http://hkom.blog1.fc2.com/blog-entry-503.html
	var agt = navigator.userAgent.toLowerCase();
	var is_IE = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
//	alert("hello IE" + is_IE);
	var pos = new function(){		//位置測定Objectの定義
		this.parent=""; this.x=0; this.y=0;
	}
	var targetElm=element;

	if (is_IE == 1){
		while( targetElm ){			//parentを辿りながらoffset値を計算。同時に途中経過を配列に代入。
			pos.x += targetElm.offsetLeft; 
			pos.y += targetElm.offsetTop; 
			targetElm = targetElm.offsetParent;
		}
	}else{
		pos.x = targetElm.offsetLeft; 
		pos.y = targetElm.offsetTop; 
	}
	return pos;
}

PopupMenu.prototype.on = function(){

	var loc = this.getOffset(this.target);

	this.frame.style.left = ( loc.x + this.target.offsetWidth - 3 )+  "px";
	this.frame.style.top =  ( loc.y + 1 ) +  "px";
	this.frame.style.display = "block";
}

PopupMenu.prototype.off = function(){
	this.frame.style.display="none";
}


PopupMenu.prototype.make = function ()
{
	var dd = document.getElementsByTagName("body")[0];
	this.frame = document.createElement("DIV");
	this.frame.style.position = "absolute";
	this.frame.style.textAlign = "left" ;
	this.frame.path = this;
	this.frame.style.display = "none";

	dd.appendChild(this.frame) ;

	this.target=document.getElementById(this.element);
	this.target.path = this;

	this.menu = new Array(this.data.length);
	for (i = 0 ; i < this.data.length ;i++){
		this.menu[i] = document.createElement("A");
		this.menu[i].innerHTML = this.data[i].text ;
		this.menu[i].setAttribute("href", this.data[i].href);
		this.menu[i].path = this;
		this.menu[i].style.border="1px solid #B5B5B5";
		this.menu[i].style.width="180px";
		this.menu[i].style.backgroundColor="#E0E0E0";
		this.menu[i].style.padding="1px 1px 1px 4px";
		this.menu[i].style.color="#53A327";
		this.menu[i].onmouseover=function(){ this.style.backgroundColor="#ffffff"; this.style.color="#FF6600";};
		this.menu[i].onmouseout=function(){ this.style.backgroundColor="#E0E0E0"; this.style.color="#53A327"; };

		this.menu[i].style.display="block";
		this.frame.appendChild(this.menu[i]) ;

	}
	/*ターゲットのではなく、自身のメソッドとして自分の関数を呼び出す*/
	this.addOnMouseOver(this.element, function (){this.path.on();});
	this.addOnMouseOut(this.element, function (){this.path.off();});
	this.frame.onmouseover = function(){ this.path.on(); };
	this.frame.onmouseout = function(){ this.path.off(); };
}


menu_data = new Array(
	{text:"決算対応", href:"/portal/commentary/closing/index.html"},
	{text:"資産除去債務", href:"/portal/commentary/debt/index.html"},
	{text:"工事契約", href:"/portal/commentary/construction/index.html"},
	{text:"在外子会社", href:"/portal/commentary/cfc/index.html"},
	{text:"関連当事者", href:"/portal/commentary/connectedperson/index.html"},
	{text:"ソフトウエア", href:"/portal/commentary/software/index.html"},
	{text:"棚卸資産", href:"/portal/commentary/inventory/index.html"},
	{text:"リース", href:"/portal/commentary/lease/index.html"},
	{text:"会社法", href:"/portal/commentary/cl/index.html"},
	{text:"内部統制", href:"/portal/commentary/internalcontrol/index.html"},
	{text:"ストック・オプション", href:"/portal/commentary/stockoption/index.html"},
	{text:"減損会計", href:"/portal/commentary/depletionaccount/index.html"},
	{text:"四半期報告制度", href:"/portal/commentary/quarter/index.html"}
);

var pumenu = new PopupMenu("navi4", menu_data);


