/**
 * jQuery - Config file
 */
jQuery(function($) {
	/**
	 * Google Analytics
	 */
//	$.GATracker('');

	$(document).bind("contextmenu", function(e) {
		return false;
	});

	/**
	 * Window Open
	 */
	$('a[href^="http"]').not('a[href^="http://'+ location.host +'"]').winOpen();

	/**
	 * Fragment link
	 */
	$('a[href^="#"]').click(function() {
		$('html, body').animate({scrollTop: $($(this).attr('href')).position().top}, 500, 'swing');
		return false;
	});

	/**
	 * Image Rollover
	 */
	$('a img', '.rollover').rollover({speed: 150});
	$('input:image', '#inquiry').rollover({speed: 150});

	(function() {
		var CS = $('#CalendarSelect');
		if (CS.length < 1) return;

		var select = $('<select/>');
		select.append($('<option/>', {
			text: '▼年月を選択して下さい。',
			value: '',
			selected: 'selected'
		}));
		$('a', CS).each(function() {
			var self = $(this);
			select.append($('<option/>', {
				text: self.text(),
				value: this.href
			}));
		});

		CS.after(select);
		CS.hide();
		select.jQselectable({
			style: 'simple',
			height: 250,
			callback: function() {
				location.href = $(this).val();
			}
		});
	})();

	(function() {
		var inquiry = $('#inquiry');

		var birthday = $('#dataBirthday', inquiry);
		if (birthday.length < 1) return;

		var bd = birthday.val().split(/[年月日]/);

		var _option = {
			text: '--',
			value: '',
			'class': 'br'
		};
		var year = $('<select/>').addClass('m_year required').append($('<option/>', _option));
		var month = $('<select/>').addClass('m_day required').append($('<option/>', _option));
		var day = $('<select/>').addClass('m_day required').append($('<option/>', _option));

		var date = new Date;
		var max = date.getFullYear() - 10;
		var min = max - 70;
		var cnt = 0;
		for (; min <= max; min++) {
			var css = '';
			if (++cnt % 7 === 0) css = 'br';
			var selected = '';
			if (min == bd[0]) selected = 'selected';
			year.append($('<option/>', {
				text: min,
				value: min + '年',
				'class': css,
				selected: selected
			}));
		}
		for (var i = 1; i <= 12; i++) {
			var css = '';
			if (i % 6 === 0) css = 'br';
			var selected = '';
			if (i == bd[1]) selected = 'selected';
			month.append($('<option/>', {
				text: i,
				value: i + '月',
				'class': css,
				selected: selected
			}));
		}
		for (var i = 1; i <= 31; i++) {
			var css = '';
			if (i % 7 === 0) css = 'br';
			var selected = '';
			if (i == bd[2]) selected = 'selected';
			day.append($('<option/>', {
				text: i,
				value: i + '日',
				'class': css,
				selected: selected
			}));
		}
		birthday.hide()
			.before(year).before(' 年 ')
			.before(month).before(' 月 ')
			.before(day).before(' 日 ');
		year.jQselectable();
		month.jQselectable();
		day.jQselectable();

		$('#dataStore').jQselectable({
			style: 'simple',
			height: 250
		});

		$('input, textarea', inquiry).focus(function() {
			$(this).addClass('focus');
		}).blur(function() {
			$(this).removeClass('focus');
		});

		$('form', inquiry).submit(function() {
			birthday.val(year.val() + month.val() + day.val());
		});
	})();

});

