//文字サイズ変更
function setActiveStyleSheet(title, b) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	if(b) hf(b);
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
			) return a.getAttribute("title");
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else expires = "";
	document.cookie = name + "=" + value+expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i< ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if(c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onunload = function() {
	try{
		var title = getActiveStyleSheet();
		createCookie("style", title, 365);
	}catch(e){}
};

var cookie = readCookie("style");
var title  = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

//文字サイズ変更表示スクリプト
function sizechange() {
	document.write('<div id="size-change">');
	document.write('<ul>');
	document.write('<li id="ttl">文字サイズ変更：</li>');
	document.write('<li id="small"><a href="javascript:void(0)" onclick="setActiveStyleSheet(\'small\',this);return false;">小</a></li>');
	document.write('<li id="medium"><a href="javascript:void(0)" onclick="setActiveStyleSheet(\'default\',this);return false;">中</a></li>');
	document.write('<li id="large"><a href="javascript:void(0)" onclick="setActiveStyleSheet(\'large\',this);return false;">大</a></li>');
	document.write('</ul>');
	document.write('</div>');
}
function hf(a) {
	a.hideFocus = true;
}

//focusで背景色
var colorful = new ColorfulInput;
	colorful.skip = ['submit'];
	colorful.color['focus'] = '#ffc';

function ColorfulInput() {
	this.skip  = [];
	this.color = { 'blur': '', 'focus': '#ffc' };
	this.set   = function() {
		for (var i = 0; i < document.forms.length; i++) {
			for (var f = 0; f < document.forms[i].length; f++) {
				var elm = document.forms[i][f];
				if(!this._checkSkip(elm)) continue;
				this._setColor(elm, 'focus');
				this._setColor(elm, 'blur');
			}
		}
	}
	this._checkSkip = function(elm) {
		for(var i in this.skip) {
			if(elm.type == this.skip[i]) return false;
		}
		return true;
	}
	this._setColor = function(elm, type) { 
		var color = this.color[type];
		var event = function() { elm.style.backgroundColor = color; };
		if(elm.addEventListener) {
			elm.addEventListener(type, event, false);
		} else if(elm.attachEvent) {
			elm.attachEvent('on'+type, event);
		} else {
			elm['on'+type] = event;
		}
	}
}

//NewMark
function newMark(y,m,d) {
	oldDay = new Date(y + "/" + m + "/" + d);
	newDay = new Date();
	n      = (newDay - oldDay) / (1000 * 60 * 60 * 24);
	if(n<=5){
		document.write('<img src="../img/new.gif" width="21" height="9" alt="NEW!" />');
	}
}

//記事折りたたみ
function showhide() {
	if(document.classNames('showhide').style.visibility == 'visible') {
		document.getElementByClass('showhide').style.visibility = 'hidden';
		document.getElementById('showhide').value = '表示する';
	} else {
		document.getElementById('showhide').style.visibility = 'visible';
		document.getElementById('showhide').value = '表示しない';
	}
}
//html部分
//<input type="button" name"button" id="showhide" value="表示" onclick="showhide();" />
//(or <a onclick="showhide();">表示・非表示切り替え</> )
//<p id="showhide" style=2visuality="hidden">・・・</p>
//
//記事折りたたみ
function togglediv(divid) {
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
	} else {
		document.getElementById(divid).style.display = 'none';
	}
}

//smooth.pack.js
eval((function(){a="Scroller={speed:10,8dC.;d.while(dC.+C.}} J8N;d=5;&&M4M}d&&dM4dM}%4%} 0J8a,F4(F,fa@7a.4a.LP+F7Jend8e66.cancelBubble=true;6.Value=fa@;}&&(E(7J8di=Hner3||5.G3;hN.3;a=(Ed>ah-d>i7e@{-(h-d)7}e@{a=a+(d-a}To(0,aEa==a}=aJHit8KwHdow,A,A7,A82P;l=9;d=locatiP;D&&D.HdexOfL#)!=-1&&(l/+l=C)Kl,Gck,endEl.PGck=2l=this.hash.substr(1E9.name==l;i=setILL+(9)+),107}}}}}};Hit()",b=48;while(b>=0)a=a.replace(new RegExp("%23456789@ACDEFGHJKLMNP".charAt(b),"g"),("\042Scroller.entfunction(offsetParscrollwindow.returndocumattachEvntervala=.getElemsByTagName(a);if(offsetTop){for(i=0;i<a.length;i++.pathnamea+=Math.ceil((d-ae.stopPropagationTopa.addEvListenerbody)/speede.prevDefaultclearI(i)pageYOffsetend(this);Height .Elemev)}:a[i]lseload=dl.href);b,dcliin},((.=.=C||on".split(""))[b--]);return a})())

//flash表示用スクリプト
function swf_Write(path,bgcolor,w,h,vars){
	if(typeof vars == "undefined"){ vers = ""; }
	var tagStr =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + w + '" height="' + h + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0">'
				+ '<param name="allowScriptAccess" value="sameDomain" \/>'
				+ '<param name="movie" value="' + path + '" \/>'
				+ '<param name="salign" value="lt" \/>'
				+ '<param name="quality" value="high" \/>'
				+ '<param name="bgcolor" value="' + bgcolor + '" \/>'
				+ '<param name="wmode" value="transparent">'
				+ '<param name="flashvars" value="' + vars + '" \/>'
				+ '<embed src="' + path + '" name="fContent" flashvars="' + vars + '" salign="lt" bgcolor="' + bgcolor + '" wmode="transparent" width="' + w + '" height="' + h + '" quality="high" align="middle" play="true" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" \/>'
				+ '<\/object>';
	document.write(tagStr);
}

//target="_blank"
function BlankLinks(){
	if(!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for(var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if(anchor.className.indexOf("blank",0) >= 0){
			anchor.target = "_blank";
		}
	}
}

//切り替えタブ用スクリプト
var TabMaker = Class.create()
	TabMaker.prototype = {
		initialize: function() {
			this.tabLnegth = document.getElementsByClassName('tab').length;
		},
		create: function() {
			var menu = new TabIndex();
			for (var i = 0; i < this.tabLnegth; i++) {
				menu.appendTab(new Tab('Tab' + i, (i==0)));
			}
			menu.setTab();
		}
	}
var Tab = Class.create();
	Tab.prototype = {
		initialize: function(name, open) {
			this.name = name;
			this.page = name + 'Page';
			this.open = (open);
		},
		styleTab: function() {
			if (this.open) {
				this.setStyle('block', '', 'open');
			} else {
				this.setStyle('none', 'absolute', 'close');
				this.open = false;
			}
		},
		setStyle: function(display, position, className){
			var page = $(this.page).style;
			var name = $(this.name);
			page.display   = display;
			page.position  = position;
			name.className = className;
		}
	}
var TabIndex = Class.create();
	TabIndex.prototype = {
		initialize : function() {
			this.last = 0;
			this.tabs = new Array();
		},
		getTabAt : function(index) {
			return this.tabs[index];
		},
		appendTab : function(tab) {
			this.tabs[this.last] = tab;
			document.getElementsByClassName('tab')[this.last].id = tab.name;
			document.getElementsByClassName('box')[this.last].id = tab.page;
			this.last++;
			$(tab.name).onclick = function(){
				tab.open = true;
				this.setTab();
			}.bind(this);
		},
		getLength : function() {
			return this.last;
		},
		each : function(func) {
			for (var i = 0; i < this.getLength(); i++) {
				func(this.getTabAt(i));
			}
		},
		setTab: function() {
			this.each(function(tab) {
				tab.styleTab();
			});
		}
	};

/*--------------------------------------------------------------------------------*
 *  heightLine JavaScript Library beta4(ブロック要素の高さをそろえるスクリプト)
 *  MIT-style license. 
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *------------------------------------------------------------------------------*/
new function(){
	function heightLine(){
		this.className="height";
		this.parentClassName="heightparent"
		reg = new RegExp(this.className+"-([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/\s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}

		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;

		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}

		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}

	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}

	}
	addEvent(window,"load",heightLine);
}

window.onload = function(){
	try{
		colorful.set();
		BlankLinks();
	}catch(e){}
};
