// tools.js

// 2006/03/14

//

d = window.document

loaded = false;

active = '1';

delay=300;

timer = null;

// popped = 0;



function init(){

	prepare_menus();

	loaded = true;

}



// browser detection object



function lib_bwCheck(){

	this.ver = parseInt(navigator.appVersion);

	this.agent = navigator.userAgent.toLowerCase();

	this.dom = document.getElementById?1:0

	this.opera = (this.agent.indexOf("opera")>-1);

	this.opera5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);

	this.nav = ((this.agent.indexOf('mozilla')>-1) && (this.agent.indexOf('spoofer')==-1)

	&& (this.agent.indexOf('compatible') == -1) && (this.agent.indexOf('opera')==-1)

	&& (this.agent.indexOf('webtv')==-1) && (this.agent.indexOf('hotjava')==-1));

	this.nav4up = (this.nav && (this.ver == 4));

	this.nav6up = (this.nav && (this.ver >= 5));

	this.gecko = (this.agent.indexOf('gecko')>-1);

	this.ie5 = (this.agent.indexOf("msie 5")>-1 && this.dom && !this.opera)?1:0

	this.ie6 = (this.agent.indexOf("msie 6")>-1 && this.dom && !this.opera)?1:0

	this.ie4 = (document.all && !this.dom && !this.opera)?1:0

	this.ie = ((this.agent.indexOf("msie") != -1) && (this.agent.indexOf("opera") == -1));

	this.ie4up = (this.ie && (this.ver >= 4));

	this.mac = this.agent.indexOf("mac")>-1

	this.ns6 = (this.dom && this.ver>=5)?1:0

	this.ns4 = (document.layers && !this.dom)?1:0

	this.bw = (this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera)

	return this

}

bw = new lib_bwCheck() // Browser object



function lib_pfCheck(){

	this.ver = parseInt(navigator.appVersion);

	this.agent = navigator.userAgent.toLowerCase();	

	this.win = ((this.agent.indexOf("win")!=-1) || (this.agent.indexOf("16bit")!=-1) );

	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all

	// Win32; can't distinguish between Win95 and WinNT.

	this.win95 = ((this.agent.indexOf("win95")!=-1) || (this.agent.indexOf("windows 95")!=-1));



	// is this a 16 bit compiled version?

	this.win16 = ((this.agent.indexOf("win16")!=-1) || (this.agent.indexOf("16bit")!=-1) ||

		(this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("windows 16-bit")!=-1) );

	this.win31 = ((this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("win16")!=-1) ||

		(this.agent.indexOf("windows 16-bit")!=-1));



	this.winme = ((this.agent.indexOf("win 9x 4.90")!=-1));

	this.win2k = ((this.agent.indexOf("windows nt 5.0")!=-1));

	

	// NOTE: Reliable detection of Win98 may not be possible. It appears that:

	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.

	//       - On Mercury client, the 32-bit version will return "Win98", but

	//         the 16-bit version running on Win98 will still return "Win95".

	this.win98 = ((this.agent.indexOf("win98")!=-1) || (this.agent.indexOf("windows 98")!=-1));

	this.winnt = ((this.agent.indexOf("winnt")!=-1) || (this.agent.indexOf("windows nt")!=-1));

	this.win32 = (this.win95 || this.winnt || this.win98 || ((this.ver >= 4) && (navigator.platform == "Win32")) ||

		(this.agent.indexOf("win32")!=-1) || (this.agent.indexOf("32bit")!=-1));	

	this.os2 = ((this.agent.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) ||

		(this.agent.indexOf("ibm-webexplorer")!=-1));

	this.mac = (this.agent.indexOf("mac")!=-1);

	this.mac68k = (this.mac && ((this.agent.indexOf("68k")!=-1) || (this.agent.indexOf("68000")!=-1)));

	this.macppc = (this.mac && ((this.agent.indexOf("ppc")!=-1) || (this.agent.indexOf("powerpc")!=-1)));

	

	return this

}

pf = new lib_pfCheck() // Platform object



lib_cssCheck();



///////

function lib_obj(obj){

	this.el = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval('document.' + obj):0;

	this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;

	this.moveIt = lib_moveIt;

	this.showIt = lib_showIt;

	this.hideIt = lib_hideIt;

	return this;

}



function lib_moveIt(x,y){

	if (x){this.x=x; this.css.left = x;}

	if (y){this.y=y; this.css.top = y;}

}



function lib_showIt(){this.css.visibility = "visible"}

function lib_hideIt(){this.css.visibility = "hidden"}

///////



function changeactive(which) {

	if (loaded){

		clearTimeout(timer);

		m_rollover('item' + which);

//		popped = 1;

		mDiv['m' + active].hideIt();

		m_rollout('item' + active);

		active =which;

		mDiv['m' + active].showIt();

		theleft = m_move(active);

		mDiv['m' + active].css.left = theleft;

		m_rollover('item' + active);		

	}

}



function killIt(){

	if (loaded){

		mDiv['m' + active].hideIt();

		m_rollout('item' + active);	

	}

}



function killmenu(){

	if (loaded){

		timer = setTimeout("killIt()",delay);

	}

}



function sleep(){

	clearTimeout(timer);

}



function prepare_menus() {

	mDiv = new Array();

	for (var i=0;i<4;i++){

		mDiv['m' +i] = new lib_obj('m' +i);

	}

}



function get_menus() {

	// requires a global "rootpath" variable

	// menu items

	var mitems = new Array(

		"協会の概要　　　　　　,協会の活動紹介　　　　,全国の支部所在地と連絡先,入会のご案内と申し込み,ご寄付のお願い",

		"ALSの病理と診断　　　　,ALSの症状と生活の変化　,ALSの治療研究　　　　　,ALS関連の講演・論文など　　,ALSに関するデータ　　　",

		"ALSと診断されたら　　　,得られる社会的支援と相談窓口,自分らしく生きるために〜療養生活の実例〜,関連する法律と制度／サービス情報,生き方さまざま　　　　,難病と心のケア",

		"コミュニケーション支援室,ALS人工呼吸器患者の外出,ALS患者の緊急時の備え　,療養の工夫とヒヤリ・ハット体験集,日本ALS協会定款全文　　,譲って／譲りますコーナー,機関誌JALSA閲覧室　　　"

	);





	// link directories

	//var mdurls = new Array(

	//	"",

	//	"contents/profile/",

	//	"contents/schedule/",

	//	"contents/report/",

	//	"contents/library/",

	//	"contents/essay/",

	//	"contents/link/"

	//);



	// link file destinations

	var mfurls = new Array(

		"contents/profile/index.html,contents/profile/02.html,contents/profile/03.html,contents/profile/04.html,contents/profile/05.html",

		"contents/whatis/index.html,contents/whatis/02.html,contents/whatis/03.html,contents/whatis/04.html,contents/whatis/05.html",

		"contents/care/index.html,contents/care/02.html,contents/care/03.html,contents/care/04.html,contents/care/05.html,contents/care/06.html",

		"/cgi-bin/jalsa/mem_login.cgi?type=0,/cgi-bin/jalsa/mem_login.cgi?type=1,/cgi-bin/jalsa/mem_login.cgi?type=2,/cgi-bin/jalsa/mem_login.cgi?type=3,/cgi-bin/jalsa/mem_login.cgi?type=4,/cgi-bin/jalsa/mem_login.cgi?type=5,/cgi-bin/jalsa/mem_login.cgi?type=6"

	);

	for(i=0;i<mitems.length;i++) {

		var mid = 'm' + i;

		var subitems =mitems[i].split(',');

		var suburls = mfurls[i].split(',');

		//var subpath = rootpath + mdurls[i];

		document.write("<table id='");

		document.write(mid);

		document.write("' onmouseout='killmenu()' onmouseover='sleep()'>");	

		for(j=0;j<subitems.length;j++) {

			document.write("<tr class='mitem'><td><a href='");

			if(suburls[j].charAt(0) == "/"){

				document.write(suburls[j]);

			}else{

				document.write(rootpath + suburls[j]);

			}

			document.write("'><font color='#001699'>");

			document.write(subitems[j]);

			document.write("</font></a></td></tr>");

		}

		document.write("</table>");

	}

}



//menu left

menu_left = new Array();

menu_left = ["0","173","360","460"]



// rollover functions

menu_ar = new Array();

menu_ar[0] = 'item0';

menu_ar[1] = 'item1';

menu_ar[2] = 'item2';

menu_ar[3] = 'item3';

menu_ar[4] = 'item4';

menu_ar[5] = 'item5';

menu_ar[6] = 'item6';





function load_menu_rollovers(){

	mro_ar = new Array();

	for (var i=0;i<menu_ar.length;i++){

		mro_ar[menu_ar[i]] = new Array();

		mro_ar[menu_ar[i]]['off']=new Image();

		mro_ar[menu_ar[i]]['on']=new Image();

		mro_ar[menu_ar[i]]['off'].src=imgfolder + "topmn_"+menu_ar[i]+".gif";

		mro_ar[menu_ar[i]]['on'].src=imgfolder +  "topmn_"+menu_ar[i]+"_on.gif";

	}

}



///////

load_menu_rollovers();



function m_rollover(which){

	document.images[which].src =mro_ar[which]['on'].src;

}



function m_rollout(which){

	document.images[which].src =mro_ar[which]['off'].src;

}



function m_move(active){

	if(document.body.clientWidth){

		thewidth = document.body.clientWidth;

	}else if(window.outerWidth){

		thewidth = window.outerWidth;

	}

	thewidth = Math.round((thewidth - 640)/2);

	thewidth += Number(menu_left[active]);

	return thewidth;

}


