/*
 Author : http://www.yomotsu.net
 Licensed under the GNU Lesser General Public License version 2.1
*/

/* ie png
----------------------------------------*/

function yomotsuIePng(){
	if (document.all && !window.opera && !window.XMLHttpRequest && (typeof document.getElementsByTagName("body")[0].style.outline == "undefined"))/* IE+Opera - opera - ie7up - macIE */{
		for (var i = 0; i <document.getElementsByTagName("img").length; i++) { 
		
		if (document.getElementsByTagName("img")[i].getAttribute("src").lastIndexOf(".png") != -1){
			
			var pngSrc = document.getElementsByTagName("img")[i].getAttribute("src");
			var blankSrc = pngSrc.slice(0, pngSrc.lastIndexOf("/")+1) + "png-blank.gif";
			
			document.getElementsByTagName("img")[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngSrc+"')";
			document.getElementsByTagName("img")[i].setAttribute("src",blankSrc);
			
			}
		}
	}
}

addEvent(window, 'load', yomotsuIePng);

/* IE BG png
----------------------------------------*/

function yomotsuIeBgPng(){
	if ((typeof document.documentElement.style.filter != "undefined")&&(typeof document.documentElement.style.msInterpolationMode == "undefined"))/* IE5.5&6*/ {
		element = document.getElementsByTagName("*");
		for(i=0;i<element.length;i++){
			bgImg = element[i].currentStyle.getAttribute("backgroundImage");
			bgRepeat = element[i].currentStyle.getAttribute("backgroundRepeat");
			bgRepeat="repeat"?"scale":"crop";
			
			if(bgImg.lastIndexOf(".png")!=-1){
				bgSrc = bgImg.slice(5,-2);
				element[i].style.backgroundImage = "none";
				element[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="+bgRepeat+",src='"+bgSrc+"')";

			}
		}
	}
}

addEvent(window, 'load', yomotsuIeBgPng);

/* rollover
----------------------------------------*/

function yomotsuRollover() {
	
	var img = document.getElementsByTagName("img");
	
	for(i=0;i<img.length;i++){

		var src   = img[i].getAttribute("src");
		var ftype = src.substring(src.lastIndexOf("."), src.length);
		
		if(new RegExp("_n"+ ftype + "\\b").exec(src)) {
			
			img[i].onmouseover = function() {
				if(this.style.filter){/*for IE5.5-6 && png*/
					roSrc = this.style.filter.slice(this.style.filter.indexOf("src='")+5,-8)+"_r.png"
					this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop,src='"+roSrc+"')";
				}
				else {
					var curSrc   = this.getAttribute("src");
					var curFtype = curSrc.substring(curSrc.lastIndexOf("."), curSrc.length);
					this.setAttribute("src", curSrc.slice(0, -1*(curFtype.length + 2)) + "_r" + curFtype);
				}
			}	
			
			img[i].onmouseout = function() {
				if(this.style.filter){/*for IE5.5-6 && png*/
					outSrc = this.style.filter.slice(this.style.filter.indexOf("src='")+5,-8)+"_n.png"
					this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop,src='"+outSrc+"')";
				}
				else {
					var curSrc   = this.getAttribute("src");
					var curFtype = curSrc.substring(curSrc.lastIndexOf("."), curSrc.length);
					this.setAttribute("src", curSrc.slice(0, -1*(curFtype.length + 2)) + "_n" + curFtype);
				}
			}
		}
	}
}

addEvent(window, "load", yomotsuRollover);

/* striped table
----------------------------------------*/

function yomotsuStripedTable(){
	var table = document.getElementById("article").getElementsByTagName("table");

	for(i=0;i<table.length;i++){
		var tr = table[i].getElementsByTagName("tr");
		
		var thead="yes";
		for(ii=0;ii<tr[0].childNodes.length;ii++){
			thead = tr[0].childNodes[ii].tagName=="TD" ? "no" : "yes";
		}
		
		if(thead=="no"){
			for(ii=0;ii<tr.length;ii++){
				tr[ii].className += ii%2==0 ? " odd" : " even";
			}
		}
		
		else{
			for(ii=1;ii<tr.length;ii++){
				tr[ii].className += ii%2==1 ? " odd" : " even";
			}
		}
	}
}

addEvent(window, 'load', yomotsuStripedTable);

/* Open new win
----------------------------------------*/


yomotsuOpenWinConf = {
	className : "external",//リンク先を別ウインドウで開きたいa要素につけるclass名
	fileTypes : ["pdf","doc","xls","ppt"]//リンク先を別ウインドウで開きたいファイルの拡張子
}

var fileTypesReg = "";
for(i = 0; i <yomotsuOpenWinConf.fileTypes.length; i++){
	fileTypesReg += "."+yomotsuOpenWinConf.fileTypes[i]+"|"
}
fileTypesReg=fileTypesReg.slice(0, -1);

function yomotsuOpenWin() {
var a = document.getElementsByTagName("a");
	for (i = 0; i <a.length; i++) {
		if (new RegExp("\\b" + yomotsuOpenWinConf.className + "\\b").exec(a[i].className)||
		(new RegExp(fileTypesReg).exec(a[i].getAttribute("href")))){

			a[i].onclick = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			a[i].onkeypress = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			
		}
		
		if(new RegExp("details").exec(a[i].className)) {

			a[i].onclick = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "width=700, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			a[i].onkeypress = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "width=700, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			
		}
	}
	
	var area = document.getElementsByTagName("area");
	for (i = 0; i <area.length; i++) {
		if (new RegExp("\\b" + yomotsuOpenWinConf.className + "\\b").exec(area[i].className)||
		(new RegExp(fileTypesReg).exec(area[i].getAttribute("href")))){

			area[i].onclick = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			area[i].onkeypress = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			
		}
		
			if(new RegExp("details").exec(area[i].className)) {

			area[i].onclick = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "width=700, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
			area[i].onkeypress = function() {
				var href = this.getAttributeNode("href").value;
				this.setAttribute("href","javascript:;");	
				window.open(href, "", "width=700, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, close=yes");
				this.setAttribute("href",href);
				return false;
			}
		}
	}
}

addEvent(window, 'load', yomotsuOpenWin);



/* font-size change
----------------------------------------*/
var fontSizeState = "m";//m,l
var defoFontSize  = "";//m,l
var aaaaa  = "m";//m,l


function largeFontSize(){

	var documentBody = document.getElementsByTagName("body")[0];
	var fontSizeUnit = "";
	
	if(document.defaultView){
	fontSize=document.defaultView.getComputedStyle(documentBody, '').getPropertyValue("font-size");
	}
	else{
	fontSize=documentBody.currentStyle.getAttribute("fontSize");
	}
	
	var defoFontSize = fontSize;
	
	if(fontSize.lastIndexOf("px")!=-1){
	fontSize=fontSize.slice(0,-2);
	sizeUnit="px"
	}
	else if(fontSize.lastIndexOf("%")!=-1){
	fontSize=fontSize.slice(0,-1);
	sizeUnit="%"
	}
	

	if(fontSizeState=="m"){
		documentBody.style.fontSize=fontSize*1.25+sizeUnit;
		//document.cookie = "jointGroupFontSize=l-"+defoFontSize.length+"-"+defoFontSize+";expires=Sun, 1 Mar 2100 00:00:00 UTC";
		fontSizeState = "l";
	}

}

function middleFontSize(){
	var documentBody = document.getElementsByTagName("body")[0];
	
	//var fSizeChangeValue = document.cookie.slice(document.cookie.indexOf("jointGroupFontSize=")+19,20)
	if(fontSizeState=="l"){
		documentBody.style.fontSize=defoFontSize;
		//document.cookie = "jointGroupFontSize=m-"+defoFontSize.length+"-"+defoFontSize+";expires=Sun, 1 Mar 2100 00:00:00 UTC";
		fontSizeState = "m";
	}
}


//alert(arr)


/* --  

function ifDefoLSize(){
	var fSizeChangeValue = document.cookie.slice(document.cookie.indexOf("jointGroupFontSize=")+19,20)
	
	if(fSizeChangeValue=="l"){
		fLength=document.cookie.slice(document.cookie.indexOf("jointGroupFontSize=")+21,22);
		defoFontSize=document.cookie.slice(23,23+eval(fLength));
		alert(defoFontSize)
		
	}
}

addEvent(window, 'load', ifDefoLSize);



/* backToTop
----------------------------------------*/

backToTopBootConf = {
	topFlag : "#header"
}

function yomotsuBackToTopBoot(){
	var a = document.getElementsByTagName("a");
	for(i=0;i<a .length;i++){
		if(new RegExp(backToTopBootConf.topFlag + "\\b").exec(a[i].getAttribute("href"))) {
			
			a[i].onclick = function(){
				this.removeAttribute("href")
				backToTop();
				this.setAttribute("href",backToTopBootConf.topFlag);
				return false;
			}
		}
	}
}


function backToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;

	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}

	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}

	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;

	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));

	window.scrollTo(Math.floor(x / 1.3), Math.floor(y / 1.3));

	if (x > 0 || y > 0) {
		window.setTimeout("backToTop()", 25);
	}
	else if (navigator.userAgent.indexOf("AppleWebKit") == -1){
		location.href = backToTopBootConf.topFlag;
	}
		
}

addEvent(window, 'load', yomotsuBackToTopBoot);


/* add event
----------------------------------------*/

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		return false;
	}
}
