/**
 *	@filename		lib.js
 *	@charset		utf-8
 *	@modified		April 6, 2010
 *	@description	共通js
 */
(function(win){



//
//	高速化＠IE
//
var document = window.document;



//
//	名前空間
//
var ns = win.kc3456 = win.kc3456 || {};



//
//	ルート（トップページのindex.htmlがある場所）のパスを取得
//
var s = document.createElement("script"),
	h = document.getElementsByTagName("head")[0];
h.appendChild(s);
h.removeChild(s);
s = h = null;
var rootPath = document.getElementsByTagName("script");
rootPath = rootPath[rootPath.length - 1].src.replace(/\/js\/common\/lib\.js$/, "");


//
//	フォントサイズ変更
//
var FSC=function(){this.id="_FSC_";this.fl={};this.fl.change=[];this.fl.smaller=[];this.fl.larger=[];this.init();this.ir=true;var ms=100,os=this.gcs(),ocs=this.gccs(),me=this;this.timer=setInterval(function(){if(me.ir){var cs=me.gcs(),ccs=me.gccs();if(os!=cs){me.cf("change");if(os>cs){me.cf("smaller");}else if(os<cs){me.cf("larger");}}else if(ocs!=ccs){me.cf("change");if(ocs>ccs){me.cf("smaller");}else if(ocs<ccs){me.cf("larger");}}os=cs;ocs=ccs;}},ms);};FSC.prototype.init=function(){var _de=document.getElementById(this.id);if(_de){this.de=_de;}else{this.de=document.createElement("span");this.de.style.display="block";this.de.style.visibility="hidden";this.de.style.position="absolute";this.de.style.zIndex="-9999";this.de.style.left="-9999px";this.de.style.top="-9999px";this.de.style.margin="0";this.de.style.padding="0";this.de.style.minWidth="1px";this.de.style.minHeight="1px";if(document.all&&!window.opera&&!window.XMLHttpRequest){this.de.style.height="1px";}this.de.style.lineHeight="1em";this.de.style.overflow="visible";this.de.style.fontSize="1000%";this.de.style.textIndent="0";this.de.innerHTML="B";this.de.setAttribute("id",this.id);var body=document.getElementsByTagName("body").item(0);body.appendChild(this.de);}};FSC.prototype.addListener=function(en,f){if(en=="change"||en=="smaller"||en=="larger"){if(typeof f!="function"){return;}else{this.fl[en].push(f);}}};FSC.prototype.cf=function(en){this.ir=false;for(var i=0;i<this.fl[en].length;i++){if(typeof this.fl[en][i]=="function"){(this.fl[en][i])();}}this.ir=true;};FSC.prototype.gcs=function(){return this.de.clientHeight;};FSC.prototype.gccs=function(){if(document.defaultView){return document.defaultView.getComputedStyle(this.de,null).getPropertyValue("font-size");}else{return 0;}};FSC.prototype.removeListener=function(en){if(en=="change"||en=="smaller"||en=="larger"){this.fl[en]=null;}};


//
//	HeightController[ver. October 16, 2009]
//
var HeightController=function(){var self=this;this.isIE=document.all&&!window.opera;this.isFX=navigator.userAgent.indexOf("Firefox")>-1;this.head=document.getElementsByTagName("head")[0];this.count=0;this.elementSet=[];if(this.isIE){this.styleSheet=document.createStyleSheet();}else{this.styleSheet=document.createElement("style");this.head.appendChild(this.styleSheet);}(new FSC()).addListener("change",function(){self.setHeight();});};HeightController.CLASS_NAME_PREFIX="height_controller_";HeightController.prototype.addElements=function(elements){var className=HeightController.CLASS_NAME_PREFIX+this.count;this.count++;this.elementSet.push({elements:elements,className:className});var i=0,len=elements.length;while(i<len){elements[i].className+=(" "+className);i++;}this.setHeight();};HeightController.prototype.setHeight=function(){this.resetHeight();var rules=[];var maxHeight,_h;var i=0,len=this.elementSet.length;while(i<len){maxHeight=_h=0;var j=0,len2=this.elementSet[i].elements.length;while(j<len2){_h=this.calcHeight(this.elementSet[i].elements[j]);maxHeight=maxHeight<_h?_h:maxHeight;j++;}rules.push("."+this.elementSet[i].className+"{height:"+maxHeight+"px!important;}");i++;}if(this.isIE){this.styleSheet.cssText=rules.join("");}else if(this.isFX){this.styleSheet.innerHTML=rules.join("");}else{var k=0;var len3=rules.length;while(k<len3){this.styleSheet.sheet.insertRule(rules[k],k);k++;}}};HeightController.prototype.calcHeight=function(obj){var height=0,padding=0,style;if(this.isIE){style=obj.currentStyle;if(typeof XMLHttpRequest!=="undefined"){padding=parseInt(style.getAttribute("paddingTop"),10)+parseInt(style.getAttribute("paddingBottom"),10);}}else{style=document.defaultView.getComputedStyle(obj,null);padding=parseInt(style.getPropertyValue("padding-top"),10)+parseInt(style.getPropertyValue("padding-bottom"),10);}height=obj.offsetHeight;return height-padding;};HeightController.prototype.resetHeight=function(){if(this.isIE){this.styleSheet.cssText="";}else if(this.isFX){this.styleSheet.innerHTML="";}else{this.head.removeChild(this.styleSheet);this.styleSheet=document.createElement("style");this.head.appendChild(this.styleSheet);}};



//////////////////////////////////////// START OF DOM READY ////////////////////////////////////////

$(function(){



//
//	このページの先頭へボタン動作
//
var scroller = ns.scroller = function(){
	var START = "start",
		END   = "end",
		doc   = document,
		bdy   = doc.body,
		de    = doc.documentElement,
		sto   = setTimeout,
		sct   = scrollTo,
		scrollee,
		handlers = {},
		dispatchEvent = function(typ){
			var arr = handlers[typ] || [];
			for(var i=0, fnc, len=arr.length; i<len; i++){
				(fnc = arr[i]) && fnc.call(utils, { type : typ });
			}
		},
		scroll = function(){
			var y = scrollee.scrollTop;
			sct(0, y = (y << 3) - y >> 3);
			y ? sto(scroll, 16) : dispatchEvent(END);
		},
		utils;
	
	handlers[START] = [];
	handlers[ END ] = [];
	
	return (utils = {
		START : START,
		END : END,
		scroll : function(){
			if( ( scrollee = bdy.scrollTop ? bdy : de ).scrollTop ){
				dispatchEvent(START);
				scroll();
			}
			return false;
		},
		addEventListener : function(typ, fnc){
			var arr = handlers[typ];
			arr && arr.push(fnc);
			return this;
		},
		removeEventListener : function(typ, fnc){
			var arr = handlers[typ] || [],
				i = arr.length;
			while(i--){
				arr[i] === fnc && arr.splice(i, 1);
			}
			return this;
		},
		start : function(fnc){
			return this.addEventListener(START, fnc);
		},
		end : function(fnc){
			return this.addEventListener(END, fnc);
		}
	});
}();

//
//	スクロール用
//
$(".anchorTop a").click(scroller.scroll);
$("#anchorTop a").click(scroller.scroll);



//
//	閉じるボタン
//
$("#buttonClose, .buttonClose").click(function(){
	window.close();
	return false;
});



//
//	IE用objectタグ関係
//
if(document.all && !window.opera){
	$("object").each(function(){
		this.removeAttribute("data");
		this.outerHTML = this.outerHTML;
	});
}



//
//	ポップアップリンク用
//
/*
$(".popup").click(function(){
	window.open(this.href).focus();
	return false;
});
*/




//	ポップアップリンク用
//
$(".popup").click(function(){
	var hrf = this.href,
		prm = hrf.replace(/^[^\?]*(\?.*)?$/, "$1"),
		opt = [];
	prm.replace(/(\w+)=([\d\w]+)/g, function(a, key, val){
		opt.push(key + "=" + val);
	});
	window.open(hrf, "", opt.join(",")).focus();
	return false;
});




//
//	input@type=image & a img マウスオーバー
//
//	マウスオーバー画像（と推測される）画像が存在する場合、マウスオーバー時にsrcを切り替えます。
//
$("input:image, a img").each(function(){
	var self = this,
		src = this.src,
		src_ov = src.replace(/^(.*)(\..*)$/, "$1_ov$2"),
		loader = new Image();
	loader.onload = function(){
		$(self).hover(function(){
			this.src = src_ov;
		},function(){
			this.src = src;
		});
		self = loader.onload = loader = null;
	};
	loader.src = src_ov;
});



//
//	リンクの点線を消す
//
$(document.links).focus(function(){
	this.blur();
});



//
//	(トップで使用)
//

var hc = new HeightController();
$("ul.cells").each(function(){
	hc.addElements( this.getElementsByTagName("dd") );

});





});

///////////////////////////////////////// END OF DOM READY /////////////////////////////////////////

})(this);
