(function($){ $(function(){
	/**
	 * jQueryの拡張
	 */
	$.extend({
		/**
		 * Dateオブジェクトを日本語フォーマット文字列で返す
		 */
		formatDate: function(date) {
			return date.getFullYear() + '年'
				+ (date.getMonth()+1) + '月'
				+ date.getDate() + '日';
		},
		/**
		 * クエリストリング用の日付パラメータを生成
		 */
		makeDateParam: function(date) {
			return {
				y: date.getFullYear(),
				m: date.getMonth()+1,
				d: date.getDate()
			};
		}
	});

	/**
	 * jQueryオブジェクトの拡張
	 */
	$.fn.extend({
		/**
		 * selectに対して日付の取得または設定
		 */
		selectDate: function(date) {
			if (date == undefined) {
				return new Date(
					$("select[id$='Year'], select[name$='Year']", this).val(),
					$("select[id$='Month'], select[name$='Month']", this).val()-1,
					$("select[id$='Day'], select[name$='Day']", this).val()
				);
			} else {
				var _date = $.makeDateParam(date);
				var month = ('0' + _date.m.toString()).slice(-2);
				var day = ('0' + _date.d.toString()).slice(-2);
				this.find("select[id$='Year'], select[name$='Year']").val(_date.y).end()
					.find("select[id$='Month'], select[name$='Month']").val(month).end()
					.find("select[id$='Day'], select[name$='Day']").val(day);
				return this;
			}
		},
		/**
		 * datepickerの日本語オプション
		 */
		datepickerJa: function(opts) {
			opts = $.extend(true, {
				bgiframe: true,
				changeMonth: true,
				changeYear: true,
				showMonthAfterYear: true,
				yearSuffix: ''
			}, opts);
			this.datepicker(opts);
		},
		/**
		 * デフォルトオプションつきlightpop
		 */
		lightpopEx: function(opts) {
			opts = $.extend(true, {
				imageBox:		'/common/images/lightbox/lightpop-box.gif',
				imageBorderL:	'/common/images/lightbox/lightpop-border-l.gif',
				imageBorderR:	'/common/images/lightbox/lightpop-border-r.gif',
				imageLoading:	'/common/images/lightbox/lightpop-ico-loading.gif',
				imageBtnPrev:	'/common/images/lightbox/lightpop-btn-prev.gif',
				imageBtnNext:	'/common/images/lightbox/lightpop-btn-next.gif',
				imageBtnClose:	'/common/images/lightbox/lightpop-btn-close.gif',
				imageBlank:		'/common/images/lightbox/lightpop-blank.gif',
				contentFrameType:'border'
			}, opts);
			this.lightpop(opts);
		}
	});
}); })(jQuery);

