/*
___________________________________________________________

index:
	Detect
	Plugin Check
	Set Class
	Get Class
	Get Yscroll
	Get PageSize
	Add Event
	Change Image
	change font size 14px to 16px
___________________________________________________________*/


/* Detect
____________________________________________________________*/
function BrowserCheck(){
		var b = navigator.appName;
		if (b == "Netscape") this.b = "NN";
		else if (b == "Microsoft Internet Explorer") this.b = "IE";
		else this.b = b;
		this.version = navigator.appVersion;
		this.vSub = navigator.vendorSub;
		this.userAgent = navigator.userAgent;
		this.appVersion = navigator.appVersion;
		this.v = parseInt(this.version);
		this.vs = parseFloat(this.vSub);
		
		this.NN = (this.b == "NN");
		this.NN3 = (this.b == "NN" && this.v == 3);
		this.NN4 = (this.b == "NN" && this.v == 4);
		this.NN6x = (this.b == "NN" && this.v == 5 && this.vs >= 6.01);
		this.NN6 = (this.b == "NN" && this.v == 5);
		this.NN7 = (this.b == "NN" && this.v == 5 && this.vs >= 7);
		
		this.IE = (this.b == "IE");
		this.IE3 = (this.userAgent.indexOf('MSIE 3')>0);
		this.IE45 = (this.userAgent.indexOf('MSIE 4.5')>0);
		this.IE401 = (this.userAgent.indexOf('MSIE 4.01')>0);
		this.IE4 = (this.userAgent.indexOf('MSIE 4')>0);
		this.IE51 = (this.userAgent.indexOf('MSIE 5.1')>0);
		this.IE512 = (this.userAgent.indexOf('MSIE 5.12')>0);
		this.IE514 = (this.userAgent.indexOf('MSIE 5.14')>0);
		this.IE52 = (this.userAgent.indexOf('MSIE 5.2')>0);
		this.IE5 = (this.userAgent.indexOf('MSIE 5')>0);		
		this.IE6 = (this.userAgent.indexOf('MSIE 6')>0);
		
		this.GEK = (this.userAgent.indexOf("Gecko") != -1);
		this.SAF = (this.userAgent.indexOf("Safari",0) != -1);
		this.FF = (this.userAgent.indexOf("Firefox") != -1);
		this.CAB = (this.userAgent.indexOf("iCab",0) != -1);
		this.OPE = (this.userAgent.indexOf("Opera",0) != -1);
		
		this.Win = (this.userAgent.indexOf('Win',0) != -1);
		this.Mac = (this.userAgent.indexOf('Mac',0) != -1);
		this.MacOSX = (this.userAgent.indexOf('Mac OS X',0) != -1);
		if(this.IE512 || this.IE52){
			this.MacOSX=true;
		}
		else if(this.IE514){
			if (navigator.plugins) {
				for (i=0; i < navigator.plugins.length; i++ ) {
					if (navigator.plugins[i].name.indexOf('QuickTime') >= 0 && navigator.plugins[i].filename.indexOf('.plugin')!=-1){
						this.MacOSX=true;
					}
				}
			}
		}
		this.Unix = (this.appVersion.indexOf('X11',0) != -1);
}

var checkB = new BrowserCheck();


/* Flash Plugin Check
____________________________________________________________*/
var flash_version;
var FlashInstalled = false;
var pv = 6;

function ControlVersion(detectVersion) {
	var version = -1;
	var axo;
	var e;

	try {
	   // for ver.7 and later
	   axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
	   version=axo.GetVariable("$version");
	} catch(e) {
	   try {
		   // for ver.6
		   axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
		   version="WIN 6,0,21,0";
		   /*
		   	* GetVariable() crashes player version 6.0.22-29, and
			* players which have those versions throws when access 
			* to AllowScriptAccess
			*/
			axo.AllowScriptAccess="always";
			version=axo.GetVariable("$version");
	   } catch(e) {
		   if (!version.match(/^WIN/)) {
			   try {
				   // for 4.x,5.x
				   axo=null;
				   axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				   // version 3 player throws when you call GetVariale().
				   version=axo.GetVariable("$version");
			   } catch(e) {
				   if (axo) {
					   // for 3.x
					   version="WIN 3,0,18,0";
				   } else {
					   try {
						   // for 2.x
						   axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
						   version="WIN 2,0,0,11";
					   } catch(e) {
						   version="WIN 0,0,0,0";
					   }
				   }
			   }
		   }
	   }
	}
	
	if (version != -1) {
		var version__ = version.split(",");
		return (version__[0].substring(4, version__[0].length) >= detectVersion) ? true : false;
	} else {
		return false;
	}
}

function isenableSWF() {
	if (checkB.OPE) {
		var sp = navigator.plugins["Shockwave Flash"].description.indexOf("Flash");
		var ep = navigator.plugins["Shockwave Flash"].description.lastIndexOf(" ");
		var aver = parseFloat(navigator.plugins["Shockwave Flash"].description.substring(sp+pv,ep));
		if(aver >= flash_version){
			FlashInstalled = true;
		}
	} else if(checkB.Win && checkB.IE){
		/*document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('contentVersion = ' + flash_version + ' \n');
		document.write('FlashInstalled = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & contentVersion))) \n');
		document.write('</SCR' + 'IPT\> \n');*/
		if(checkB.IE4){
			FlashInstalled = false;
		} else {
			FlashInstalled = ControlVersion(flash_version);	
		}
	}else if(checkB.Mac && checkB.IE){
		if(!checkB.IE4 && navigator.plugins["Shockwave Flash"]){
			var sp = navigator.plugins["Shockwave Flash"].description.indexOf("Flash");
			var ep = navigator.plugins["Shockwave Flash"].description.lastIndexOf(" ");
			var aver = parseFloat(navigator.plugins["Shockwave Flash"].description.substring(sp+pv,ep));
			if(aver >= flash_version){
				FlashInstalled = true;
			}
		}
	}else if(checkB.NN && navigator.plugins["Shockwave Flash"]){
		if(checkB.NN7 || checkB.NN6 || checkB.NN6x || checkB.NN4){
			var sp = navigator.plugins["Shockwave Flash"].description.indexOf("Flash");
			var ep = navigator.plugins["Shockwave Flash"].description.lastIndexOf(" ");
			var aver = parseFloat(navigator.plugins["Shockwave Flash"].description.substring(sp+pv,ep));
			if(aver >= flash_version){
				FlashInstalled = true;
			}
		}
	}
}


/* Set Class
____________________________________________________________*/
function setClass(target, cname) {
	var elm;
	if ((typeof target).toLowerCase() == 'string') {
		elm = document.getElementById(target);
	} else {
		elm = target;	
	}
	
	if (document.all) {
		if (navigator.userAgent.indexOf("Opera") != -1) {
			elm.setAttribute('class', cname);
		} else {
			elm.setAttribute('className', cname);
		}
	} else {
		elm.setAttribute('class', cname);
	}
}

/* Get Class
____________________________________________________________*/
function getClassName(target) {
	var elm;
	if ((typeof target).toLowerCase() == 'string') {
		elm = document.getElementById(target);
	} else {
		elm = target;	
	}
	
	if (document.all) {
		if (navigator.userAgent.indexOf("Opera") != -1) {
			return elm.getAttribute('class');
		} else {
			return elm.getAttribute('className');
		}
	} else {
		return elm.getAttribute('class');
	}
}

function setDivClear() {
	var div = document.createElement('div');
	setClass(div, 'clear');
	
	return div;
}

/* Get Yscroll
____________________________________________________________*/
function getYscroll() {
	var yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
  	}
	
	return yScroll;
}

/* Get PageSize
____________________________________________________________*/
function getPageSize(){
	var w, h;
	var arrayPageSize;
	if(window.innerWidth) { 
		w = window.innerWidth; // Mozilla, Opera, NN4
	} else if (document.documentElement && document.documentElement.clientWidth) { // IE
		w = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		w = document.body.clientWidth;
	}	
	
	if(window.innerHeight) {
		h = window.innerHeight; // Mozilla, Opera, NN4
	} else if(document.documentElement && document.documentElement.clientHeight) { // IE
		h = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		h = document.body.clientHeight;
	}
	
	arrayPageSize = new Array(w,h);
	return arrayPageSize;
}


/* Add Event
____________________________________________________________*/
function addEvent(elm, evType, func, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, func, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, func);
		return r;
	} else {
		elm['on' + evType] = func;
	}
}

/* Change Image
____________________________________________________________*/
function cngImg(cimg, fnam) {
	document.images[cimg].src = fnam;
}


/* change font size 14px to 16px // 基準フォントサイズが14pxなとき16pxにする 
____________________________________________________________*/
function fontPatch() {
	if ( document.defaultView.getComputedStyle(document.body,'"').getPropertyValue("font-size") == "14px") {
		document.body.style.fontSize='16px';
	}
}
if ( document.defaultView && document.styleSheets  ) addEvent(window, 'load', fontPatch, false);
