﻿/* ------------------------------------------------------------

	自由に改変してください orz

	by kura07

------------------------------------------------------------ */

/* ------------------------------------------------------------
   コメントの文字色
------------------------------------------------------------ */
function previewCommentColor(){

	var elm = $("color"),
	func = function(){
		if(!b.ie && !b.op) elm.style.color = elm.value;
		$("CommentTextArea").style.color = elm.value;
	};

	addEvent(elm, "keyup", func);
	addEvent(elm, "change", func);

}

/* ------------------------------------------------------------
   テキストエリアの拡張
------------------------------------------------------------ */
var extendCTAobj = {

	// イベントリスナーの登録
	register : function(){
		var textarea = $("CommentTextArea"), elm = $("CommentTextAreaExtend"), body = document.getElementsByTagName("body")[0],
		getY = function(e){
			return b.ie ? e.y + body.scrollTop : e.pageY;
		};

		// 外見
		var s = elm.style;
		s.marginLeft = "127px";
		s.border = "1px solid #555";
		s.width = "127px"; s.height = "5px";
		s.fontSize = "0"; s.overFlow = "hidden";
		s.cursor = "s-resize";
		textarea.style.height = "50px";

		// 選択の回避
		addEvent(elm, "selectstart", function(){event.returnValue=false;});
		addEvent(elm, "mousedown", function(){event.returnValue=false;});
		elm.unselectable = "on";
		s.MozUserSelect = "none";

		// イベントの登録
		addEvent(elm, "mousedown", function(e){

			if(eo.on) return; eo.on = true;
			var originY = getY(e);

			// Chromeのテキストエリア拡大による変化に対応
			if(textarea.style.height.match(/[\d\.]+px/) && eo.nowSize+"px" != textarea.style.height){
				eo.nowSize = Number(textarea.style.height.replace(/[^\d]/g, ""));
			}

			var moveFunc = function(e){
				eo.nowSize += getY(e) - originY; originY = getY(e);
				textarea.style.height = (eo.nowSize > 0 ? eo.nowSize : 1) + "px";
			},
			upFunc = function(e){
				eo.on = false;
				if(eo.nowSize < 1) eo.nowSize = 1;
				delEvent(body, "mousemove", moveFunc);
				delEvent(body, "mouseup", upFunc);
			};

			addEvent(body, "mousemove", moveFunc);
			addEvent(body, "mouseup", upFunc);
		});
	},

	on : false,
	nowSize : 50
};
var eo = extendCTAobj;

/* ------------------------------------------------------------
   画像の繰り返し
------------------------------------------------------------ */
function repeatImg(img, times){
	var prnt = img.parentNode, d = document;

	// 画像の繰り返し
	img.style.width = ((times > 10 ? 10 : times) * 14) + "px";

	// 数字の挿入
	var str = (times > 10 ? "… " : (times == 0 ? "" : " ")) + "(" + times + ")";
	if(img.nextSibling){
		prnt.insertBefore(d.createTextNode(str), img.nextSibling);
	}
	else{
		prnt.appendChild(d.createTextNode(str));
	}
}

/* ------------------------------------------------------------
   タブ
------------------------------------------------------------ */
var tabObj = {
	tabs : [],
	alphas : [0, 0, 0, 0],
	timerIds : [0, 0, 0, 0],
	change : [0, 0, 0, 0],
	maxAlpha : 9,

	changeAlpha : function(i){

		var to = tabObj;

		// タイトルの色
		to.tabs[i].childNodes[0].style.color = (to.change[i] == 1 ? "#0f0" : "#ddd");

		// 可視化
		if(to.alphas[i] == 0 && to.change[i] == 1){
			to.tabs[i].childNodes[1].style.display = "block";
		}

		// alphaの変化
		to.alphas[i] += to.change[i];
		if(to.alphas[i] < 0) to.alphas[i] = 0;
		if(to.alphas[i] > to.maxAlpha) to.alphas[i] = to.maxAlpha;

		// 適用(IE)
		if(to.tabs[i].childNodes[1].filters){
			to.tabs[i].childNodes[1].filters.alpha.opacity = to.alphas[i] * 10;
		}
		// 適用(Firefox)
		else if(b.ff && b.v < 3.5){
			to.tabs[i].childNodes[1].style.MozOpacity = to.alphas[i] / 10;
		}
		// 適用(その他)
		else{
			to.tabs[i].childNodes[1].style.opacity = to.alphas[i] / 10;
		}
		// 終了
		if(to.alphas[i] == 0 || to.alphas[i] == to.maxAlpha){

			to.timerIds[i] = 0;

			// 不可視化
			if(to.alphas[i] == 0){
				to.tabs[i].childNodes[1].style.display = "none";
			}
			return;
		}

		// 続ける
		to.timerIds[i] = setTimeout(function(){to.changeAlpha(i);}, 50);
	},

	contentShowFunc : function(i, v){
		return function(){
			var to = tabObj;

			to.change[i] = v;

			// タイマーがセットされていない
			if(!to.timerIds[i]){
				to.timerIds[i] = setTimeout(function(){to.changeAlpha(i);}, 50);
			}
		};
	},

	attachTabEvent : function(){
		this.tabs = $c("TabTds");
		for(var i=0;i<4;i++){
			this.tabs[i].childNodes[1].style.display = "none";
			addEvent(this.tabs[i], "mouseover", this.contentShowFunc(i, 1));
			addEvent(this.tabs[i], "mouseout", this.contentShowFunc(i, -1));
		}
	}
};

/* ------------------------------------------------------------
   ブラウザ判別
------------------------------------------------------------ */
var b = {
	// http://d.hatena.ne.jp/uupaa/20090603/1244029278 から引用
	v : (function(){
		return window.opera ? (opera.version().replace(/\d$/, "") - 0)
				: parseFloat((/(?:IE |fox\/|ome\/|ion\/)(\d+\.\d)/.
				exec(navigator.userAgent) || [,0])[1]);
	})(),

	ie : "\v" == "v",
	ff : /a/[-1] == "a",
	sf : /a/.__proto__ == "//",
	op : !!window.opera,
	ch : !!navigator.userAgent.match("Chrome")
};
//b.browser = b.ie ? "IE" : b.ff ? "FF" : b.sf ? "SF" : b.op ? "OP" : b.ch ? "CH" : "??";

/* ------------------------------------------------------------
   よく使うやつ
------------------------------------------------------------ */
function $(_){
	return document.getElementById(_);
}
function $c(_){
	if(document.getElementsByClassName){
		return document.getElementsByClassName(_);
	}
	// IEなどへの対策
	else {
		var els = document.getElementsByTagName("*"), rtns = [],
		hasAsElm = function(str, name){
			return str.match(new RegExp("^(?:[A-z_\\-]+ )*"+name+"(?: [A-z_\\-]+)*$"));
		};
		for(var i=0;i<els.length;i++) if(hasAsElm(els[i].className, _)) rtns.push(els[i]);
		return rtns;
	}
}
function addEvent(elm, type, event){
	if(elm.attachEvent) elm.attachEvent("on"+type, event, false);
	else elm.addEventListener(type, event, false);
}
function delEvent(elm, type, event){
	if(elm.attachEvent) elm.detachEvent("on"+type, event, false);
	else elm.removeEventListener(type, event, false);
}
