// fmnパラメータ判定
var request = {
	QueryString : function(val) {
		var uri = window.location.search;
		var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
		return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
	},
	QueryStrings : function() {
		var uri = window.location.search;
		var re = /\w*\=([^\&\?]*)/ig;
		var retval=[];
		while ((arr = re.exec(uri)) != null)
		retval.push(arr[0]);
		return retval;
 	}
}

var fmn=request.QueryString("fmn");
var previewUrl=request.QueryString("previewUrl");
if(fmn==null){
	fmn="f";
}else if(fmn.length==0){
	fmn="f";
}
if(previewUrl!=null){
	var fmn_n=previewUrl.search("fmn%3Dn");
	var fmn_m=previewUrl.search("fmn%3Dm");
	if(fmn_n>0){
		fmn="n";
	}
	if(fmn_m>0){
		fmn="m";
	}
};

//「乗り換え案内」
function norikaePop(formName) {
	var SubWindow=window.open("about:blank", "compinfo", "width=600, height=550, toolbar=1, location=0, status=0, menubar=1, scrollbars=1, resizable=1");
	SubWindow.focus();
	document.forms[formName].submit();
};



jQuery(function($){
	/**
	 * 物件情報ヘッダ
	 */
	//「情報の見方」
	$("a.howInfo").click(function(){
		SUUMO.MS.popUpMap('/edit/joho_mikata/',800,700);
	});

	//「マイリストに追加する」
	$("a.btAddMyListI").click(function(){
		SUUMO.COMMON.registClipSingle(this);
	});

	//《地図を見る》ボタン、《応募締め切りまであと○日》ボタン、《登録締め切り当日です》ボタン、《地図を印刷する》ボタン
	$(".showMap").click(function(){
		var href = $(this).attr("name");
		SUUMO.MS.popUpMap(href,800,640);
	});

	//価格更新お知らせメール - jQuery Plugin
	//  --ライトボックス表示
	$('#updatePrice').modalWinOpen({
		height: 470,
		width: 810
	});

	//  --価格更新メール登録(非会員)
	$('#updatePrice').click(function(){
		SUUMO.COMMON.registClipMailSingle($(this));
		return false;
	});

	//  --価格更新メール登録(会員)
	$('#updatePriceLogin').click(function(){
		SUUMO.COMMON.registClipMailSingle($(this));
		return false;
	});

	//資料請求・お問い合わせ（無料）の画像クリックイベント
	$('a[id=singleShiryou]').click(function() {
		if(fmn.toLowerCase() == "f"){
			var href = $(this).attr("href");
			var turHtml= $('<input type="hidden" name="turnbackinfo" value ="'+$(".turnbackinfo :input").val()+'"/>');
			var shiryouForm = $('<form action='+href+' method="post"></form>');
			shiryouForm.appendTo("body");
			turHtml.appendTo(shiryouForm);
			shiryouForm[0].submit();
		}
		return false;
	});

	/**
	 * メインコンテンツ：物件概要
	 */
	//イベント開催日
	$(".js_cluetip_above_fix_trigger").click(function(){
		var href = $(this).attr("name");
		SUUMO.MS.popUpMap(href,800,640);
	});


	/**
	 * メインコンテンツ：間取り・価格
	 */
	$('#searchInfo').modalWinOpen({
		height: 345,
		width: 800
	});

	/**
	 * 物件情報フッタ
	 */
	//携帯電話へ物件情報を送る
	$('#mailInfo').modalWinOpen({
		height: 465,
		width: 810
	});

	//不動産会社ガイド
	$("a.fguide").click(function(){
		var num = $(this).attr("name");
		logClickLinkEx(1,num);
	});

	//関連サイトのリスト(logClickLinkEx, logWindowOpenOptionWithReferer)
	$("select#kanrenSiteA").bind('change', function(){
		if (this.options[this.selectedIndex].value!=1) {
			logClickLinkEx(5,this.options[this.selectedIndex].id);
			logWindowOpenOptionWithReferer(this.options[this.selectedIndex].value)
		}
	});

	//関連サイトのリスト(logWindowOpenOptionWithReferer)
	$("select#kanrenSiteB").bind('change', function(){
		if (this.options[this.selectedIndex].value!=1) {
			logWindowOpenOptionWithReferer(this.options[this.selectedIndex].value)
		}
	});


	/**
	 * 物件情報ヘッダ、メインコンテンツ、物件情報フッタ共通
	 */
	//	モーダルポップアップ部分
	// -----------------------------------

	//共通デフォルト設定
	$.extend($.fn.cluetip.defaults, {
		width:            275,
		height:           'auto',
		cluezIndex:       97,
		positionBy:       'auto',
		topOffset:        15,
		leftOffset:       5,
		local:            false,
		hideLocal:        true,
		attribute:        'rel',
		titleAttribute:   'title',
		splitTitle:       '',
		showTitle:        true,
		cluetipClass:     'default',
		hoverClass:       '',
		waitImage:        false,
		cursor:           '',
		arrows:           false,
		dropShadow:       false,
		dropShadowSteps:  6,
		sticky:           false,
		mouseOutClose:    false,
		activation:       'hover',
		clickThrough:     false,
		tracking:         false,
		delayedClose:     0,
		closePosition:    'top',
		closeText:        'Close',
		truncate:         0,
		debug:            false
	});

	//photo 写真のホバー表示
	$('.js_cluetip_photo_trigger').cluetip(
		{
			width:            300,
			local:            true,
			showTitle:        false,
			cluetipClass:     'nodecoration'
		}
	);
	//title title属性のみのホバー表示（）
	$('.js_cluetip_titleonly_trigger[title]').cluetip({
			positionBy:       'mouse',
			topOffset:        10,
			leftOffset:       30,
			splitTitle:       "#####split#####",//title内に絶対に一致しない文字列を設定
			cluetipClass:     'titleonly',
			tracking:         true,
			onShow: function(cluetip, cluetipInner){
				cluetip.width('auto');
			}
		});
	//真上に25pxの間を設けてホバー表示（幅、高さは自動で取得設定）
	$('.js_cluetip_above_fix_trigger').each(function(index){
		var $trigger = $(this);
		var bottomMargin = 35;
		$(this).cluetip({
			positionBy:       'fixed',
			local:            true,
			showTitle:        false,
			cluetipClass:     'noframe',
			onShow: function(cluetip, cluetipInner){
				var offset = cluetip.offset();
				cluetip.css('top', offset.top - cluetip.height() - bottomMargin);
				cluetip.width('auto');
				cluetip.css('left', offset.left - parseInt(cluetip.width())/2 - $trigger.width());
			}
		});
	});//End of Tooltip

	/*
	 * モーダルウィンドウのギャラリー設定
	 */
	$.nyroModalSettings({
		closeButton: '',
		padding: 40,
		endFillContent:function(modal, settings) {
			var gallery = $('[rel="'+ settings.from.rel +'"]');
			var currentIndex = gallery.index(settings.from);
			if(currentIndex - 1 < 0) {
				$("#nyroModalContent .btn_previous a").css("visibility", "hidden");
			} else {
				$("#nyroModalContent .btn_previous a").css("visibility", "visible").click(function(e) {
					e.preventDefault();
					var index = currentIndex - 1;
					if (index >= 0 && index < gallery.length) {
						gallery.eq(index).nyroModalManual();
					}
					return false;
				});
			}
			if(currentIndex + 1 >= gallery.length) {
				$("#nyroModalContent .btn_next a").css("visibility", "hidden");
			} else {
				$("#nyroModalContent .btn_next a").css("visibility", "visible").click(function(e) {
					e.preventDefault();
					var index = currentIndex + 1;
					if (index >= 0 && index < gallery.length) {
						gallery.eq(index).nyroModalManual();
					}
					return false;
				});
			}
			$("#nyroModalContent").after("<p class='js_message nyroModalClose'>閉じるボタン、もしくはグレー背景をクリックすると一覧画面に戻ります。</p>");
			var index = currentIndex + 1;
			index = (index < 10)? "0" + index : index;
			var modal_num = gallery.size();
			modal_num = (modal_num < 10)? "0" + modal_num : modal_num;
			$("#nyroModalContent .modal_index").text("[ " + index + " / " + modal_num + " ]");
		},
		showBackground: function(elts, settings, callback) {
			elts.bg.css({opacity:0}).fadeTo(10, 0.75, callback);
			IE6fix();
		}
	});

	function IE6fix() {
		if ($.browser.msie && $.browser.version.split('.')[0] < 7) {
			$("body").css({
				width: 'auto'
			});
			$('html').css({overflow: 'hidden'});
			$("#nyroModalBg, #nyroModalIframeHideIe").css({
				position: 'absolute',
				top: '0px',
				left:'0px',
				width: '100%',
				height: '100%'
			});
		}
	}

	$('a[id=kuchikomiButton]').click(function() {
			if(fmn.toLowerCase() == "f"){
				var href = $(this).attr("href");
				var turHtml= $('<input type="hidden" name="turnbackinfo" value ="'+$(".turnbackinfo :input").val()+'"/>');
				var shiryouForm = $('<form action='+href+' method="post"></form>');
				shiryouForm.appendTo("body");
				turHtml.appendTo(shiryouForm);
				shiryouForm[0].submit();
			}
			return false;
	})


});//End of document loaded
