jQuery(function(){
	
	//公開終了カウントダウン
	var targetTime = $('#target_date').val();
	var liftoffTime = new Date(targetTime);
	$('span#countDown')
		.countdown({
			until: liftoffTime,
			compact: true,
//			format: 'H時間M分S秒',
			description: ''
		})
	;  
	
	//プロフィール登録性別
	if ($('input[name="u[sex]"]:checked').val() == 'f') {
		$('#form table tr#man').hide();
		$('#form table tr#woman').show();
	}
	else {
		$('#form table tr#man').show();
		$('#form table tr#woman').hide();
	}
	
	$('input[name="u[sex]"]:radio')
		.click(
			function() {
				if ($('input[name="u[sex]"]:checked').val() == 'f') {
					$('#form table tr#man').hide();
					$('#form table tr#woman').show();
				}
				else {
					$('#form table tr#man').show();
					$('#form table tr#woman').hide();
				}
			}
		)
	;
	
	//各ボタンhover
	$("img, input:image")
		.hover(
			function () {
				$(this).attr('src',$(this).attr('src').replace("/off/", "/on/"));
			},
			function () {
				$(this).attr('src',$(this).attr('src').replace("/on/", "/off/"));
			}
		)
	;
	// subページwindow.open（1つ目の要素＝ホームは除く）
	$("#footer a:not(:eq(0)), #navi a:not(:eq(0)), #formBase a, #registIn a")
		.click(
			function() {
				obj = window.open( $(this).attr('href'), 'sub', 'width=450, height=530, scrollbars=no, resizable=no, toolbar=no');
				obj.focus();
				return false;
			}
		)
	;
	// 2ページ目window.open用
	$("#textBox p a.womanRegist")
		.click(
			function() {
				obj2 = window.open( $(this).attr('href'), '_blank' , 'width=450, height=530, scrollbars=no, resizable=no, toolbar=no');
				obj2.focus();
				return false;
			}
		)
	;
	
	// サブウインドウを閉じるボタン
	$("#close a img")
		.click(
			function () {
				window.close();
			}
		)
	;
	
	// 検索プルダウン
	$("form#searchForm select")
		.change(
			function () {
				area_id = $(this).attr('value');
				MediaCode = $("form#searchForm input:hidden").attr('value');
				$("form#searchForm")
					.attr("action","./index.php?s[area1]=" + area_id + "&MediaCode=" + MediaCode)
					.submit()
				;
			}
		)
	;
	
	//Ajaxで大地域の詳細地域を配列で取得、変更
	$("select[name='u[area1]']")
		.change(
			function () {
				//ajaxで詳細地域配列を取得
				$.ajax({
					type: "POST",
					data: 'area1=' + $(this).val(),
					url: "./js/ajax_select_area2.php",
					dataType: "script",
					success: function(){
						$("select[name='u[area2]']")
							.empty()
						;
						for(keys in columns) {
							$("select[name='u[area2]']")
									.append(
										$('<option>')
											.attr({ value: keys })
												.text(columns[keys])
									)
							;
						}
						
						if (!$(this).val()) {
							$("select[name='u[area2]']")
								.append(
									$('<option>')
										.attr({ value: 0 })
											.text('詳細地域')
								)
							;
						}
						
						return true;
					}
				});
			}
		)
		.change()
	;
	
});
