$(function(){
	
	//Flash表示
	$('#flashMovi')
		.flash(
			{
				src: './swf/main.swf',
				width: 550,
				height: 85
			},
			{
				expressInstall: true
			}
		)
	;
	
	//PNG透過処理
	$('img[src$=png]').pngfix();
	
	//各ボタン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/"));
			}
		)
	;
	
	//タイプ検索ボタン
	$("div#search form dd.aim img")
		.click(
			function() {
				//押下されたボタンのname値取得
				button_id = $(this).attr("id");
				hidden_param = "input#"+ button_id;
				
				//押下されたボタンIDがおまかせの場合
				if (button_id == 'entrust') {
					//おまかせ以外のボタンをoff
					$("img:not(#entrust)", "div#search form dd.aim")
						.each(
							function(){
								$(this).attr('src', $(this).attr('src').replace("/check/", "/off/"));
								$("input#"+ $(this).attr("id")).val('0');
							}
						)
					;
				}
				else {
					//おまかせボタンをoff
					$("img#entrust", "div#search form dd.aim").attr('src', $("img#entrust", "div#search form dd.aim").attr('src').replace("/check/", "/off/"));
					$("input#entrust").val('0');
				}
				
				//対応するhiddenパラメータがoffならonにする
				if ($(hidden_param).val() == '0') {
					$(hidden_param).val('1');
					$(this).attr('src',$(this).attr('src').replace("/on/", "/check/"));
//					$(this).attr('src',$(this).attr('src').replace("/off/", "/check/"));
				}
				else {
					$(hidden_param).val('0');
					$(this).attr('src',$(this).attr('src').replace("/check/", "/on/"));
				}
			}
		)
/*
		.each(
			function() {
				//押下されたボタンのname値取得
				button_id = $(this).attr("id");
				hidden_param = "input#"+ button_id;
				
				if ($(hidden_param).val() == '0' || $(hidden_param).val() == '') {
					$(hidden_param).val('0');
					$(this).attr('src',$(this).attr('src').replace("/check/", "/on/"));
				}
				else {
//					$(this).attr('src',$(this).attr('src').replace("/on/", "/check/"));
					$(this).attr('src',$(this).attr('src').replace("/off/", "/check/"));
				}
			}
		)
*/
	;
	
	
	//全選択／リセットボタン
	$("div#search form dl.choice2 dd.control img")
		.click(
			function() {
				if ($(this).attr('alt') == '全選択') {
					var befor_button_type = '/off/';
					var after_button_type = '/check/';
					var hidden_type = '1';
					var befor_button_entrust = '/check/';
					var after_button_entrust = '/off/';
					var hidden_entrust = '0';
				}
				else if ($(this).attr('alt') == 'リセット') {
					var befor_button_type = '/check/';
					var after_button_type = '/off/';
					var hidden_type = '0';
					var befor_button_entrust = '/off/';
					var after_button_entrust = '/check/';
					var hidden_entrust = '1';
				}
				
				//おまかせ以外のボタン
				$("img:not(#entrust)", "div#search form dd.aim")
					.each(
						function(){
							$(this).attr('src', $(this).attr('src').replace(befor_button_type, after_button_type));
							$("input#"+ $(this).attr("id")).val( hidden_type );
						}
					)
				;
				//おまかせボタン
				$("img#entrust", "div#search form dd.aim").attr('src', $("img#entrust", "div#search form dd.aim").attr('src').replace(befor_button_entrust, after_button_entrust));
				$("input#entrust").val( hidden_entrust );
			}
		)
	;

	//Ajaxで大地域の詳細地域を配列で取得、変更
	$("div#send_1 dl dd p select[name='u[area1]']")
		.change(
			function () {
				//ajaxで詳細地域配列を取得
				$.ajax({
					type: "POST",
					data: 'area1=' + $(this).val(),
					url: "./js/ajax_select_area2.php",
					dataType: "script",
					success: function(){
						$("div#send_1 dl dd p select[name='u[area2]']")
							.empty()
						;
						for(keys in columns) {
							$("div#send_1 dl dd p select[name='u[area2]']")
									.append(
										$('<option>')
											.attr({ value: keys })
												.text(columns[keys])
									)
							;
						}
						return true;
					}
				});
			}
		)
	;
	
	//詳細ページwindow.open
	$("div#girls ul.tt li.ll dl a")
		.click(
			function() {
				obj = window.open( $(this).attr('href'), '_blank', 'width=660, height=750, menubar=no, scrollbars=yes, resizable=no, toolbar=no');
				obj.focus();
				return false;
			}
		)
	;
	
	// サブウインドウを閉じるボタン
	$("body#detailed p.shut a, body#detailed div#sendcomp dl dd.close a")
		.click(
			function () {
				window.close();
			}
		)
	;

/*
	//対象ページをロード時にウィンドウをリサイズ
	var match_array = new Array(
		"contact_comp.php",
		"comp.php",
		"send_mb_"
	);
	var page_url = document.URL;
	for (key in match_array) {
		if (page_url.match(match_array[key])) {
			window.resizeTo(700,340);
			break;
		}
	}
	
	//検索ボタン：性別判定(IEだとimageタイプのvalueは送信できないため)
	$("div#search form ul.search_mode_sex li input")
		.click(
			function() {
				var sex = $(this).attr("alt");
				if (sex=='男性検索') {
					submit_mode = '104';
				}
				else {
					submit_mode = '4';
				}
				$("ul.search_mode_sex input:[name='s[sex]']").val(submit_mode);
			}
		)
	;
*/
	
/*
	//詳細ページwindow.open
	$("div.memberBox h4 a")
		.click(
			function() {
				obj = window.open( $(this).attr('href'), '_blank', 'width=620, height=700, menubar=no, scrollbars=yes, resizable=no, toolbar=no');
				obj.focus();
				return false;
			}
		)
	;
	// スポンサー一覧window.open
	$("body#tos.subsize div#main div#subsizeColumn dl dd a")
		.click(
			function() {
				obj = window.open( $(this).attr('href'), 'sp', 'width=600, height=450, menubar=no, scrollbars=yes, resizable=no, toolbar=no');
				obj.focus();
				return false;
			}
		)
	;
	
	// サブウインドウを閉じるボタン
	$("body.subsize div#footer p a")
		.click(
			function () {
				window.close();
			}
		)
	;
*/
});



