/**
 * @fileOverview *************************
 * @version 0.0.1
 */
/* ----------------------------------------------------------------------------------- */


/**
 * @namespace 
 */
var CBLIB = {};


/* ----------------------------------------------------------------------------------- */
/**
 * スムーススクロール処理。
 * @class スムーススクロール
 * @constructor
 */
CBLIB.SmoothScroll = function () {

	/** イベントを設定する要素を指定。
	    @type jQuery Object @constant @private */
	this.selector    = $('a[href^=#], area[href^=#]');

	/** 「ページ先頭へ戻る」のリンクの場合は、URLからフラグメント識別子を削除。
	    @type String @constant @private */
	this.goToPageTop = "#header-area";

	/** アニメーション速度
	    @type Number @constant @private */
	this.speed       = 600;

	/** easing用キーワード
	    @type RegExp @constant @private */
	this.easing      = "easeOutExpo";

	/** スクロールさせたくない場合に設定するclass属性値
	    @type String @constant @private */
	this.noScrollCName    = "no-scroll";

	if (this.selector.length) {
		this.init();
	}
}

/**
 * 初期化処理。とび先のid属性を持つ要素が無ければname属性を調べる。
 * ・アンカーリンク移動時の挙動
 * ・とび先がページの最下部付近の場合
 * @function
 * @return {Boolean} 
 */
CBLIB.SmoothScroll.prototype.init = function () {
	var _this = this;
	this.selector.each(function () {
		if (!$(this).hasClass(_this.noScrollCName)) {
			var fi = $(this).attr("href");
			if (fi == "#") return false;
			var el = ($(fi).length) ? $(fi) : $("a[name="+fi.replace(/#/,"")+"]");
			if (el.length) {
				$(this).click(function(e) {
					e.preventDefault();
					var target = el[0];
					$.scrollTo(target, {
						speed: _this.speed,
						easing: _this.easing,
						onAfter: function() {
							if (!fi.match(_this.goToPageTop)) {
								location.href = fi;
							}/*
							else {
								location.href = "./";
							}*/
						}
						/*,
						onAfter: function() {
							return (fi == _this.goToPageTop) ? false : true;
						}*/
					});
				});
			}
		}
	});
}

/* ----------------------------------------------------------------------------------- */

/**
 * PDFリンクの検出し、target="_blank"の設定、及びAdobe Readerバナーの表示
 * @class PDFリンク関連処理
 * @constructor
 */
CBLIB.PdfLinkDetection = function () {

	/** PDFファイルへのリンク検出用
	    @type RegExp @constant @private */
	this.regPdfLink = new RegExp("(\.pdf$|\.pdf#.*)", "i");

	/** PDFファイルへのリンク検出対象ノード
	    @type jQuery Object @constant @private */
	this.targetNode = $("#contents-area a");

	/** Adobe Readerバナーのブロック
	    @type jQuery Object @constant @private */
	this.bannerBlock = $("#pdf-banner-block");

	/** PDFリンクのノード格納用配列
	    @type Array @private */
	this.pdfLinkNodes = [];

	if (this.targetNode.length) {
		this.init();
	}
}

/**
 * 初期化処理。PDFリンクが存在した場合、Adobe Readerバナーを表示。
 * @function
 */
CBLIB.PdfLinkDetection.prototype.init = function () {
	if (this.detectPdfLink() && this.bannerBlock.length) {
		this.bannerBlock.css({"display":"block"});
	}
}

/**
 * PDFリンクを検索し、pdfLinkNodesに格納。その要素にtarget="_blank"を設定。
 * @function
 * @return {Boolean} PDFリンクが存在した場合はtrueを返す。
 */
CBLIB.PdfLinkDetection.prototype.detectPdfLink = function () {
	var _this = this;
	this.targetNode.each(function () {
		var href = $(this).attr("href");
		if (href.match(_this.regPdfLink)) {
			_this.pdfLinkNodes.push(this);
			this.setAttribute("target", "_blank");
		}
	});
	return _this.pdfLinkNodes.length ? true : false;
}


/* ----------------------------------------------------------------------------------- */

CBLIB.PdfLinkDetection = function () {
	this.regPdfLink   = new RegExp("(\.pdf$|\.pdf#.*)", "i");
	this.targetNode   = $("#contents-area a");
	this.pdfLinkNodes = [];
	this.bannerBlockHTML  = ""
							+'<div class="section margin-top-m">'
							+'<div class="pdf-block-01">'
							+'	<div class="pdf-banner">'
							+'		<p><a href="http://www.adobe.com/go/EN_US-H-GET-READER" target="_blank"><img src="/english/common/images/get_adobe_reader.png" alt="Get Adobe Reader" width="158" height="39" /></a></p>'
							+'	</div>'
							+'	<div class="pdf-text">'
							+'		<p>To view PDF files, it is necessary to use Adobe Reader software. Viewers who do not already have this software can click this icon to download it for free.</p>'
							+'	</div>'
							+'<!-- /pdf-block-01 --></div>';
							+'</div>';

	if (this.targetNode.length) {
		this.init();
	}
}

CBLIB.PdfLinkDetection.prototype.init = function () {
	if (this.detectPdfLink()) {
		$("#main-contents").append(this.bannerBlockHTML);
	}
}

CBLIB.PdfLinkDetection.prototype.detectPdfLink = function () {
	var _this = this;
	this.targetNode.each(function () {
		var href = $(this).attr("href");
		if (href.match(_this.regPdfLink)) {
			_this.pdfLinkNodes.push(this);
			this.setAttribute("target", "_blank");
		}
	});
	return _this.pdfLinkNodes.length ? true : false;
}
/*---------------------------------------------------------------------------*/
/**
 * @version  0.0.1_2009-06-29
 * @requires jquery.js
 * @requires styleswitcher.js
 * @requires rollover.js
 */

FONTSIZE_SELECTOR_ENABLED = true;
FONTSIZE_SELECTOR         = null;


if (FONTSIZE_SELECTOR_ENABLED) {

	$(function() {
		var config = {
			className      : "fontsize",
			blockId        : "fontsize-selector",
			buttonsSetting : {
					"default" : {
								styleId       : "fontsize-default",
								buttonId      : "fontsize-btn-default",
								title         : "Text Size: Normal",
								titleSelected : "Text Size: Normal"
					},
					"large" : {
								styleId       : "fontsize-large",
								buttonId      : "fontsize-btn-large",
								title         : "Text Size: Large",
								titleSelected : "Text Size: Large"
					}
			}
			,rollover : new RolloverImages("rollover-fsbutton", "on", "on")
		};

		FONTSIZE_SELECTOR = new FontSizeSelector(config);
	});

	// 
	document.write(''
	+ '<style  type="text/css" media="screen,print">'
	+ '#fontsize-selector {display: block !important;}'
	+ '</style>');
}

/* ----------------------------------------------------------------------------------- */
$(function() {

	/* for IE6 background image flicker */
	if (jQuery.browser.msie && jQuery.browser.version == 6) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}

	/* Setup RolloverImages */
	var roi = new RolloverImages('rollover', 'on');

	/* Setup CBLIB  */
	for (module in CBLIB) {
		var obj = CBLIB[module];
		if (obj && typeof obj == "function") {
			new CBLIB[module]();
		}
	}

});



/* ----------------------------------------------------------------------------------- */
$(function() {

	/* for IE6 horizontal-nav */
	if (jQuery.browser.msie && jQuery.browser.version == 6) {
		$('div.horizontal-nav-01 td,div.horizontal-nav-02 td').hover(
			function() {
				$(this).css('background-color','#ffdede')
			},
			function() {
				$(this).css('background-color','')
		
			}
		);
	}
	
});




