jQuery(function(){

/***index******************************/
	// search img
	$(".search ul li img")
		.hover(
			function () {
				var _class = $(this).parent().parent().attr("class");
				$(this).attr("src", 'img/area/'+ _class + '/btn_ov.png');
			},
			function () {
				var _class = $(this).parent().parent().attr("class");
				$(this).attr("src", 'img/area/'+ _class + '/btn.png');
			}
		)
	;
	
	// entry img
	$("div.man dl dd img , div.woman dl dd img")
		.hover(
			function () {
				$(this).attr("src", "img/normal/btn_girl_ov.png");
			},
			function () {
				$(this).attr("src", "img/normal/btn_girl.png");
			}
		)
	;
	
/***list******************************/
	// chara list img
	$(".list ol img")
		.hover(
			function () {
				$(this).attr("src", 'img/common/bg_photo_ov.png');
			},
			function () {
				$(this).attr("src", 'img/common/rollover.gif');
				$(this).attr("src", 'img/common/blank.gif');
			}
		)
	;
	// re img
	$(".list p img")
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_re_ov.png');
			},
			function () {
				$(this).attr("src", 'img/common/btn_re.png');
			}
		)
	;	
	// next img
	$("a[title='次を見る'] img")
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_next_ov.png');
			},
			function () {
				$(this).attr("src", 'img/common/btn_next.png');
			}
		)
	;	
	// back img
	$("a[title='前に戻る'] img")
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_back_ov.png');
			},
			function () {
				$(this).attr("src", 'img/common/btn_back.png');
			}
		)
	;	
	// mail img
	$(".base .send_mail input")
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_sendmail_ov.gif');
			},
			function () {
				$(this).attr("src", 'img/common/btn_sendmail.gif');
			}
		)
	;	

/*** menu ******************************/
	// menu img
	$(".menuTop img")
		.hover(
			function () {
				$(this).attr("src", "img/common/menu1_ov.png");
			},
			function () {
				$(this).attr("src", "img/common/menu1.png");
			}
		)
	;
	$(".menuCompany img")
		.hover(
			function () {
				$(this).attr("src", "img/common/menu2_ov.png");
			},
			function () {
				$(this).attr("src", "img/common/menu2.png");
			}
		)
	;
	$(".menuPrivacy img")
		.hover(
			function () {
				$(this).attr("src", "img/common/menu3_ov.png");
			},
			function () {
				$(this).attr("src", "img/common/menu3.png");
			}
		)
	;
	$(".menuTos img")
		.hover(
			function () {
				$(this).attr("src", "img/common/menu4_ov.png");
			},
			function () {
				$(this).attr("src", "img/common/menu4.png");
			}
		)
	;
	$(".menuContact img")
		.hover(
			function () {
				$(this).attr("src", "img/common/menu5_ov.png");
			},
			function () {
				$(this).attr("src", "img/common/menu5.png");
			}
		)
	;
	
	//ポップアップ－小ウィンドウ用
	$("a.small_pop_up")
		.click(
			function() {
				//リンク先URLを取得
				var uri = $(this).attr("href");
				//ウインドウサイズの定義
				var wid = 200;
				var hei = 250;
				//既にパラメーター（MediaCode）が付加されているかいないかで付加する値を変更
				if (uri.match(/.*?\?.*/)) {
					uri = uri + "&js=on"
				}
				else {
					uri = uri + "?js=on"
				}
				
				//ウインドウを立ち上げる
				obj = window.open(uri, "sponsor", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizeable=0,width="+wid+",height="+hei);
				obj.focus();
				return false;
			}
		)
	;
	
	//ポップアップ
	$("a.pop_up")
		.click(
			function() {
				//リンク先URLを取得
				var uri = $(this).attr("href");
				//ウインドウサイズの定義
				var wid = 420;
				var hei = 570;
				
				//既にパラメーター（MediaCode）が付加されているかいないかで付加する値を変更
				if (uri.match(/.*?\?.*/)) {
					uri = uri + "&js=on"
				}
				else {
					uri = uri + "?js=on"
				}
				
				//ウインドウを立ち上げる
				obj = window.open(uri, "subsize", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizeable=0,width="+wid+",height="+hei);
				obj.focus();
				return false;
			}
		)
	;

	//ポップアップ
	$("a.pop_up2")
		.click(
			function() {
				//リンク先URLを取得
				var uri = $(this).attr("href");
				//ウインドウサイズの定義
				var wid = 420;
				var hei = 570;
				
				//既にパラメーター（MediaCode）が付加されているかいないかで付加する値を変更
				if (uri.match(/.*?\?.*/)) {
					uri = uri + "&js=on"
				}
				else {
					uri = uri + "?js=on"
				}
				
				//ウインドウを立ち上げる
				obj = window.open(uri, "_blank", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizeable=0,width="+wid+",height="+hei);
				obj.focus();
				return false;
			}
		)
	;

/*** subsize ******************************/
	// close img
	$(".close img")
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_close_ov.gif');
			},
			function () {
				$(this).attr("src", 'img/common/btn_close.gif');
			}
		)
	;	
	// send_mail
	$("#entry .send_mail input")
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_w_entry_ov.gif');
			},
			function () {
				$(this).attr("src", 'img/common/btn_w_entry.gif');
			}
		)
	;	
	
	// ポップアップウィンドウを閉じる
	$(".subsize p.close img, #sponsor p.close img")
		.click(
			function() {
				window.close();
			}
		)
	;
	
/*** message_template ******************************/
	// 詳細画面：「定型文から素早くメール作成」ボタン
	$(".template img")
		// ロールオーバー
		.hover(
			function () {
				$(this).attr("src", 'img/common/btn_template_ov.gif');
			},
			function () {
				$(this).attr("src", 'img/common/btn_template.gif');
			}
		)
		// 一覧出現
		.click(
			function () {
				// 要素出現
				$(".select")
					.show()
				;
				
				// IE以外でanimate
				if (!$.browser.msie) {
					$(".select")
						.css({opacity: 0.1})
						.animate({opacity: 1}, 700)
					;
				}
				
				// キャラ画像を非表示
				$(".list").hide();
			}
		)
	;
	
	
	// 一覧を選択したら挿入＆定型文一覧非表示
	$(".select :radio")
		.click(
			function () {
				// 挿入されるメッセージ
				var _message = $(this).parent().text();
				// 挿入エフェクト表現に要する時間
				var _time = 700;
				// 挿入されるメッセージID
				var _messageID = $(this).val();
				
				if (_messageID != 0) {
					var _insertMessage = _message;
				}
				else {
					var _insertMessage = '';
				}
				
				setTimeout( function () { $(".send_message textarea").val(_insertMessage) }, _time );
				
				// 定型文一覧 非表示：IE以外でanimate
				if (!$.browser.msie) {
					$(".select")
						.animate({opacity: 0}, _time)
					;
				}
				// 定型文一覧 非表示：IEの場合は0.3秒後に非表示
				else {
					setTimeout( function() { $(".select").hide() }, _time );
				}
				
				// キャラ画像を0.3秒後に表示
				setTimeout( function() { $(".list").show() }, _time );
				
				//
				_positionX = 415;
				_positionY = 300;
				
				// Insert Effect
				$("#insertMoveBox")
					.show()
					.css(
						{
							opacity: 1,
							right: _positionX + "px",
							top: _positionY + (17*_messageID) + "px"
						}
					)
					.animate(
						{
							opacity: 0.3,
							top: "520px",
							right: "94px"
						}, _time
					)
				.children("textarea")
					.val(_message)
				;
				
				// 挿入用テキストエリアを非表示
				setTimeout( function () { $("#insertMoveBox").hide(); $(".send_message textarea").focus() }, _time );
			}
		)
	;
	
	// メッセージ入力欄フォーカス時イベント
	$(".send_message textarea")
		.focus(
			function() {
				$(this).addClass("focus");
			}
		)
		.blur(
			function() {
				$(this).removeClass("focus");
			}
		)
	;
	
	
/*** area_select ******************************/
	//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])
									)
							;
						}
						return true;
					}
				});
			}
		)
	;


});

