/**
 * @fileOverview *************************
 * @version 0.0.1
 */
/* ----------------------------------------------------------------------------------- */



/**
 * @namespace 
 */
var DSLIB = {};


/* ----------------------------------------------------------------------------------- */

$(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');

});





/*---------------------------------------------------------------------------*/
/**
 * @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>');
}




/* ----------------------------------------------------------------------------------- */
/**
 * サイト内検索フォーム用のプレースホルダ。
 * @class サイト内検索フォーム用のプレースホルダ。
 * @constructor
 */
DSLIB.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 : "#MF_form_phrase",
							defaultKeyword : "サイト内検索"
						},
						{
							target : "#content-txt-search",
							defaultKeyword : "サイト内検索"
						}
					];
//	if () {
		this.init();
//	}
}

DSLIB.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});
				}
			});
		});

	});
}

/* ----------------------------------------------------------------------------------- */

DSLIB.AgreementPolicy = function () {
	this.agreementCBox    = $("#agreement-checkbox");
	this.nextStepBtn     = $("#goto-next-btn");
	this.btnSrc    = "";
	this.btnOffSrc = "";
	this.btnSuffix = "off";
	this.buttons = [];
	this.btnDisabled = false;
	this.form = null;

	this.msg =   "「個人情報の取り扱いについて」をご確認の上、同意いただける場合は\n"
				+"「個人情報の取り扱いに同意」にチェックを入れてから、ボタンを押して\n"
				+"次のページにお進みください。";

	if (this.agreementCBox.length && this.nextStepBtn.length) {
		this.init();
	}
}

DSLIB.AgreementPolicy.prototype.init = function () {
	var _this = this;
	var imgsrc = this.nextStepBtn.attr("src");
	this.btnSrc   = imgsrc;
	this.preloadImage(this.btnSrc);

	var reg = /\.(jpe?g|gif|png)$/i;
	this.btnOffSrc = imgsrc.replace(reg, this.btnSuffix+".$1");
	this.preloadImage(this.btnOffSrc);

	if (!this.agreementCBox.attr("checked")) {
		this.deactivate();
	}

	this.agreementCBox.click(function() {
		if (_this.agreementCBox.attr("checked")) {
			_this.activate();
		}
		else {
			_this.deactivate();
		}
	});

	var formEl = (function(el) {
					return (el.tagName.toLowerCase()=="form") ?
								el :
									(el.parentNode) ?
										arguments.callee(el.parentNode) : null;
				})(this.nextStepBtn.get(0));

	this.form = $(formEl);

	this.nextStepBtn.click(function(e) {
		e.preventDefault();
		if (_this.btnDisabled) {
			alert(_this.msg);
		}
		else {
			_this.form.submit();
		}
	});
}

DSLIB.AgreementPolicy.prototype.activate = function () {
	if (this.nextStepBtn.attr("src") != this.btnSrc) {
		this.nextStepBtn.attr({"src": this.btnSrc});
	}
	//this.nextStepBtn.attr({"disabled": false});
	this.btnDisabled = false;
}

DSLIB.AgreementPolicy.prototype.deactivate = function () {
	if (this.nextStepBtn.attr("src") != this.btnOffSrc) {
		this.nextStepBtn.attr({"src": this.btnOffSrc});
	}
	//this.nextStepBtn.attr({"disabled": true});
	this.btnDisabled = true;
}

DSLIB.AgreementPolicy.prototype.preloadImage = function (path) {
	var img = new Image();
	img.src = path;
	this.buttons.push(img);
}



/* ----------------------------------------------------------------------------------- */
$(function() {

	/* Setup DSLIB  */
	for (module in DSLIB) {
		var obj = DSLIB[module];
		if (obj && typeof obj == "function") {
			new DSLIB[module]();
		}
	}

});
