$(function() {
	//フェードロールオーバー
	$(".f_over").find("img").hover(
		function() {
			$(this).stop(true, true).animate({opacity: 0}, 150, "easeOutCubic");
		},
		function() {
			$(this).stop(true, true).animate({opacity: 1}, 300, "easeInOutCubic");
		}
	);
	//リストオーバー
	$(".list_hover li").hover(
		function() {
			$(this).css({backgroundPosition: "-310px 0"});
		},
		function() {
			$(this).css({backgroundPosition: "0 0"});
		}
	);
	//リストオーバー(マタニティーのみ)
	$(".maternity_list_hover li").hover(
		function() {
			$(this).css({backgroundPosition: "0 -150px"});
		},
		function() {
			$(this).css({backgroundPosition: "0 0"});
		}
	);
	
	//ページ内スムーススクロール
	$(".smooth_scroll").find("a").click(function() {
		var anc_name = $(this).attr("href");
		$('html,body').animate({scrollTop: $(anc_name).offset().top}, 500, 'easeOutCubic');
		return false;
	});
	//メイクサンプルポップアップ(『a』タグにクラス付加で、その『href』のページへ飛ぶさ)
	$(".pop_up").click(function() {
		window.open(this.href, 'WindowName', 'width=720,height=720,top=0,left=0,status=no,resizable=no,scrollbars=no');
		return false;
	});
	//ヘッダイメージフェードイン
	$(".main_image img.image").fadeIn(2000, "easeInOutCubic");

	//ホームキャンセル
	$("#homeCancelbutton").find("a").click(function() {
		$("#modalBg").css({
			opacity: '0.6',
			filter: 'alpha(opacity=60)'
		});
		$(".foot_content").css({zIndex: '-1'});
		$("#modalBg").fadeIn();
		$("#cancelContainer").fadeIn();
		$("#cancelClose").fadeIn();
		return false;
	});
	$("#modalBg").click(function() {
		$("#cancelClose").hide();
		$("#modalBg").fadeOut();
		$("#cancelContainer").fadeOut();
		$(".foot_content").css({zIndex: '1'});
		return false;
	});
	$("#cancelClose").click(function() {
		$("#cancelClose").hide();
		$("#modalBg").fadeOut();
		$("#cancelContainer").fadeOut();
		$(".foot_content").css({zIndex: '1'});
		return false;
	});
	
	//レンタル見取り図
	$(".sketch_thumb dt").click(function() {
		$("#sketchMainImageAll").hide();
		$("#sketchMainImageStudio").hide();
		var this_attr = $(this).attr("id");
		switch(this_attr) {
			case 'thumbAll':
			$("#sketchMainImageAll").fadeIn();
			$("#descriptionBaloon").stop(true, true).animate({left: "55px"}, 250, 'easeOutBack');
			$(".sketch_description dd").stop(true, true).animate({left: "10px"}, 350, 'easeInOutCubic');
			$("#thumbAll").css({cursor: "default"});
			$("#thumbStudio").css({cursor: "pointer"});
			$("#thumbAll img").hide();
			$("#thumbStudio img").show();
			break;
			case 'thumbStudio':
			$("#sketchMainImageStudio").fadeIn();
			$("#descriptionBaloon").stop(true, true).animate({left: "165px"}, 250, 'easeOutBack');
			$(".sketch_description dd").stop(true, true).animate({left: "-240px"}, 350, 'easeInOutCubic');
			$("#thumbAll").css({cursor: "pointer"});
			$("#thumbStudio").css({cursor: "default"});
			$("#thumbAll img").show();
			$("#thumbStudio img").hide();
			break;
			default:
			break;
		}
	});

	//ギャラリーリストページ
	//ロールオーバー(自分以外明度上げ)
	var now_list_thumb;
	$("#galleryListButton").find("li").hover(function() {
		now_list_thumb = $(this);
		$("#galleryListButton li:not(now_list_thumb)").stop(true, true).animate({opacity: "0.3"}, 350, 'easeOutCubic');
		$(now_list_thumb).stop(true, true).animate({opacity: "1"}, 10, 'easeOutCubic');
	},
	function() {
		$("#galleryListButton li:not(now_list_thumb)").animate({opacity: "1"}, 350, 'easeOutCubic');
		$(now_list_thumb).animate({opacity: "1"}, 350, 'easeOutCubic');
	});
	//ギャラリークローズ(ページ遷移になったので、ヒストリーバックに変更)
	$("#galleryClose").click(function() {
		history.back();
	});
	//ギャラリーコンテンツ
	var IMG_MAX = $("#galleryImage li").length;
	var IMG_MIN = 1;
	var now_pos;
	var set_pos_num = 1;
	var now_thumb;
	$("#nowNum").text(IMG_MIN);
	$("#totalNum").text(IMG_MAX);
	$("#galleryImage li:not(:last)").css({display: "none"});
	//サムネイルロールオーバーの挙動
	$("#galleryThumb").find("li").hover(function() {
		now_thumb = $(this);
		$("#galleryThumb li:not(now_thumb)").css({opacity: "0.5"});
		$(now_thumb).css({opacity: "1"});
	},
	function() {
		$(now_thumb).css({opacity: "1"});
		$("#galleryThumb li:not(now_thumb)").css({opacity: "1"});
	});
	//サムネイルクリックの挙動
	$("#galleryThumb").find("li").click(function() {
		set_pos_num = $("#galleryThumb li").index(this) + 1;
		now_pos = '#image' + set_pos_num;
		now_thumb = '#thumb' + set_pos_num;
		$("#galleryThumb li:not(now_thumb)").css({borderColor: "#ccc"});
		$(now_thumb).css({borderColor: "#f21889"});
		$("#galleryImage li").slideUp(500, 'easeOutBack');
		$(now_pos).slideDown(500, 'easeInBack');
		$("#nowNum").text(set_pos_num);
		return false;
	});
	//NEXTクリックの挙動
	$("#next").click(function() {
		now_pos = '#image';
		if(set_pos_num < IMG_MAX) {
			set_pos_num++;
			now_pos = now_pos + set_pos_num;
			now_thumb = '#thumb' + set_pos_num;
		}else{
			set_pos_num = IMG_MIN;
			now_pos = now_pos + set_pos_num;
			now_thumb = '#thumb' + set_pos_num;
		}
		//$("#galleryImage li").hide().filter($(now_pos)).fadeIn();
		$("#galleryImage li").slideUp(500, 'easeOutBack');
		$(now_pos).slideDown(500, 'easeInBack');
		$("#galleryThumb li:not(now_thumb)").css({borderColor: "#ccc"});
		$(now_thumb).css({borderColor: "#f21889"});
		$("#nowNum").text(set_pos_num);
		return false;
	});
	//PREVクリックの挙動
	$("#prev").click(function() {
		now_pos = '#image';
		if(set_pos_num > IMG_MIN) {
			set_pos_num--;
			now_pos = now_pos + set_pos_num;
			now_thumb = '#thumb' + set_pos_num;
		}else{
			set_pos_num = IMG_MAX;
			now_pos = now_pos + set_pos_num;
			now_thumb = '#thumb' + set_pos_num;
		}
		$("#galleryImage li").slideUp(500, 'easeOutBack');
		$(now_pos).slideDown(500, 'easeInBack');
		$("#galleryThumb li:not(now_thumb)").css({borderColor: "#ccc"});
		$(now_thumb).css({borderColor: "#f21889"});
		$("#nowNum").text(set_pos_num);
		return false;
	});

	//実績画像表示(モーダル)
	//$("#worksContainer").css({display: 'none'});
	$(".works").find("a").click(function() {
		$("#modalBg").css({
			opacity: '0.6',
			filter: 'alpha(opacity=60)'
		});
		$(".foot_content").css({zIndex: '-1'});
		$("#modalBg").fadeIn();
		$("#worksContainer img").attr("src", $(this).attr("href"));
		$("#worksContainer").fadeIn();
		$("#worksClose").fadeIn();
		return false;
	});
	$("#modalBg").click(function() {
		$("#modalBg").fadeOut();
		$("#worksContainer").fadeOut();
		$("#worksClose").fadeOut();
		$(".foot_content").css({zIndex: '1'});
		return false;
	});
	$("#worksClose").click(function() {
		$("#modalBg").fadeOut();
		$("#worksContainer").fadeOut();
		$("#worksClose").fadeOut();
		$(".foot_content").css({zIndex: '1'});
		return false;
	});
	
	//アクセス(地図画像切り替え)
	$("#linkMap").click(function() {
		$("#mapImage").hide();
		$("#mapGoogleMap").hide();
		$("#mapImage").fadeIn();
		return false;
	});
	$("#linkGoogleMap").click(function() {
		$("#mapImage").hide();
		$("#mapGoogleMap").hide();
		$("#mapGoogleMap").fadeIn();
		return false;
	});
	
	
	//ブログアーカイブタブ
	$("#archiveTab").find("a").click(function() {
		var this_id = $(this).attr("href");
		$("#archiveContent ul").stop(true, true).slideUp();
		$("#archiveTab li a:not(this)").css({backgroundPosition: '0 0'});
		$(this).css({backgroundPosition: '0 -17px'});
		$(this_id).stop(true, true).slideDown();
		return false;
	});
	
	//ページトップに戻る表示非表示
	$(".page_top_link").hide();
	$(window).scroll(function() {
		if($(this).scrollTop() > 100) {
			$(".page_top_link").fadeIn(500);
		}else{
			$(".page_top_link").fadeOut(250);
		}
	});
	
	//ホームバナーサブメニュー表示
	$(".home_sub_nav").hover(function() {
			$(this).find("dd").stop().animate(
			{
				bottom: '0'
			},
			{
				duration: 300,
				easing: 'easeOutCubic'
			}
			);
		},
		function() {
			$(this).find("dd").stop().animate(
			{
				bottom: '-80'
			},
			{
				duration: 500,
				easing: 'easeOutBounce'
			}
			);
	});

	//リンクバナーテキストエリア全選択
	$(".take_banner_sample_content").find("textarea").focus(function() {
		$(this).select();
	});
	
	//ブログカレンダーの月移動リンクが聞かないのでJSで無理やりセルフ移動させる
	$("#prev").find("a").click(function() {
		window.open($(this).attr("href"), '_self');
		return false;
	});
	$("#next").find("a").click(function() {
		window.open($(this).attr("href"), '_self');
		return false;
	});
	
	/*マタニティーモーダル--------------------------------------*/
	/*マタニティ用各種変数*/
	var _id;															//現在の画像番号
	var nowImage;													//表示されている画像のID名(#image～)
	var _width;														//画像の幅
	var _height;													//画像の高さ
	var _mat_flg  = true;									//表示中フラグ
	var MAT_DELAY_TIME_BG = 400;					//背景・サムネイルロールオーバーエフェクト変化時間
	var MAT_DELAY_TIME_IMAGE = 150;				//イメージエフェクト変化時間
	var MAT_EASE_STYLE = 'easeOutCubic';	//イージング(全部共通)
	/*モーダルの背景を半透明にする
	(CSSでやるとIEとか用に分けなければならないのでこちらで共通指定)*/
	$("#modalLayer").css({opacity: '0.7'});
	
	/*リストサムネイルロールオーバー*/
	$(".modal li").hover(
		function() {
			$(this).css({borderColor: '#f21889'}).stop().animate({opacity: '0.8'},MAT_DELAY_TIME_BG, MAT_EASE_STYLE);
		},
		function() {
			$(this).css({borderColor: '#ccc'}).stop().animate({opacity: '1'},MAT_DELAY_TIME_BG, MAT_EASE_STYLE);
		}
	);
	/*モーダル背景クリック非表示*/
	$("#modalLayer").click(function() {
		if(_mat_flg) {
			$(nowImage).fadeOut(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {$("#modalLayer").slideUp(MAT_DELAY_TIME_BG, MAT_EASE_STYLE);});
		}
		return false;
	});
	$(".mat_close").click(function() {
		if(_mat_flg) {
			$(nowImage).fadeOut(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {$("#modalLayer").slideUp(MAT_DELAY_TIME_BG, MAT_EASE_STYLE);});
		}
		return false;
	});
	/*サムネイルクリックからのモーダル表示動作*/
	if(_mat_flg) {
		$(".modal a").click(function() {
			_mat_flg = false;
			nowImage = $(this).attr("href");						//画像のID名を取得
			_id = nowImage.replace("#img", "");					//画像IDから数字だけにする
			_width = $(nowImage).find("img").width();		//画像の幅を取得
			_height = $(nowImage).find("img").height();	//画像の高さを取得
			/*縦・横確認・一調整用クラス設定
				初めに位置を決めないとヘンな位置に行く(当たり前のことだけど)*/
			if(_width > _height) { $(nowImage).addClass('mat_height_image'); }
			else { $(nowImage).addClass('mat_width_image'); }
			/*画像表示*/
			$("#modalLayer").slideDown(MAT_DELAY_TIME_BG, MAT_EASE_STYLE, function() {
				$(nowImage).fadeIn(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {
					_mat_flg = true;
				});
			});
			return false;
		});
	}
	//次へ(next)リンク
	if(_mat_flg) {
		$(".mat_next").click(function() {
			_mat_flg = false;
			$(nowImage).stop(true, false).fadeOut(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {
				_id = Number(_id) + 1;
				nowImage = "#img" + _id;
				_width = $(nowImage).find("img").width();		//画像の幅を取得
				_height = $(nowImage).find("img").height();	//画像の高さを取得
				/*縦・横確認・一調整用クラス設定
					初めに位置を決めないとヘンな位置に行く(当たり前のことだけど)*/
				if(_width > _height) { $(nowImage).addClass('mat_height_image'); }
				else { $(nowImage).addClass('mat_width_image'); }
				$(nowImage).stop(true, false).fadeIn(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {
					_mat_flg = true;
				});
			});
			return false;
		});
	}
	//戻る(prev)リンク
	if(_mat_flg) {
		$(".mat_prev").click(function() {
			_mat_flg = false;
			$(nowImage).stop(true, false).fadeOut(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {
				_id = Number(_id) - 1;
				nowImage = "#img" + _id;
				_width = $(nowImage).find("img").width();		//画像の幅を取得
				_height = $(nowImage).find("img").height();	//画像の高さを取得
				/*縦・横確認・一調整用クラス設定
					初めに位置を決めないとヘンな位置に行く(当たり前のことだけど)*/
				if(_width > _height) { $(nowImage).addClass('mat_height_image'); }
				else { $(nowImage).addClass('mat_width_image'); }
				$(nowImage).stop(true, false).fadeIn(MAT_DELAY_TIME_IMAGE, MAT_EASE_STYLE, function() {
					_mat_flg = true;
				});
			});
			return false;
		});
	}
	
	/*------------------------------------------------*/
	
	//ブログコメントフォーム入力チェック
	//ちょっとずつやってみる。メールアドレスの形式の確認と、コメントのタグの有無の確認、
	//その後送信するまで、できるのか?
	/*
	$("input#submit").click(function() {
		var author_str = $("#author").val();
		var email_str = $("#email").val().match(/.+@.+\..+/g);
		var comment_str = $("#comment").val();
		if(email_str != null) {
			alert(email_str);
		}else{
			alert('不正な形式');
		}
		return false;
	});
	*/
	
});

