jQuery(function(){

	//ポップアップその1
	$("a.small_pop_up")
		.click(
			function() {
				//リンク先URLを取得
				var uri = $(this).attr("href");
				//ウインドウサイズの定義
				var wid = 200;
				var hei = 250;
				
				//ウインドウを立ち上げる
				obj = window.open(uri, "sponsor", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizable=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;
				
				//ウインドウを立ち上げる
				obj = window.open(uri, "subsize", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizable=0,width="+wid+",height="+hei);
				obj.focus();
				return false;
			}
		)
	;
	
	// girls pop up
	$("#girlsList a")
		.click(
			function() {
				if ($(this).attr("href").indexOf("detail.php", 0) > 0) {
					//リンク先URLを取得
					var uri = $(this).attr("href");
					//ウインドウサイズの定義
					var wid = 600;
					var hei = 900;
					
					//ウインドウを立ち上げる
					obj = window.open(uri, "girlDetail", "directories=0,location=0,menubar=0,status=0,toolbar=0,scrollbars=yes,resizable=yes,width="+wid+",height="+hei);
					obj.focus();
					return false;
				}
			}
		)
	;
	
	// ポップアップウィンドウを閉じる
	$(".subsize p.close img, #sponsor p.close img")
		.click(
			function() {
				window.close();
			}
		)
	;
	
	// 外部リンクのアンカーが押された場合新規ウインドウ
	$("a")
		.click(
			function () {
				//URLを取得
//				var uri = $(this).attr("href").match(/^https?:\/\/.*$/);
				var uri = $(this).attr("href").match(/^.*?\/r\/\?id=.*$/);
				//もし外部リンクの場合はポップアップ
				if (uri) {
					obj = window.open(uri, "_blank");
					obj.focus();
					return false;
				}
				else {
					return true;
				}
			}
		)
	;
	
	//フッターリンクのポップアップ
	$("#footer ul li a, .regist #quickEntry table a:last" )
		.click(
			function() {
				//サイトマップの場合はなにもしない
				if ($(this).attr("title") == 'サイトマップ') {
					return true;
				}
				
				//uriを取得
				var uri = $(this).attr("href");
				//ウインドウを立ち上げる
				obj = window.open(uri, "subsize", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizeable=0,width=500,height=600");
				obj.focus();
				return false;
				
			}
		)
	;
	
	//キャラ詳細から規約へのリンクを踏んだ場合
	$("input:checkbox[name='u[agree][1]']")
		.next("a")
			.click(
				function() {
					//uriを取得
					var uri = $(this).attr("href");
					//ウインドウを立ち上げる
					obj = window.open(uri, "subsize", "directories=0,location=0,menubar=0,status=0,toolbar=0,resizeable=0,width=500,height=600");
					obj.focus();
					return false;
					
				}
			)
	;
	
	//サブサイズ閉じるボタン
	$(".subsize img[alt='閉じる']")
		.css("cursor","pointer")
		.click(
			function () {
				window.close();
			}
		)
	;
	
	//ブックマークボタン
	$(".vote dd img")
		.click(
			function () {
				// アクセス成功時に実行する関数
				var successCallback = function(response) {
					waitTime = 700;
//					setTimeout(function(){$(".voteComp").show();}, waitTime);
//					setTimeout(function(){$(".vote").hide();}, waitTime);
					setTimeout(function(){$(".vote").replaceWith(response);}, waitTime);
				};
				
				// リクエストを投げる
				$.ajax(
					{
						'type':     "POST",
						'url':      "./point_up.php",
						'data':     {'id': jQuery.url.param("s[id]")},
						'success':  successCallback
					}
				);
			}
		)
	;
	
	// animation：1の桁
	$('.BMpoint .one')
		.cycle({ 
			fx:    'scrollVert', 
			timeout: 0,
			speedIn:  800, 
			speedOut: 800,
			next:   '.vote dd img',
			nowrap:  1
		})
	;
	
	// animation：10の桁
	$('.BMpoint .ten')
		.cycle({ 
			fx:    'scrollVert', 
			timeout: 0,
			speedIn:  800, 
			speedOut: 800,
			next:   '.vote dd .cycleTen',
			nowrap:  1
		})
	;
	
	// animation：100の桁
	$('.BMpoint .hundred')
		.cycle({ 
			fx:    'scrollVert', 
			timeout: 0,
			speedIn:  800, 
			speedOut: 800,
			next:   '.vote dd .cycleHundred',
			nowrap:  1
		})
	;
	
	// animation：1000の桁
	$('.BMpoint .thousand')
		.cycle({ 
			fx:    'scrollVert', 
			timeout: 0,
			speedIn:  800, 
			speedOut: 800,
			next:   '.vote dd .cycleThousand',
			nowrap:  1
		})
	;
	
	// girlsList
	$('#girlsList .girls')
		.cycle({ 
			fx:    'scrollHorz', 
			timeout: 0,
			speedIn:  800, 
			speedOut: 800,
			next:   '.slideLeft',
			prev:   '.slideRight'
		})
	;
	
	// cycle
	$('#cycle .siteList')
		.cycle({ 
			fx:    'scrollVert', 
			timeout: 0,
			speedIn:  800, 
			speedOut: 400,
			easeIn:  'bounceout', 
			easeOut: 'backin', 
			next:   '#next3',
			prev:   '#prev3' ,
			nowrap:  1
		})
	;
	
	// img rollover
	$("img, input[type='image']")
		.hover(
			function () {
				$(this).attr("src", $(this).attr("src").replace('/off.gif', '/on.gif'));
				$(this).attr("src", $(this).attr("src").replace('/off.png', '/on.png'));
//				$(this).attr("src", $(this).attr("src").replace('/off/', '/on/'));
			},
			function () {
				$(this).attr("src", $(this).attr("src").replace('/on.gif', '/off.gif'));
				$(this).attr("src", $(this).attr("src").replace('/on.png', '/off.png'));
//				$(this).attr("src", $(this).attr("src").replace('/on/', '/off/'));
			}
		)
	;	
	
	
	// img rollover
	$("#free #contents img, input[type='image']")
		.hover(
			function () {
				$(this).attr("src", $(this).attr("src").replace('/off/', '/on/'));
			},
			function () {
				$(this).attr("src", $(this).attr("src").replace('/on/', '/off/'));
			}
		)
	;	
	
	
	// message template
	$(".profile .form dd img")
		.click(
			function () {
				$(".profile .form .wrap").toggle();
			}
		)
	;
	
	$(".profile .form .wrap :radio")
		.click(
			function () {
				if ($(this).attr("id") != 'close') {
					var _message = $(this).parent().text();
					
					$(".profile .form textarea").val(_message);
				}
				$(".profile .form .wrap").hide();
			}
		)
	;
	
	
});