/**
 *	@filename		lib.js
 *	@charset		utf-8
 *	@modified		May 18, 2010
 *	@description	共通js
 */
(function(){



//
//	エイリアス
//
var w = this,
	d = w.document,
	h = d.getElementsByTagName("head")[0],
	b = d.body;



//
//	専用名前空間
//
var c = w.cybele = w.cybele || {};



//
//	ルート（トップページのindex.htmlがある場所）のパスを取得
//
h.removeChild( h.appendChild( d.createElement("script") ) );
var root = d.getElementsByTagName("script");
root = root[root.length - 1].src.replace(/\/js\/common\/lib\.js$/, "");



//
//	フォントサイズ変化検知
//
var FSC = c.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 = c.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);}};



//
//	外部JavaScript読み込み用1
//
var load1 = function(src){
	src = /^https?:\/\//.test(src) ? src : (root + src);
	d.write('<script type="text/javascript", src="' + src + '" charset="utf-8"></script>');
};



//
//	外部JavaScript読み込み用2
//
var load2 = function(src, fnc){
	var s = d.createElement("script"),
		done = false;
	s.src = /^https?:\/\//.test(src) ? src : (root + src);
	s.charset = "utf-8";
	s.onload = function(){
		if(!done){
			done = true;
			fnc();
		}
	};
	s.onreadystatechange = function(){
		if( !done && /^(complete|loaded)$/.test(s.readyState) ){
			done = true;
			fnc();
		}
	};
	h.appendChild(s);
};



//////////////////////////////////////// START OF DOM READY ////////////////////////////////////////

$(function(){



//
//	エイリアス
//
var d   = w.document,
	b   = d.body,
	sct = w.scrollTo,
	sto = w.setTimeout,
	$   = w.$;



//
//	OS・ブラウザ判別
//
var ua = w.navigator.userAgent;
$(b).addClass(
	/windows/i.test( ua ) ? "windows" :
	/mac/i.    test( ua ) ? "mac" :
	"unkwnOs"
).addClass(
	/firefox/i.test( ua ) ? "firefox" :
	/safari/i. test( ua ) ? "safari webkit" : 
	/chrome/i. test( ua ) ? "chrome webkit" : 
	/opara/i.  test( ua ) ? "opera" :
	/msie/i.   test( ua ) ? "ie" :
	"unkwnBrowser"
);



//
//	このページの先頭へボタン動作
//
$(".anchorTop a, #anchorTop a").click(function(){
	var y = d.body.scrollTop || d.documentElement.scrollTop;
	sct(0, y = ((y << 3) - y) >> 3);
	y && sto(arguments.callee, 16);
	return false;
});



//
//	閉じるボタン
//
$("#buttonClose, .buttonClose").click(function(){
	w.close();
	return false;
});



//
//	IE用objectタグ関係
//
if(d.all && !w.opera){
	$("object").each(function(){
		this.removeAttribute("data");
		this.outerHTML = this.outerHTML;
	});
}



//
//	ポップアップリンク用
//
$(".popup").click(function(){
	var name = "popup",
		hrf = this.href,
		src = hrf.replace(/\?.*$/, "").replace(/#.*$/, ""),
		prm = hrf.replace(/^[^\?]*(\?.*)?$/, "$1"),
		typ = src.replace(/^.*\.(.*)/, "$1"),
		opt = [];
	prm.replace(/(\w+)=([\d\w]+)/g, function(a, key, val){
		opt.push(key + "=" + val);
	});
	if( /^(jpe?g|gif|png|bmp)$/i.test(typ) ){
		var nw = w.open("", name, opt.join(",")),
			nd = nw.document,
			title = this.title || "";
		nd.open().write([
			'<?xml version="1.0" encoding="utf-8"?>',
			'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
			'<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">',
				'<head>',
					'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
					'<meta http-equiv="Imagetoolbar" content="no" />',
					'<title>' + title + '</title>',
				'</head>',
				'<body style="text-align:center;margin: 0;padding:10px;">',
					'<img src="' + src + '" alt="" />',
				'</body>',
			'</html>'
		].join("\n"));
		nd.close();
		nw.focus();
	}else{
		w.open(hrf, name, opt.join(",")).focus();
	}
	return false;
});



//
//	input@type=image & a img マウスオーバー
//
//	マウスオーバー画像（と推測される）画像が存在する場合、マウスオーバー時にsrcを切り替えます。
//
var REGEX_SWAP_SRC = /^(.*)(\..*)$/;
var Image = w.Image;
$("input:image, a img").each(function(){
	var self = this,
		src = this.src,
		src_ov = src.replace(REGEX_SWAP_SRC, "$1_ov$2"),
		loader = new Image();
	loader.onload = function(){
		$(self).hover(function(){
			this.src = src_ov;
		},function(){
			this.src = src;
		});
		self = loader = loader.onload = null;
	};
	loader.src = src_ov;
});



//
//	リンクの点線を消す
//
$(d.links).focus(function(){
	this.blur();
});



//
//	偶数奇数
//
$("tbody").each(function(){
	$("tr:even", this).addClass("even");
});
$("dl").each(function(){
	$("dd:even", this).addClass("even");
});



//
//	thickbox
//
load2("/js/plugins/thickbox.js", function(){
	tb_init("a.thickbox");
});



//
//	アクセス解析
//
if( location.hostname === "www.cybele.co.jp" ){
	
	//Google Analytics
	load2( ( document.location.protocol === "https:" ? "https://ssl." : "http://www.") + "google-analytics.com/ga.js", function(){
		try{
			var pageTracker = window.pageTracker = _gat._getTracker("UA-10545448-1");
			pageTracker._trackPageview();
		}catch(err){}
	});
	
	//Yahoo! Analytics
	load2( "http://i.yimg.jp/images/analytics/js/ywa.js", function(){
		var YWATracker = window.YWATracker = YWA.getTracker("1000196651207");
		YWATracker.addExcludeProtocol("file:");
		YWATracker.submit();
	});
}



});

///////////////////////////////////////// END OF DOM READY /////////////////////////////////////////

})();
