//browser check object & fontdetection
//copyright Youjirou Hisano
//h@hsn4.org


function lib_bwcheck(){ 
	this.ver=navigator.appVersion
	this.name=navigator.appName
	this.agent=navigator.userAgent

	this.major = parseInt(this.ver);
	this.minor = parseFloat(this.name);

	this.dom=document.getElementById?1:0;

	this.opera=(navigator.userAgent.indexOf("Opera")>-1 && !this.ie6)?1:0

	this.ie4=(document.all && !this.dom)?1:0;       //ie4
	this.ie6=(this.agent.indexOf("MSIE 5")>-1 || this.agent.indexOf("MSIE 6")>-1)?1:0;        //IE5,6,Opera include
 	this.ie=(this.ie4 || this.ie6);  //最近のIEすべて含む

	this.moz=(this.agent.indexOf("Gecko")>-1 && this.dom)?1:0;
	this.ns6=(this.name.match("Netscape") && this.dom)?1:0;                                //mozilla include
	this.ns4=(document.layers)?1:0;

	this.mac=  (this.ver.indexOf("Mac") != -1) ? 1:0;
	this.win = (this.ver.indexOf("Win") != -1) ? 1:0;
	this.linux = (this.ver.indexOf("X11") != -1) ? 1:0;

	this.old = (this.ver.indexOf("2")>-1 || this.ver.indexOf("3")>-1);

	this._flash_currentver = 10; // for future version
	this._checkflashinstalled = BrowserCheckFlashInstalled;	
	this.flash6 = this._checkflashinstalled(6);
	this.flash5 = this._checkflashinstalled(5);
	this.flash4 = this._checkflashinstalled(4);



  return this
}


		function BrowserCheckFlashInstalled(version) {
			if(this.mac && this.ie4) return true;
			if(this.opera) return true;
			
			flashinstalled = 'false';
			if(this.ie && this.win) {
				var str = "";
				for(var i=version; i<=this._flash_currentver; i++)
				{
					str += 'IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.' + version + '\"))';
					if(i!=this._flash_currentver) str += " Or ";
				}
				document.writeln('<script language=\"VBscript\">');
				document.writeln('on error resume next');
				document.writeln('flashinstalled = ' + str);
				document.writeln('<\/script>');
			/*
			} else if(
				navigator.mimeTypes["application/x-director"] != null &&
				navigator.plugins["Shockwave for Director"] != null) {
					navigator.mimeTypes["application/x-director"] != null &&
					navigator.plugins["Shockwave for Director"] != null) {
					var desc = navigator.plugins["Shockwave for Director"].description;
					if(eval(desc.charAt(desc.indexOf("version",0)+"version ".length)) >= 7) flashinstalled  = 'true';
			*/
			} else {
				for(var i=0; i<navigator.plugins.length; i++)
					if(navigator.plugins[i].name == 'Shockwave Flash')
					{
						var desc = navigator.plugins["Shockwave Flash"].description;
						if(eval(desc.charAt(desc.indexOf("Flash",0)+"Flash ".length)) >= version) flashinstalled  = 'true';
					}
			}
			return eval(flashinstalled);
		}



bw=new lib_bwcheck()



//font detection
	if (bw.mac) {
		if (bw.dom || bw.ie4){
			fName = "css_mac_dom.css";
		} else if (bw.ns4){
			fName = "css_mac_ns4.css";
		}
	}else if(bw.win){
		if (bw.dom || bw.ie4) {
			fName = "css_win_dom.css";
		} else if (bw.ns4){
			fName = "css_win_ns4.css";
		}
	}else if(bw.other){
	fName = "css_win_dom.css";
	}


if (fName != null) {
	document.write('<link rel=\"stylesheet\" href=\"' + CSSdir + '' + fName + '\" type=\"text/css\" title=\"fontproperty\">');
}







var nvDoa = 0,   nvDol = 0,   nvDog = 0,   nvOs = 0,    nvMW = 0,    nvMH = 0,   nvVsn = 1
if (document.all) nvDoa = 1;   if (document.layers) nvDol = 1;   if (!document.all && document.getElementById) nvDog = 1
nvUtC= navigator.userAgent.toUpperCase();   nvAPP = navigator.appVersion;   nvUA = navigator.userAgent;
if (nvUtC.indexOf("MAC") >= 0) nvOs="mac"; if (nvUtC.indexOf("WIN") >= 0) nvOs="win"
nvMW = screen.width;   nvMH = screen.height;   
if ((nvDol) || (nvDog)){
	snvAPP = nvAPP.indexOf(" ",0);   nvVsn = eval(nvAPP.substring(0, snvAPP));   if (nvVsn >= 5) nvVsn++;   if (nvUA.indexOf("6/6.0") >= 0) nvVsn = 1;
} if (nvDoa){
	snvAPP = nvUA.indexOf("MSIE ",0)+5;   snvUA = nvUA.indexOf(";",snvAPP);   nvVsn = eval(nvUA.substring(snvAPP, snvUA))
}


aNewWindow = new Array();   sNWinCnt = 0
function knNWin(j, k, l, m){
	var cX, cY;   var cW = k;   var cH = l;   var scTgl=0;   if (m) scTgl=1;   var winNm="";   if (nvDol) winNm="view"+sNWinCnt
	cX = (nvMW - cW) / 2;   cY = (nvMH - cH) / 2;
	if (!nvDol) {if (aNewWindow[sNWinCnt-1]) {  if (!aNewWindow[sNWinCnt-1].closed) {aNewWindow[sNWinCnt-1].close() }}}
	aNewWindow[sNWinCnt] = window.open (j+".html",winNm,"left="+cX+",top="+cY+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scTgl+",resizable="+scTgl+",width="+k+",height="+l); 
	aNewWindow[sNWinCnt].focus()
	sNWinCnt++
}
