/**
 * @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} フラグメント識別子をURL末尾に付けるか否か。falseの場合は付けない。※falseの時は既に入っているものを消したい。
 */
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;
						}*/
					});
					//return (fi == _this.goToPageTop) ? false : true;
					// フラグメント識別子を後付けしてあげる必要あり。
					// ブラウザ別に処理が必要。
					//return true;
					//
				});
			}
		}
	});
}


/* ----------------------------------------------------------------------------------- */
/**
 * サイト内検索フォーム用のプレースホルダ。
 * @class サイト内検索フォーム用のプレースホルダ。
 * @constructor
 */
CBLIB.SearchPlaceholder = function () {

	/** 初期表示時の文字色。
		@type String @constant @private */
	this.d_fcolor = "#8a8a8a";// class attr

	/** 検索キーワード入力後の文字色。
		@type String @constant @private */
	this.fcolor = "#555555";// class attr

	/** 処理対象のフォームのセレクタ、及びキーワードの初期値を格納。targetに対象となる入力フォームを、defaultKeywordに初期キーワードをそれぞれ登録。
		@type Array @constant @private */
	this.formData = [
						{
							target : "#search-keywords",
							defaultKeyword : "サイト内検索"
						},
						{
							target : "#content-txt-search",
							defaultKeyword : "サイト内検索"
						}
					];
//	if () {
		this.init();
//	}
}

CBLIB.SearchPlaceholder.prototype.init = function () {
	var _this = this;
	$.each(_this.formData, function (i) {
		var d_key = this.defaultKeyword;
		$(this.target).each(function () {
			var el = $(this);
			el.css({"color" : _this.d_fcolor})
				.attr({"value"  : d_key});

			el.focus(function () {
				if (el.attr("value") == d_key) {
					el.attr({"value" : ""});
				}
				el.css({"color" : _this.fcolor});
			});

			el.blur(function () {
				if (el.attr("value") == "") {
					el.css({"color" : _this.d_fcolor})
						.attr({"value"  : d_key});
				}
			});
		});

	});
}

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

	if (location.pathname.match(/\/lounge/)) return;

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

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

	/** PDFリンクのノード格納用配列
	    @type Array @private */
	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/JP-H-GET-READER" target="_blank"><img src="/common/images/get_adobe_reader.png" alt="Get Adobe Reader" width="158" height="39" /></a></p>'
							+'	</div>'
							+'	<div class="pdf-text">'
							+'<p>PDFファイルを閲覧・印刷いただくには、アドビシステムズ社の配布している'
							+'<a href="http://www.adobe.com/go/JP-H-GET-READER" target="_blank">Adobe Reader［外部リンク］</a>（無償）を左のリンクより入手し、'
							+'インストールすることが必要となります。Adobe、Adobeロゴ、Reader は、アドビシステムズ社の米国ならびに他の国における商標または登録商標です。</p>'
							+'	</div>'
							+'<!-- /pdf-block-01 --></div>'
							+'</div>';

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

/**
 * 初期化処理。PDFリンクが存在した場合、Adobe Readerバナーを表示。
 * @function
 */
CBLIB.PdfLinkDetection.prototype.init = function () {
	if (this.detectPdfLink()) {
		$("#main-contents").append(this.bannerBlockHTML);
	}
}

/**
 * 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 && href.match(_this.regPdfLink)) {
			_this.pdfLinkNodes.push(this);
			this.setAttribute("target", "_blank");
		}
	});
	return _this.pdfLinkNodes.length ? true : false;
}




/* ----------------------------------------------------------------------------------- */
$(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','')
		
			}
		);
	}
	
});


/* ----------------------------------------------------------------------------------- */
$(function() {
	$("a[href='/rate/rate_r.html']").attr("target", "_blank");
});




/* ----------------------------------------------------------------------------------- */
/**
 * heading-02-03用
 */
$(function() {
		   
	if($(".heading-02-03").length) {
		
		var locationHash = location.hash;
		var target = $(".heading-02-03");
		var closeIcon = "/common/images/com_ic037.gif";
		var openIcon = "/common/images/com_ic038.gif";
		
		//スタイル調整
		$("html").css("overflow-y","scroll");
		$("a",target).css("display","inline");
		$("span",target).css("padding","2px 5px 5px 7px");
		
		//アンカーで飛んできた時の動作
		if(target.is(locationHash)){
			$("div.slide-toggle-area").hide();
			$(locationHash).next().show();
			$("img",target).attr("src",openIcon);
			$("img",locationHash).attr("src",closeIcon);
		}
		
		//開閉動作、アイコンの変更
		$("img",target).click(
			function(){
				if($(this).attr("src") == openIcon){
					$(this).attr("src",closeIcon);
				}
				else if($(this).attr("src") == closeIcon){
					$(this).attr("src",openIcon);
				}
				
				var toggleArea = $(this).parent().parent().parent().next("div.slide-toggle-area");
				toggleArea.animate(
					{height:"toggle"},
					{duration: 700, easing: "easeOutExpo"}
				);	
				
				return false;
			}
		);
	};
});




/* ----------------------------------------------------------------------------------- */
$(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]();
		}
	}

});





/*---------------------------------------------------------------------------*/
/**
 * @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         : "文字サイズを「標準」に変更します",
								titleSelected : "現在選択中の文字サイズは「標準」です"
					},
					"large" : {
								styleId       : "fontsize-large",
								buttonId      : "fontsize-btn-large",
								title         : "文字サイズを「大」に変更します",
								titleSelected : "現在選択中の文字サイズは「大」です"
					}
			}
			,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>');
}



/*マイアクセス用*/
var win1;
function open1() {
	win1 = window.open("https://ib1.chibabank.co.jp/0134chiba/BankContents/CTLOG0A.html","");
}
