/*
* E&Y Exhibition
* Require:
*  jquery.js
*
**************************************/

// init
$(document).ready(function(){
	$("ul.exhibitionIndex img").click(getExhibitionData);
});


// function getExhibitionData (for EXHIBITION)
function getExhibitionData(){
	$.getJSON(entryUrl[$("ul.exhibitionIndex img").index(this)], null, showExhibitionPanel);
}

// function showExhibitionPanel (for EXHIBITION)
function showExhibitionPanel(data){
	for (i=1; i<=data.imageNum; i++) {
		var mainImg = new Image();
		var number = i<=9 ? "0" + i : i;
		mainImg.src = "/exhibition/img/exh_img_" + data.id + "_" + number + ".jpg";
	}
	
	var panel = document.createElement("div");
	panel.id = "exhibitionPanel";

	var title = document.createElement("h2");
	var titleImg = document.createElement("img");
	titleImg.src = "/exhibition/img/exh_ttl_" + data.id + ".gif";
	titleImg.alt = data.title + ", " + data.place;
	title.appendChild(titleImg);

	var mainBlock = document.createElement("div");
	mainBlock.className = "mainBlock";
	
	var infoCol = document.createElement("div");
	infoCol.className = "infoCol";
	
	var textImgBlock = document.createElement("div");
	textImgBlock.className = "textImg";
	var textImg = document.createElement("img");
	textImg.src = "/exhibition/img/exh_txt_" + data.id + ".gif";
	textImg.width = 310;
	textImg.alt = data.body;
	textImgBlock.appendChild(textImg);
	infoCol.appendChild(textImgBlock);
	mainBlock.appendChild(infoCol);

	var mainImagePanel = document.createElement("div");
	mainImagePanel.className = "mainImage";
	var mainImage = document.createElement("img");
	mainImage.src = "/exhibition/img/exh_img_" + data.id + "_01.jpg";
	mainImage.alt = "";
	mainImage.width = "630";
	mainImage.height = "470";
	mainImagePanel.appendChild(mainImage);
	mainBlock.appendChild(mainImagePanel);
	
	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement4 = document.createElement("li");
	funcListElement4.className = "close";
	var closeImage = document.createElement("img");
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement4.appendChild(closeImage);
	funcList.appendChild(funcListElement4);
	
	var thumbList = document.createElement("ul");
	thumbList.className = "thumbUL";
	for (i=1; i<=data.imageNum; i++) {
		var thumbListElement = document.createElement("li");
		var thumbImage = document.createElement("img");
		thumbImage.className = "hover";
		if (i==1) {
			thumbImage.className = "stay";
		}
		var number = i <= 9 ? "0" + i : i;
		thumbImage.src = "/exhibition/img/exh_btn_" + data.id + "_" + number + ".gif";
		thumbImage.width = "30";
		thumbImage.height = "20";
		thumbListElement.appendChild(thumbImage);
		thumbList.appendChild(thumbListElement);
	}
	panel.appendChild(title);
	panel.appendChild(mainBlock);
	panel.appendChild(funcList);
	panel.appendChild(thumbList);
	$("div#body").append(panel);
	$("div#exhibitionPanel").show("slow");
	$("li.close img").click(hideExhibitionPanel);
	$("ul.thumbUL img.hover").click(changeImage);
	$.lm.hover.init();
}

// function hideExhibitionPanel (for EXHIBITION)
function hideExhibitionPanel(){
	$("div#exhibitionPanel").hide("slow", function(){
		$("div#exhibitionPanel").remove();
	});
}
