// グローバル変数定義
// Toggle
var leftflag="open";
var sideflags={sideslide1:"open",sideslide2:"open",sideslide3:"open",sideslide4:"open",sideslide5:"open"};
var acce=200;
var slide_interval=1;
var defleftwidth=213;
var widthmin=26;
var mouseX,mouseY;

/* --Script for Toggle--start */
// ローカルエリア開閉
function leftslide(){
	var objBody=document.getElementsByTagName("body")[0];

	if(leftflag=="open"){ 
		var leftwidth=defleftwidth;
		$("left_display").style.display="none";
		objBody.style.backgroundImage="url(http://www.infofarm.jp/img/left_back2.gif)";
		if(!document.all) {
			$("left_toggle-area").style.marginLeft=leftwidth-widthmin+"px";
		} else{
			$("left_toggle-area").style.marginLeft="-39px";
		}
		var funcRef= function(){
			leftwidth=leftwidth-acce;
			if( leftwidth < widthmin ){
				leftwidth=widthmin ;
				clearInterval(IntvarID);
				leftflag="close";
				// 開閉状態をクッキーへ格納
//				document.cookie = "localToggle=" + escape(leftflag) + ";";
				Element.removeClassName($("left_toggle"), "toggle_l");
				Element.addClassName($("left_toggle"), "toggle_r");
				setTimeout(function(){
					$("left_toggle-area").style.marginLeft="-13px";
				},1);
			}
// U_ST 20090304 tanaka 戦略箱ADVANCEDとウェブサイトでidの名前が異なる為。
//			$("wrapper").style.marginLeft=leftwidth+"px";
			$("contents_wrapper").style.marginLeft=leftwidth+"px";
// U_ED 20090304 tanaka
			$("left").style.width=leftwidth+"px";
			$("left").style.marginLeft="-"+(leftwidth-1)+"px";
			if(!document.all) $("left_toggle-area").style.marginLeft=leftwidth-widthmin+"px";
		}
		IntvarID=setInterval(funcRef,slide_interval);
		// 予実テーブル幅再計算用
		if($("analyze_table")){
			var orgHdrWidth = parseInt($("analyze_right_header").style.width.replace("px",""));
			var orgBdyWidth = parseInt($("analyze_right_body").style.width.replace("px",""));
			$("analyze_right_header").style.width = orgHdrWidth+187 + "px";
			$("analyze_right_body").style.width = orgBdyWidth+187 + "px";
		}
	} else{ 
		var leftwidth=widthmin;
		var funcRef= function(){
			leftwidth=leftwidth+acce;
			if(leftwidth>defleftwidth){
				leftwidth=defleftwidth;
				clearInterval(IntvarID);
				leftflag="open";
				// 開閉状態をクッキーへ格納
//				document.cookie = "localToggle=" + escape(leftflag) + ";";
				Element.removeClassName($("left_toggle"), "toggle_r");
				Element.addClassName($("left_toggle"), "toggle_l");
				
				setTimeout(function(){
					objBody.style.backgroundImage="url(http://www.infofarm.jp/img/left_back.gif)";
					$("left_display").style.display="block";
					$("left_toggle-area").style.marginLeft="-26px";
				},1);
			}
			
// U_ST 20090304 tanaka 戦略箱ADVANCEDとウェブサイトでidの名前が異なる為。
//			$("wrapper").style.marginLeft=leftwidth+"px";
			$("contents_wrapper").style.marginLeft=leftwidth+"px";
// U_ED 20090304 tanaka
			$("left").style.width=leftwidth+"px";
			$("left").style.marginLeft="-"+(leftwidth-1)+"px";
			if(!document.all) $("left_toggle-area").style.marginLeft=leftwidth-widthmin+"px";
			
		}
		IntvarID=setInterval(funcRef,slide_interval);
		// 予実テーブル幅再計算用
		if($("analyze_table")){
			var orgHdrWidth = parseInt($("analyze_right_header").style.width.replace("px",""));
			var orgBdyWidth = parseInt($("analyze_right_body").style.width.replace("px",""));
			$("analyze_right_header").style.width = orgHdrWidth-187 + "px";
			$("analyze_right_body").style.width = orgBdyWidth-187 + "px";
		}
	}	
}

// ローカルエリア内メニュー開閉
function sideslide(e){
	obj=Event.element(e);
	objid=obj.id;
	str=objid.replace("_toggle","");
	switch(sideflags[str]){
		case "moving":
			return;break;
		case "open":
			sideflags[str]="moving";
			var bl=new Effect.BlindUp(str,{duration:0.5});
			new effectWatcher(bl,function(){
			  	sideflags[str]="close";
				obj.src="http://www.infofarm.jp/img/local_toggle_p.gif";
			});
			break;
		case "close":
			sideflags[str]="moving";
			var bl=new Effect.BlindDown(str,{duration:0.5});
			new effectWatcher(bl,function(){
				sideflags[str]="open";
				obj.src="http://www.infofarm.jp/img/local_toggle_m.gif";
			});
			break;
	}
}
/* --Script for Toggle--end */

function effectWatcher(obj,afterfunc,frequency){ //Effect-object's status listner
	if(!frequency) frequency=200;
	var intv;
	var func=function(){
		if(obj.state=="finished"){
			afterfunc();
			clearInterval(intv);
		}
	}
	intv=setInterval(func,frequency);
}

function getPageSize(){
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

/*--マウス座標取得 srart--*/
function setXY(e){
	mouseX=Event.pointerX(e);
	mouseY=Event.pointerY(e);
}
/*--マウス座標取得 end--*/

// 指定したIDへスクロール（ページの先頭へ戻る場合は、引数に'wrapper'を指定）
function scrTo(targetid){
	new Effect.ScrollTo($(targetid));
}

/* ウィンドウリサイズ --end */

/* --Script for Table mouseover--start */
function table_mouseon(e){
	obj=e;
	if (obj.className != "second roll") {
		trOrig=obj.className;
		obj.className="second roll";
	}

	if(obj.getElementsByTagName("td")[0]){
		if(obj.getElementsByTagName("td")[0].getAttribute("rowspan")>1){ //brother
			trPost=obj.nextSibling.className;
			obj.nextSibling.className="second roll";
		}
		var Sib=obj.previousSibling;
		Sib=(Sib.nodeName.indexOf("TR")!=-1 ) ? Sib :Sib.previousSibling ;
			if(Sib.getElementsByTagName("td")[0] && Sib.getElementsByTagName("td")[0].getAttribute("rowspan") >1){ //cousin
				trPre=Sib.className;
				Sib.className="second roll";
			}
	}

	Event.observe(obj,"mouseout",table_mouseout,true);
}

function table_mouseout(e){
	obj=Event.element(e);
	while (obj.parentNode.nodeName!="TR"){
		obj=obj.parentNode;
	}
	if (obj.parentNode.className == "second roll") {
		obj.parentNode.className=trOrig;
	}

	if(obj.parentNode.getElementsByTagName("td")[0]){
		if(obj.parentNode.getElementsByTagName("td")[0] && obj.parentNode.getElementsByTagName("td")[0].getAttribute("rowspan")>1){ //brother
			obj.parentNode.nextSibling.className=trPost;
		}
		var Sib=obj.parentNode.previousSibling;
		Sib=(Sib.nodeName.indexOf("TR")!=-1 ) ? Sib :Sib.previousSibling ;
		if(Sib.getElementsByTagName("td")[0] && Sib.getElementsByTagName("td")[0].getAttribute("rowspan") >1){ //cousin
			Sib.className=trPre;
		}
	}
}
/* --Script for Table mouseover--end */

/*--addLoadEvent--start*/
function addLoadEvent(func){ //add 'window.onload' function later
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}
/*--addLoadEvent--end*/

function Focus1(obj){
 if (obj.value == "検索キーワードを入力") {
  obj.value = "";
  obj.style.color = "#000000"; 
 }
}

function Blur1(obj){
 if (obj.value == "") {
  obj.value = "検索キーワードを入力";
  obj.style.color = "#848284"; 
 }
}

window.onload=function(){
	//Set event-listner
	if($("left_toggle")){
		Event.observe($("left_toggle"), "click", leftslide, true);
		leftwidth =	defleftwidth;
	}
	if($("sideslide1")){
		Event.observe($("sideslide1_toggle"), "click", sideslide, true);
	}
	if($("sideslide2")){
		Event.observe($("sideslide2_toggle"), "click", sideslide, true);
	}
	if($("sideslide3")){
		Event.observe($("sideslide3_toggle"), "click", sideslide, true);
	}
	if($("sideslide4")){
		Event.observe($("sideslide4_toggle"), "click", sideslide, true);
	}
	if($("sideslide5")){
		Event.observe($("sideslide5_toggle"), "click", sideslide, true);
	}

	Event.observe(window.document, "click", setXY, false);
}
