// 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<10;i++){
		mDiv['m' +i] = new lib_obj('m' +i);
	}
}

function get_menus() {
	// requires a global "rootpath" variable
	// menu items
	var mitems = new Array(
		"2008年のごあいさつ　,プロフィール　　　　　,あけぼのネットワークの紹介,あけぼのヤング　　　　,入会案内　　　　　　　,各県連絡先　　　　　　",
		"",
		"講演会報告　　　　　　,全国大会　　　　　　　,母の日キャンペーン　　,ABCEF　　　　　,病院訪問ボランティア　",
		"",
		"あけぼのショップ　　　,AKEBONO NEWS　　　　,乳がんディクショナリー,私のカルテ　　　　　　",
		"乳がん月間とは？　　　,全国協賛病院リスト　　",
		"ワットさんの笑って長生き,SEIKOのページ　　　　 ,ナースの嘆き　　　　　,再発患者の治療日記,シリーズ再発(1)-井上さんの場合,シリーズ再発(2)-広岡さんの場合,シリーズ再発(3)-楠井さんの場合,シリーズ再発(4)-新川さんの場合",
		"",
		"",
		""
	);


	// 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/introduction/09.html,contents/introduction/index.html,contents/introduction/07.html,contents/introduction/03.html,contents/introduction/05.html,contents2/introduction/06.html",
		"",
		"/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=1,contents/introduction/02g.html,contents/introduction/02d.html,contents/introduction/abcef.html,contents/introduction/02a.html",
		"",
		"contents/publication/index.html,contents/publication/01.html,contents/publication/03.html,contents/publication/04.html",
		"contents/monthly/index.html,contents/monthly/02.html",
		"/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=0,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=2,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=3,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=4,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=5,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=6,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=7,/cgi-bin/akebono/voicebacknum.cgi?qn=0&type=8",
		"",
		"",
		""
	);
	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='white'>");
			document.write(subitems[j]);
			document.write("</font></a></td></tr>");
		}
		document.write("</table>");
	}
}

//menu left
menu_left = new Array();
menu_left = ["0","114","174","244","302","395","468","527","594","665"]

// 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';	
menu_ar[7] = 'item7';
menu_ar[8] = 'item8';
menu_ar[9] = 'item9';


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 - 750)/2);
	thewidth += Number(menu_left[active]);
	return thewidth;
}
