$(document).ready(function()
{
	//IE用にPNG対応
	$(document).pngFix();
	
	var header = [];
	var abstract = [];
	var floor_img = [];
	
	//パレットエリアを隠す
	$("#palette").css("display","none");
	
	//パレットエリア内のid名がfloorから始まるdivを選択
	var select = '#palette>div[id^="floor"]';
	
	//h1要素を配列に格納
	$(select).find('h1').each(function()
	{
		header.push('<h1>' + $(this).html() + '</h1>');
	});
	
	//abstractクラスの要素を配列に格納
	$(select).find('.abstract').each(function()
	{
		abstract.push('<p class="abstract">' + $(this).html() + '</p>');
	});
	
	//floor_imgクラスの要素を配列に格納
	$(select).find('.floor_img').each(function()
	{
		floor_img.push('<p class="floor_img">' + $(this).html() + '</p>');
	});
	
	//キャンバスを初期化
	$("#canvas").html(header[0] + abstract[0] + floor_img[0]);
	
	//左ナビゲーションエリアのクリックイベント
	$(".ctrl").click(function()
	{
		var detail = [];
		$("#canvas").height("550px");
		
		//押されたボタンのid属性を取得
		var id = $(this).attr("id");
		var temp = (5 - id) + 1;
		
		//パレットエリア内のfloor*からdetailクラス内のdl要素を配列に格納
		$('#palette > div[id="floor' + temp +'"]').find('.detail > dl').each(function()
		{
			detail.push('<dl>' + $(this).html() + '</dl>');
		});
		
		//HTMLバッファを初期化
		var buffer = header[id] + abstract[id];
		
		//フロアー図のHTMLをバッファに追加
		for(var i = 1; i < floor_img.length; i++) {
			buffer += floor_img[i];
		}
		
		//各サムネイルの絶対座標を設定してバッファに追加
		buffer += config_thumb((5-id)+1);
		
		//キャンバス内にHTMLを設定（表示しない）
		$("#canvas").css("display","none").html(buffer)
		
		//フロアー図を配置
		var index = 0;
		$("#canvas>.floor_img").each(function()
		{
			var top = 150 + index * 25;
			var opacity;
			
			if(id == index + 1) {
				opacity = 1.0;
			}else {
				opacity = 0.1;
			}
			
			$(this)
				.css("opacity",opacity)
				.css("position","absolute")
				.css("top",top)
				.css("right","0");
			
			index++;
		});
		
		//キャンバス内のHTMLを表示
		$("#canvas").fadeIn();
		
		//サムネイルのホバーイベント
		$("#canvas > .thumb_nail").hover(function(e)
		{
			//サムネイルの位置番号を取得
			var index = $(".thumb_nail").index(this);
			//位置番号に対応する詳細を出現させる
			$("body").append("<div id='preview'><img src='"+ this.src +"'/>" + detail[index] + "</div>");
			
			//詳細のCSS
			$("#preview dl").css("font-size","18px");
			$("#preview dt").css("color","#015A1B");
			$("#preview dd").css("margin-bottom","0.75em");
			
			$("#preview")
				.css("width","420px")
				.css("line-height","130%")
				.css("z-index","10")
				.css("display","none")
				.css("position","absolute")
				.css("padding","10px")
				.css("margin-bottom","10px")
				.css("margin-left","10px")
				.css("background", "#FFFFFF")
				.css("border","1px solid #CECECE")
				.css("top", (e.pageY - 200) + "px")
				.css("left",(e.pageX - 470) + "px")
				.fadeIn("normal");
    	},
		function(){
			//マウスがホバーから外れた時はDOMツリーから削除
			$("#preview").remove();
    	});
		
		//マウスがサムネイル上で動いた場合の処理
		$("#canvas > .thumb_nail").mousemove(function(e){
			$("#preview")
				.css("top",(e.pageY - 200) + "px")
				.css("left",(e.pageX - 470) + "px");
			}
		);
	});
});

//サムネイルの絶対座標設定
function config_thumb(id)
{
	var buffer = "";
	
	switch(id){
	case 5:
		
		//屋上庭園
		$("#5_1 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","230px")
			.css("right","350px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60")
		
		//ラウンジ
		buffer += $("#5_1").html();
		
		$("#5_2 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","130px")
			.css("right","150px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#5_2").html();
		
		//日本間
		$("#5_3 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","130px")
			.css("right","330px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#5_3").html();
		
		//会議室
		$("#5_4 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","270px")
			.css("right","25px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#5_4").html();
		
		break;
		
	case 4:
		
		//情報センター
		$("#4_1 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","310px")
			.css("right","240px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#4_1").html();
		
		//団体事務所
		$("#4_2 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","170px")
			.css("right","80px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
		.css("display","none")
			.attr("height","60");
		
		buffer += $("#4_2").html();
		
		//管理事務所
		$("#4_3 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","150px")
			.css("right","350px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
		.css("display","none")
			.attr("height","60");
		
		buffer += $("#4_3").html();
		
		break;
	
	case 3:
		
		//会議室
		$("#3_1 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","200px")
			.css("right","90px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#3_1").html();
		
		//控え室
		$("#3_2 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","230px")
			.css("right","400px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#3_2").html();
		
		break;
		
	case 2:
		
		//資料展示コーナー
		$("#2_1 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","230px")
			.css("right","90px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#2_1").html();
		
		//レストラン
		$("#2_2 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","200px")
			.css("right","250px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#2_2").html();
		
		break;
		
	case 1:
		
		//広い空間のアトリウム
		$("#1_1 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","330px")
			.css("right","400px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#1_1").html();
		
		//資材売り場
		$("#1_2 img")
			.attr("class","thumb_nail")
			.css("z-index","5")
			.css("position","absolute")
			.css("top","450px")
			.css("right","460px")
			.css("border","2px solid #33cccc")
			.attr("width","80")
			.attr("height","60");
		
		buffer += $("#1_2").html();
		
		break;
	}
	
	return buffer;
}
