﻿/**
 *
 *
 *
 *
 *
 */
 //
var maxWidth = 600;		//写真横サイズ
var maxHeight = 400;	//写真縦サイズ
//
$(function(){
	//
	// ---------------------------------------------------------------------------
	// header layer
	//
	$("#header").fadeTo("fast", 0.70);//0.55
	//
	
	
	// ---------------------------------------------------------------------------
	// set contents Body Height for Background gradation
	//
	// 高さを取得し設定
	var contentsBodyHeight = $("#contentsBody").height();
	//var contentsBodyHeight = document.getElementById("contentsBody").offsetHeight;
	$("#contentsBody").css("height", contentsBodyHeight);
	//
	
	
	//
	// ---------------------------------------------------------------------------
	// light box show (office map)
	//
	$('#gallery a').lightBox({fixedNavigation:true});
	//
	
	
	// ---------------------------------------------------------------------------
	// main Navigation dropdown menu
	//
	$("#mainMenuNavi li div").css({"display" : "block"});
	var aHeight  = parseInt($("#mainMenuNavi li div a").css("height"));
	var liHeight = parseInt($("#mainMenuNavi li").css("height"));
	$("#mainMenuNavi li").hover(
		function(){
			var linkName = $(this).attr("id");
			if (linkName != "nav5"){
				if (linkName == "nav2"){
					var	animateHeight = parseInt($("div a",this).css("height"))+ parseInt($("div a",this).css("padding-top"));// + 30
				}else{
					var childAcount = $("div",this).children("a");
					var animateHeight = childAcount.length * aHeight;// + liHeight
				}
				$("div",this).css({"height": animateHeight});
				animateHeight = animateHeight + aHeight + 1;
				$(this).stop(true, false).animate({height: animateHeight}, "fast");//slow normal fast
			}
		},
		function(){
			var linkName = $(this).attr("id");
			if (linkName != "nav5"){
				$(this).stop(true, false).animate({height: "30px"}, "fast");	//hide slideUp(10);		//slow normal fast
			}
	});
	//
	
	
	// ---------------------------------------------------------------------------
	// verdure
	//
	$("#imgBanner").hover(
		function(){
			this.src = "images/index/verdure1b.jpg";
		},
		function(){
			this.src = "images/index/verdure1a.jpg";
	});
	//
	
	
	// ---------------------------------------------------------------------------
	// mini slide show move left or right
	//
	$("#right").click(function(){
		var divPosiX = $(".block").position().left;
		var divRigthLimit = 0;
		//
		if (divPosiX >= divRigthLimit){
			return;
		}else {
			$(".block").animate({"left": "+=74px"}, "normal");
		}
	});
	//
	$("#left").click(function(){
		var divPosiX = $(".block").position().left;
		var liCount = ($(".block li").length) - 6;	//隠れている画像数
		var divLeftLimit = (-74) * liCount;
		//
		if (divPosiX <= divLeftLimit){
			return;
		}else {
			$(".block").animate({"left": "-=74px"}, "normal");
		}
	});
	//
	
	
	/*
	 *	クリエイト軽井沢建設 ギャラリー
	 */
	// ============================================================================== //
	var imgObjp1 = new Image();
	var imgObjp2 = new Image();
	var imgObjp3 = new Image();
	var imgObjp4 = new Image();
	var imgObjp5 = new Image();
	var imgObjArray = {
					   "p1" : imgObjp1,
					   "p2" : imgObjp2,
					   "p3" : imgObjp3,
					   "p4" : imgObjp4,
					   "p5" : imgObjp5
					  };
	// default show
	var deShow = new Image();
	deShow.src = $("#defaultShow img").attr("src");
	imgObjp1.src = deShow.src.substring(0,deShow.src.lastIndexOf("/") + 1) + "p1.jpg";
	imgObjp2.src = deShow.src.substring(0,deShow.src.lastIndexOf("/") + 1) + "p2.jpg";
	imgObjp3.src = deShow.src.substring(0,deShow.src.lastIndexOf("/") + 1) + "p3.jpg";
	imgObjp4.src = deShow.src.substring(0,deShow.src.lastIndexOf("/") + 1) + "p4.jpg";
	imgObjp5.src = deShow.src.substring(0,deShow.src.lastIndexOf("/") + 1) + "p5.jpg";
	//
	var imgReSize = getViewSizing(deShow.width, deShow.height);
	var wm = (maxWidth - imgReSize[0]) / 2;
	var hm = (maxHeight - imgReSize[1]) / 2;
	$("#targetImg").attr("src", deShow.src);
	$("#targetImg").css("width", imgReSize[0]);
	$("#targetImg").css("height", imgReSize[1]);
	$("#targetImg").css("margin-top", hm);
	$("#targetImg").css("margin-right", wm);
	$("#targetImg").css("margin-bottom", hm);
	$("#targetImg").css("margin-left", wm);
	//$("#defaultShow img").show();
	//
	//
	// construction slide show
	//
	$(".tdStyl1 img").click( function() {
		//
		var imgSeleObj   = new Image();
		imgSeleObj.src = $(this).attr("src");
		//
		imgObjp1.src = imgSeleObj.src.substring(0,imgSeleObj.src.lastIndexOf("/") + 1) + "p1.jpg";
		imgObjp2.src = imgSeleObj.src.substring(0,imgSeleObj.src.lastIndexOf("/") + 1) + "p2.jpg";
		imgObjp3.src = imgSeleObj.src.substring(0,imgSeleObj.src.lastIndexOf("/") + 1) + "p3.jpg";
		imgObjp4.src = imgSeleObj.src.substring(0,imgSeleObj.src.lastIndexOf("/") + 1) + "p4.jpg";
		imgObjp5.src = imgSeleObj.src.substring(0,imgSeleObj.src.lastIndexOf("/") + 1) + "p5.jpg";
		//
		$("#targetImg").fadeOut("fast", function() {
				var imgReSize = getViewSizing(imgSeleObj.width, imgSeleObj.height);
				var wm = (maxWidth - imgReSize[0]) / 2;
				var hm = (maxHeight - imgReSize[1]) / 2;
				$(this).attr("src", imgSeleObj.src);
				$(this).css("width", imgReSize[0]);
				$(this).css("height", imgReSize[1]);
				$(this).css("margin-top", hm);
				$(this).css("margin-right", wm);
				$(this).css("margin-bottom", hm);
				$(this).css("margin-left", wm);
				$(this).fadeIn(1000);
		});
		return;
    });
    //
    //
    // P/D Button click show (photo1～photo5)
    //
    $("#galSelectBox li").click( function() {
		var clickBtnId = $(this).attr("id");
		//
		// .stop([clearQueue], [gotoEnd])
		$("#targetImg").stop(false, true).fadeOut("fast", function() {
				$("#targetImg").css("display","none");
				var imgReSize = getViewSizing(imgObjArray[clickBtnId].width, imgObjArray[clickBtnId].height);
				var wm = (maxWidth - imgReSize[0]) / 2;
				var hm = (maxHeight - imgReSize[1]) / 2;
				$(this).attr("src", imgObjArray[clickBtnId].src);
				$(this).css("width", imgReSize[0]);
				$(this).css("height", imgReSize[1]);
				$(this).css("margin-top", hm);
				$(this).css("margin-right", wm);
				$(this).css("margin-bottom", hm);
				$(this).css("margin-left", wm);
				$(this).fadeIn(1000);
		});
		return;
    });
    //
    // ============================================================================== //
	//
	
	
	//
	// オープンハウスのオンマウス処理
	//
	$("#ohpic").hover(
		function(){
			$("#rightOpenHouse").css("background-image","url('images/index/openhouse/openhouse_bg_b.gif')")
		},
		function(){
			$("#rightOpenHouse").css("background-image","url('images/index/openhouse/openhouse_bg.gif')")
	});
	//
});



//
//***************************************************************************************
//
//	写真の表示サイズ設定
//
//***************************************************************************************
//
function getViewSizing(giWidth, giHeight){
	var ratio = giWidth / giHeight;
	var getPicWidth = 0;
	var getPicHeight = 0;
	var limit = maxWidth / maxHeight;
	//
	if (ratio <= limit){
		//縦長写真（正方形）
		getPicWidth = giWidth * maxHeight / giHeight ;
		getPicHeight = maxHeight;
		/*
		getPicWidth = maxHeight * ratio;
		getPicHeight = maxHeight;
		*/
	}else{
		//横長写真
		getPicWidth = maxWidth;
		getPicHeight = giHeight * maxWidth / giWidth;
		/*
		getPicWidth = maxWidth;
		getPicHeight = maxWidth / ratio;
		*/
	}
	return [getPicWidth, getPicHeight];
}
//
//
// サブウィンドウ
//
// サブウィンドウの大きさと開く位置の指定
l = 60; // 表示するx座標
t = 30; // 表示するy座標
w = 930; // 横幅
h = 625; // 縦幅
// 中央に開く
function openWindow() {
  x = (screen.width - w) / 2;
  y = (screen.height - h) / 3;
  subWin = window.open("kzw-birdview.html","OpenWindow",
    "screenX="+x+",screenY="+y+",left="+x+",top="+y+",width="+w+",height="+h);
}



//
//***************************************************************************************
//
// ｉｅブラウザーバージョンチェック
//
//***************************************************************************************
//
function ieVersionCheck(){
	var ua = navigator.userAgent;
	var bName = getBrowserName();
	var ver = null;
	var s, e, n;
	ua = ua.toUpperCase();
	if (bName == "IE"){
		s = ua.indexOf("MSIE") + 5;
		ver = ua.charAt(s);
		n = ua.substring(s, s+3);
		if (n == "5.5") ver = "5.5";
	}
	/*
	alert("【 お知らせ 】" + "\n" +
		  "お客様がお使いの インターネットエクスプローラー Ver " + 
		  ver + 
		  " は当サイトを正確に表示する事が出来ない可能性がございます。" +  "\n\n" +
		  "マイクロソフトアップデートより ver6.0 以上にアップデートされてご覧いただきますようお願いいたします。" +  "\n\n" +
		  "本日は当サイトにお越しいただき、誠にありがとうございます。" + "\n\n" +
		  "株式会社 クリエイト軽井沢　サイトマスター");
	*/
	return ver;
}
//
// ブラウザー名の取得
//
function getBrowserName(){
	var ua = navigator.userAgent;
	ua = ua.toUpperCase();
	if (ua.indexOf("MSIE") > -1){
		return "IE";
	}
	return null;
}



//
//***************************************************************************************
//
// Gradient gradation
//
//***************************************************************************************00a8ff
//
function backGroundGradation(){
	/* site gradation */
	var siteStartCollor = "#FF0000";//#AA0000,#800000
	var siteEndCollor   = "#F0F000";//#FEEA00
	/* contents body gradation */
	var startCollor     = "#000000";//#000000
	var endCollor       = "#172926";//#192533
	// get browser name
	var browserName     = getBrowserName();
	
	if (browserName == "IE"){
		// 2011/07廃止
		//document.getElementById("contentsBody").style.filter          = "progid:DXImageTransform.Microsoft.Gradient( GradientType=0,StartColorStr=" + startCollor + ",EndColorStr=" + endCollor + ")";
		document.getElementById("webContainerBackImage").style.filter = "progid:DXImageTransform.Microsoft.Gradient( GradientType=1,StartColorStr=" + siteStartCollor + ",EndColorStr=" + siteEndCollor + ")";
	}else{
		/* id=contentsBody */
		/* olive */
		//setGradient('contentsBody','#090a06','#1E2213',0);
		/* Blue */
		// 2011/07廃止
		//setGradient('contentsBody', startCollor, endCollor, 0);
		//
		/* id=webContainerBackImage */
		setGradient('webContainerBackImage', siteStartCollor, siteEndCollor, 1);
	}
}



//
//***************************************************************************************
//
// dynamic Keyword Support
//
//***************************************************************************************
//
function dynamicKeywordSupport(){
	// ---------------------------------------------------------------------------
	// caption area referrer dynamic control
	//		# images/index/dynamic_view/dynamic.view.js
	//
	var gr = decodeURIComponent(document.referrer);
	var msgWord1 = "";
	var msgWord2 = "";
	//
	var chkRes = gr.indexOf("軽井沢");
	if(chkRes != -1){
		msgWord1 = "軽井沢の";
	}
	for(var i = 0; i < aryKey.length; i++){
		chkRes = gr.indexOf(aryKey[i]);
		if(chkRes != -1){
			msgWord2 += aryKey[i] + "、";
		}
	}
	//
	if(msgWord2 != ""){
		msgWord2 = msgWord2.substring(0, msgWord2.length-1);
	}else{
		msgWord2 = "物件";
	}
	//地震災害の間は停止する
	//document.getElementById("comP1").innerHTML = phrase1 + msgWord1 + msgWord2 + phrase2;
	//
	// ---------------------------------------------------------------------------
	// NWE TOPIX area referrer dynamic control for image & caption
	//		div#keyDefault, div#keyBeso, div#keyToti, div#keyMansyon
	// 別荘のキーワード
	if (gr.indexOf(aryKey[1]) > -1){
		$("#keyDefault").css("display", "none");
		$("#keyBeso").css("display", "block");
		$("#keyToti").css("display", "none");
		$("#keyMansyon").css("display", "none");
		/*
		document.images["keyPhoto1"].src = dynamicViewImagePath[aryKey[1]] + "photo1.jpg";
		document.images["keyPhoto2"].src = dynamicViewImagePath[aryKey[1]] + "photo2.jpg";
		document.images["keyPhoto3"].src = dynamicViewImagePath[aryKey[1]] + "photo3.jpg";
		document.getElementById("keyText").innerHTML = dynamicCaptionPath[aryKey[1]];
		document.getElementById("newTitle").innerHTML = aryKey[1] + "&nbsp;";
		*/
	// 土地のキーワード
	}else if (gr.indexOf(aryKey[2]) > -1){
		$("#keyDefault").css("display", "none");
		$("#keyBeso").css("display", "none");
		$("#keyToti").css("display", "block");
		$("#keyMansyon").css("display", "none");
		/*
		document.images["keyPhoto1"].src = dynamicViewImagePath[aryKey[2]] + "photo1.jpg";
		document.images["keyPhoto2"].src = dynamicViewImagePath[aryKey[2]] + "photo2.jpg";
		document.images["keyPhoto3"].src = dynamicViewImagePath[aryKey[2]] + "photo3.jpg";
		document.getElementById("keyText").innerHTML = dynamicCaptionPath[aryKey[2]];
		document.getElementById("newTitle").innerHTML = aryKey[2] + "&nbsp;";
		*/
	// マンションのキーワード
	}else if (gr.indexOf(aryKey[3]) > -1){
		$("#keyDefault").css("display", "none");
		$("#keyBeso").css("display", "none");
		$("#keyToti").css("display", "none");
		$("#keyMansyon").css("display", "block");
		/*
		document.images["keyPhoto1"].src = dynamicViewImagePath[aryKey[3]] + "photo1.jpg";
		document.images["keyPhoto2"].src = dynamicViewImagePath[aryKey[3]] + "photo2.jpg";
		document.images["keyPhoto3"].src = dynamicViewImagePath[aryKey[3]] + "photo3.jpg";
		document.getElementById("keyText").innerHTML = dynamicCaptionPath[aryKey[3]];
		document.getElementById("newTitle").innerHTML = aryKey[3] + "&nbsp;";
		*/
	// 以外ののキーワード
	}else{
		$("#keyDefault").css("display", "block");
		$("#keyBeso").css("display", "none");
		$("#keyToti").css("display", "none");
		$("#keyMansyon").css("display", "none");
		/*
		document.images["keyPhoto1"].src = dynamicViewImagePath[aryKey[0]] + "photo1.jpg";
		document.images["keyPhoto2"].src = dynamicViewImagePath[aryKey[0]] + "photo2.jpg";
		document.images["keyPhoto3"].src = dynamicViewImagePath[aryKey[0]] + "photo3.jpg";
		document.getElementById("keyText").innerHTML = dynamicCaptionPath[aryKey[0]];
		*/
		//document.getElementById("newTitle").innerHTML = aryKey[0];
	}
}



