/*
* E&Y Collection(en)
* Require:
*  jquery.js
*
**************************************/

var currentData;
var orderData;
var sendStatus;

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


// function getData (for COLLECTION)
function getData(){
	$.getJSON(entryUrl[$("ul.categoryIndex img").index(this)], null, showPanel);
}

// function showPanel (for COLLECTION)
function showPanel(data){
	currentData = data;
	
	for (i=1; i<=data.imageNum; i++) {
		var mainImg = new Image();
		mainImg.src = "/en/collection/img/en_col_img_" + data.id + "_0" + i + ".jpg";
	}
	
	var panel = document.createElement("div");
	panel.id = "collectionPanel";

	var title = document.createElement("h2");
	var titleImg = document.createElement("img");
	titleImg.src = "/en/collection/img/en_col_ttl_" + data.id + ".gif";
	titleImg.alt = data.title + ", " + data.designer + ", " + data.year;
	title.appendChild(titleImg);
	
	var mainImagePanel = document.createElement("div");
	mainImagePanel.className = "mainImage";
	var mainImage = document.createElement("img");
	mainImage.src = "/en/collection/img/en_col_img_" + data.id + "_01.jpg";
	mainImage.alt = "";
	mainImage.width = "950";
	mainImage.height = "470";
	mainImagePanel.appendChild(mainImage);
	
	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement1 = document.createElement("li");
	var closeImage = document.createElement("img");
	closeImage.id = "closeBtn";
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement1.appendChild(closeImage);
	funcList.appendChild(funcListElement1);
	var funcListElement2 = document.createElement("li");
	var descImage = document.createElement("img");
	descImage.id = "descriptionBtn"
	descImage.className = "hover";
	descImage.src = "/shared/img/btn_description_01.gif";
	descImage.width = "73";
	descImage.height = "10";
	descImage.alt = "Description";
	funcListElement2.appendChild(descImage);
	funcList.appendChild(funcListElement2);
	var funcListElement3 = document.createElement("li");
	var downloadImage = document.createElement("img");
	downloadImage.id = "downloadBtn";
	downloadImage.className = "hover";
	downloadImage.src = "/shared/img/btn_download_01.gif";
	downloadImage.width = "64";
	downloadImage.height = "10";
	downloadImage.alt = "Download";
	funcListElement3.appendChild(downloadImage);
	funcList.appendChild(funcListElement3);
	
	$.getJSON("/en/collection/order/order" + currentData.id + ".js", null, function(){
		var funcListElement4 = document.createElement("li");
		var orderImage = document.createElement("img");
		orderImage.id = "orderBtn";
		orderImage.className = "hover";
		orderImage.src = "/shared/img/btn_order_01.gif";
		orderImage.width = "37";
		orderImage.height = "10";
		orderImage.alt = "Order";
		funcListElement4.appendChild(orderImage);
		funcList.appendChild(funcListElement4);
		$("img#orderBtn").click(getOrderData);
		$.lm.hover.init();
	});
	
	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";
		}
		thumbImage.src = "/en/collection/img/en_col_btn_" + data.id + "_0" + i + ".gif";
		thumbImage.width = "30";
		thumbImage.height = "20";
		thumbListElement.appendChild(thumbImage);
		thumbList.appendChild(thumbListElement);
	}
	panel.appendChild(title);
	panel.appendChild(mainImagePanel);
	panel.appendChild(funcList);
	panel.appendChild(thumbList);
	$("div#body").append(panel);
	$("div#collectionPanel").show("slow");
	$("img#closeBtn").click(hidePanel);
	$("img#descriptionBtn").click(showDescPanel);
	$("img#downloadBtn").click(showDlPanel);
	$("ul.thumbUL img.hover").click(changeImage);
	$.lm.hover.init();
}

// function hidePanel (for COLLECTION)
function hidePanel(){
	$("div#collectionPanel").hide("slow", function(){
		$("div#collectionPanel").remove();
	});
}

// function showDescPanel (for COLLECTION)
function showDescPanel(){
	for (i=1; i<=currentData.descNum; i++) {
		var mainImg = new Image();
		mainImg.src = "/en/collection/img/en_col_des_" + currentData.id + "_0" + i + ".jpg";
	}
	
	var panel = document.createElement("div");
	panel.id = "descriptionPanel";

	var mainImagePanel = document.createElement("div");
	mainImagePanel.className = "mainDescImage";
	var mainImage = document.createElement("img");
	mainImage.src = "/en/collection/img/en_col_des_" + currentData.id + "_01.jpg";
	mainImage.alt = "";
	mainImage.width = "950";
	mainImage.height = "470";
	mainImagePanel.appendChild(mainImage);
	
	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement1 = document.createElement("li");
	var closeImage = document.createElement("img");
	closeImage.id = "descCloseBtn";
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement1.appendChild(closeImage);
	funcList.appendChild(funcListElement1);

	var thumbList = document.createElement("ul");
	thumbList.className = "descThumbUL";
	for (i=1; i<=currentData.descNum; i++) {
		var thumbListElement = document.createElement("li");
		var thumbImage = document.createElement("img");
		thumbImage.className = "hover";
		if (i==1) {
			thumbImage.className = "stay";
		}
		thumbImage.src = "/en/collection/img/en_col_des_btn_" + currentData.id + "_0" + i + ".gif";
		thumbImage.width = "30";
		thumbImage.height = "20";
		thumbListElement.appendChild(thumbImage);
		thumbList.appendChild(thumbListElement);
	}

	panel.appendChild(mainImagePanel);
	panel.appendChild(funcList);
	panel.appendChild(thumbList);
	$("div#body").append(panel);
	$("div#descriptionPanel").show("slow");
	$("img#descCloseBtn").click(hideDescPanel);
	$("ul.descThumbUL img.hover").click(descChangeImage);
	$.lm.hover.init();
}

// function hideDescPanel (for COLLECTION)
function hideDescPanel(){
	$("div#descriptionPanel").hide("slow", function(){
		$("div#descriptionPanel").remove();
	});
}

// function descChangeImage (for COLLECTION)
function descChangeImage(evt) {
	var fileName = $(this).attr("src").replace("_btn", "");
	fileName = fileName.replace("_o", "");
	fileName = fileName.replace(".gif", ".jpg");
	$("div.mainDescImage").fadeOut("slow", function(){
		$("div.mainDescImage img").attr("src", fileName);
		$("div.mainDescImage").fadeIn("slow");
	});
	$("ul.descThumbUL img").removeClass("stay");
	$("ul.descThumbUL img").addClass("hover");
	$(this).removeClass("hover");
	$(this).addClass("stay");
	$(this)	
		.unbind('mouseover')
		.unbind('mouseout')
		.unbind('focus')
		.unbind('blur')
		.unbind('click');
	$(this).attr("src", $(this).attr("src").replace("_o", ""));
	$("ul.descThumbUL img.hover").click(descChangeImage);
	$.lm.hover.init();
}

// function showDlPanel (for COLLECTION)
function showDlPanel(){
	var panel = document.createElement("div");
	panel.id = "downloadPanel";

	var mainPanel = document.createElement("div");
	mainPanel.id = "mainPanel";
	var mainImagePanel = document.createElement("div");
	mainImagePanel.className = "mainDlImage";
	var mainImage = document.createElement("img");
	mainImage.src = "/en/collection/img/en_col_dld_" + currentData.id + ".jpg";
	mainImage.alt = "";
	mainImagePanel.appendChild(mainImage);
	mainPanel.appendChild(mainImage);
	
	var dlLinkPanel = document.createElement("div");
	dlLinkPanel.id = "linkPanel";
	var dlLinkElem = document.createElement("a");
	dlLinkElem.href = "/en/collection/zip/" + currentData.zip;
	var dlLinkImage = document.createElement("img");
	dlLinkImage.src = "/en/collection/img/en_col_dld_txt_" + currentData.id + ".gif";
	dlLinkImage.className = "hover";
	dlLinkImage.alt = currentData.zip;
	dlLinkElem.appendChild(dlLinkImage);
	dlLinkPanel.appendChild(dlLinkElem);
	mainPanel.appendChild(dlLinkPanel);
	
	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement1 = document.createElement("li");
	var closeImage = document.createElement("img");
	closeImage.id = "dlCloseBtn";
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement1.appendChild(closeImage);
	funcList.appendChild(funcListElement1);

	panel.appendChild(mainPanel);
	panel.appendChild(funcList);
	$("div#body").append(panel);
	$("div#downloadPanel").show("slow");
	$("img#dlCloseBtn").click(hideDlPanel);
	$.lm.hover.init();
}

// function hideDlPanel (for COLLECTION)
function hideDlPanel(){
	$("div#downloadPanel").hide("slow", function(){
		$("div#downloadPanel").remove();
	});
}

// function getOrderData (for COLLECTION)
function getOrderData(){
	$.getJSON("/en/collection/order/order" + currentData.id + ".js", null, showOrderPanel);
}

// function showOrderPanel (for COLLECTION)
function showOrderPanel(data){
	orderData = data;
	
	var panel = document.createElement("div");
	panel.id = "orderPanel";

	var innerPanel = document.createElement("div");
	innerPanel.id = "innerPanel";
	
	var textImagePanel = document.createElement("div");
	textImagePanel.className = "orderText";
	var textImage = document.createElement("img");
	textImage.src = "/en/collection/img/order/en_col_ord_txt_" + currentData.id + ".gif";
	textImage.alt = orderData.text;
	textImagePanel.appendChild(textImage);
	innerPanel.appendChild(textImagePanel);

	var selectPanel = document.createElement("div");
	selectPanel.className = "orderBlock";
	var itemID = 1;
	for (i in orderData.items){
		var selectItem = document.createElement("div");
		selectItem.className = "orderItem";
		var itemThumb = document.createElement("div");
		itemThumb.className = "thumb";
		var itemThumbImage = document.createElement("img");
		var itemThumbNum = itemID > 9 ? itemID : "0" + itemID;
		itemThumbImage.src = "/en/collection/img/order/en_col_ord_img_" + currentData.id + "_" + itemThumbNum + ".gif";
		itemThumbImage.alt = orderData.items[i].name;
		itemThumb.appendChild(itemThumbImage);
		selectItem.appendChild(itemThumb);
		
		var checkList = document.createElement("ul");
		checkList.className = "checkList";
		checkList.id = i;
		var listID = 1;
		for (j in orderData.items[i].subitems) {
			var listItem = document.createElement("li");
			var listImage = document.createElement("img");
			listImage.id = j;
			var listNum = listID > 9 ? listID : "0" + listID;
			listImage.src = "/en/collection/img/order/en_col_ord_che_" + currentData.id + "_" + itemThumbNum + "_" + listNum + ".gif";
			listImage.className = "clickable";
			listImage.alt = orderData.items[i].subitems[j].name + ":&yen;" + orderData.items[i].subitems[j].price + "(In tax)";
			listItem.appendChild(listImage);
			checkList.appendChild(listItem);
			listID++;
		}
		selectItem.appendChild(checkList);
		selectPanel.appendChild(selectItem);
		itemID++;
	}
	innerPanel.appendChild(selectPanel);
	
	var fabricBlock = document.createElement("div");
	fabricBlock.className = "fabricBlock";
	if(orderData.fabric){
		var fabricTitle = document.createElement("div");
		fabricTitle.className = "fabricTitle";
		var fabricTitleImage = document.createElement("img");
		fabricTitleImage.src = "/shared/img/order_text_01.gif";
		fabricTitleImage.alt = "FABRIC SAMPLE";
		fabricTitle.appendChild(fabricTitleImage);
		fabricBlock.appendChild(fabricTitle);
		var fabricList = document.createElement("ul");
		for(k in orderData.fabric){
			var fabricListElem = document.createElement("li");
			var fabricImage = document.createElement("img");
			switch(orderData.fabric[k]){
				case 1:
					fabricImage.src = "/shared/img/btn_fabric_01.gif";
					fabricImage.id = "fabric1";
					fabricImage.alt = "A TYPE-NS";
					break;
				case 2:
					fabricImage.src = "/shared/img/btn_fabric_02.gif";
					fabricImage.id = "fabric2";
					fabricImage.alt = "A TYPE-SU";
					break;
				case 3:
					fabricImage.src = "/shared/img/btn_fabric_03.gif";
					fabricImage.id = "fabric3";
					fabricImage.alt = "VINYL LEATHER A TYPE-LG";
					break;
				case 4:
					fabricImage.src = "/shared/img/btn_fabric_04.gif";
					fabricImage.id = "fabric4";
					fabricImage.alt = "B TYPE-CL";
					break;
				case 5:
					fabricImage.src = "/shared/img/btn_fabric_05.gif";
					fabricImage.id = "fabric5";
					fabricImage.alt = "B TYPE-FK";
					break;
				case 6:
					fabricImage.src = "/shared/img/btn_fabric_06.gif";
					fabricImage.id = "fabric6";
					fabricImage.alt = "C TYPE-EC";
					break;
				case 7:
					fabricImage.src = "/shared/img/btn_fabric_07.gif";
					fabricImage.id = "fabric7";
					fabricImage.alt = "D TYPE-NV";
					break;
				case 8:
					fabricImage.src = "/shared/img/btn_fabric_08.gif";
					fabricImage.id = "fabric8";
					fabricImage.alt = "D TYPE-EP";
					break;
			}
			fabricImage.className = "fabricBtn";
			fabricImage.className = "hover";
			fabricListElem.appendChild(fabricImage);
			fabricList.appendChild(fabricListElem);
		}
		fabricBlock.appendChild(fabricList);
	}
	innerPanel.appendChild(fabricBlock);
	
	var attentionBlock = document.createElement("div");
	attentionBlock.className = "attentionBlock";
	var attentionCol1 = document.createElement("div");
	attentionCol1.className = "col1";
	var attentionTitle = document.createElement("div");
	attentionTitle.className = "attentionTitle";
	var attentionTitleImage = document.createElement("img");
	attentionTitleImage.src = "/shared/img/order_text_02.gif";
	attentionTitleImage.alt = "ATTENTION";
	attentionTitle.appendChild(attentionTitleImage);
	attentionCol1.appendChild(attentionTitle);
	if(orderData.attention){
		var attention = document.createElement("div");
		attention.className = "attentionText";
		attentionImage = document.createElement("img");
		attentionImage.src = "/en/collection/img/order/en_col_ord_att_" + currentData.id + ".gif";
		attentionImage.alt = orderData.attention;
		attention.appendChild(attentionImage);
		attentionCol1.appendChild(attention);
	}
	attentionBlock.appendChild(attentionCol1);
	var attentionCol2 = document.createElement("div");
	attentionCol2.className = "col2";
	var nextImage = document.createElement("img");
	nextImage.src = "/collection/img/order/btn_next_01.gif";
	nextImage.className = "hover";
	nextImage.id = "showOrderSum";
	attentionCol2.appendChild(nextImage);
	attentionBlock.appendChild(attentionCol2);
	innerPanel.appendChild(attentionBlock);
	panel.appendChild(innerPanel);
	
	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement1 = document.createElement("li");
	var closeImage = document.createElement("img");
	closeImage.id = "orderCloseBtn";
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement1.appendChild(closeImage);
	funcList.appendChild(funcListElement1);
	var funcListElement2 = document.createElement("li");
	var descImage = document.createElement("img");
	descImage.id = "descriptionBtn2"
	descImage.className = "hover";
	descImage.src = "/shared/img/btn_description_01.gif";
	descImage.width = "73";
	descImage.height = "10";
	descImage.alt = "Description";
	funcListElement2.appendChild(descImage);
	funcList.appendChild(funcListElement2);
	var funcListElement3 = document.createElement("li");
	var csImage = document.createElement("img");
	csImage.id = "csBtn";
	csImage.className = "hover";
	csImage.src = "/shared/img/btn_cs_01.gif";
	csImage.width = "110";
	csImage.height = "10";
	csImage.alt = "Customer Service";
	funcListElement3.appendChild(csImage);
	funcList.appendChild(funcListElement3);
	panel.appendChild(funcList);

	$("div#body").append(panel);
	$("div.orderItem").addClassFLtoDiv(4);
	$("ul.checkList li img").click(checkItem);
	$("img#orderCloseBtn").click(hideOrderPanel);
	$("img#descriptionBtn2").click(showDescPanel);
	$("img#csBtn").click(showCSPanel);
	$("div.fabricBlock ul li img").click(showFabric);
	$("img#showOrderSum").click(showOrderSum);
	$("div#orderPanel").show("slow");
	$.lm.hover.init();
}

function checkItem(evt){
	if(evt.target.src.indexOf("_c.gif") > 0){
		orderData.items[evt.target.parentNode.parentNode.id].subitems[evt.target.id].num = 0;
		evt.target.src = evt.target.src.replace(/^(.+)_c(\.[a-z]+)$/, "$1$2");
	} else {
		orderData.items[evt.target.parentNode.parentNode.id].subitems[evt.target.id].num = 1;
		evt.target.src = evt.target.src.replace(/^(.+)(\.[a-z]+)$/, "$1_c$2");
	}
}

// function hideOrderPanel (for COLLECTION)
function hideOrderPanel(){
	$("div#orderPanel").hide("slow", function(){
		$("div#orderPanel").remove();
	});
}

// function showCSPanel (for COLLECTION)
function showCSPanel(evt){
	var panel = document.createElement("div");
	panel.id = "csPanel";

	var mainPanel = document.createElement("div");
	mainPanel.className = "csInnerPanel";

	mainPanel.innerHTML = "<h1><img src='/en/collection/img/order/en_cus_h1_01.gif' alt='CUSTOMER SERVICE' /></h1>\
<h2><img src='/en/collection/img/order/en_cus_h2_01.gif' alt='COMPANY NAME' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_01_01.gif' alt='E&amp;Y CO.,LTD' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_02.gif' alt='ADDRESS' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_02_01.gif' alt='1-32-17 UNS, Komaba, Meguro-ku, Tokyo, 153-0041 JAPAN' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_03.gif' alt='TERMS OF PAYMENT' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_03_01.gif' alt='Bank transfer in advance. With in 7 days, E&amp;Y received the order. ' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_04.gif' alt='BANK DETAILS' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_04_01.gif' alt='Bank name : Bank of Tokyo-Mitsubishi UFJ Branch : Omotesando Account code : 1766563 Account name : E and Y Co.,LTD Swift code : BOTKJPT' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_05.gif' alt='COMPLAINTS' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_05_01.gif' alt='Complaints must be received by E&amp;Y within 7 days of receipt of goods. Delivered goods must not be returned without E&amp;Y consent.' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_06.gif' alt='GUARANTEE' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_06_01.gif' alt='The products are guaranteed for one year from the date of purchase.During this period, any damage that occurs due to bad quality will be replaced free of charge.' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_07.gif' alt='E&amp;Y WILL NOT TAKE RESPONSIBILITY FOR THE FOLLOWING' /></h2>\
<p><img src='/en/collection/img/order/en_cus_text_07_01.gif' alt='- Discoloration,or deterioration due to direct sunlight, or heart from electrical appliances such as air conditioner. - Any damage that occurs after delivery - Any intentionally caused damage, or damage due to negligence.' /></p>\
<h2><img src='/en/collection/img/order/en_cus_h2_08.gif' alt='RESTRICTIONS' /></h2>\
<p class='last'><img src='/en/collection/img/order/en_cus_text_08_01.gif' alt='E&amp;Y may make price adjustments and design modifications without previous notification. * The price is Japanese domestic price. Please contact us for pricing and shipping charge.' /></p>";

	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement1 = document.createElement("li");
	var closeImage = document.createElement("img");
	closeImage.id = "csCloseBtn";
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement1.appendChild(closeImage);
	funcList.appendChild(funcListElement1);

	panel.appendChild(mainPanel);
	panel.appendChild(funcList);
	$("div#body").append(panel);
	$("div#csPanel").show("slow");
	$("img#csCloseBtn").click(hideCSPanel);
	$.lm.hover.init();
}

// function hideCSPanel (for COLLECTION)
function hideCSPanel(){
	$("div#csPanel").hide("slow", function(){
		$("div#csPanel").remove();
	});
}

// function showFabric
function showFabric(evt){
	var fabricID = evt.target.id.replace("fabric", "");

	var panel = document.createElement("div");
	panel.id = "fabricPanel";

	var mainImagePanel = document.createElement("div");
	mainImagePanel.className = "mainImage";
	var mainImage = document.createElement("img");
	mainImage.src = "/en/collection/img/order/en_col_ord_fab_" + currentData.id + "_0" + fabricID + ".jpg";
	mainImage.alt = "";
	mainImage.width = "950";
	mainImage.height = "470";
	mainImagePanel.appendChild(mainImage);
	
	var funcList = document.createElement("ul");
	funcList.className = "funcUL";
	var funcListElement1 = document.createElement("li");
	var closeImage = document.createElement("img");
	closeImage.id = "fabricCloseBtn";
	closeImage.className = "hover";
	closeImage.src = "/shared/img/btn_close_01.gif";
	closeImage.width = "35";
	closeImage.height = "10";
	closeImage.alt = "Close";
	funcListElement1.appendChild(closeImage);
	funcList.appendChild(funcListElement1);

	panel.appendChild(mainImagePanel);
	panel.appendChild(funcList);
	$("div#body").append(panel);
	$("div#fabricPanel").show("slow");
	$("img#fabricCloseBtn").click(hideFabricPanel);
	$("ul.fabricThumbUL img.hover").click(changeImage);
	$.lm.hover.init();
}

// function hideFabricPanel (for COLLECTION)
function hideFabricPanel(){
	$("div#fabricPanel").hide("slow", function(){
		$("div#fabricPanel").remove();
	});
}

// function showOrderSum (for COLLECTION)
function showOrderSum(){
	$("div#innerPanel").fadeOut("slow", function(){
		$("div#innerPanel").empty();
		
		var totalPrice = 0;
		var orderTable = "<div class='orderTableBlock'><table class='orderTable'><tr><th><img src='/collection/img/order/order_text_01.gif' alt='Item' /></th><th class='price'><img src='/collection/img/order/order_text_02.gif' alt='Unit Price(In tax)' /></th><th class='quantity'><img src='/collection/img/order/order_text_03.gif' alt='Quantity' /></th><th class='price'><img src='/collection/img/order/order_text_04.gif' alt='Price(In tax)' /></th></tr><tbody>";
		for(i in orderData.items){
			for(j in orderData.items[i].subitems){
				if(orderData.items[i].subitems[j].num > 0){
					orderTable += "<tr><td>" + orderData.items[i].name + " - " + orderData.items[i].subitems[j].name + "</td><td class='price'>&yen;" + formatPrice(orderData.items[i].subitems[j].price) + "</td><td class='quantity'><input name='" + j + "' id='" + j + "' type='text' value='" + orderData.items[i].subitems[j].num + "' /></td><td id='" + j + "total' class='price'>&yen;" + formatPrice(orderData.items[i].subitems[j].price * orderData.items[i].subitems[j].num) + "</td></tr>";
					totalPrice += orderData.items[i].subitems[j].price * orderData.items[i].subitems[j].num;
				}
			}
		}
		orderTable += "</tbody></table></div>";
		$("div#innerPanel").append(orderTable);
		
		var totalTable = "<table class='totalTable'><tr><th><img src='/collection/img/order/order_text_05.gif' alt='Total Price(In tax)' /></th><td>&yen;" + formatPrice(totalPrice) + "</td></tr></table>";
		$("div#innerPanel").append(totalTable);
		
		var navigationBlock = "<div class='orderNav'><div class='col1'><img id='backBtn1' class='hover' src='/collection/img/order/btn_back_01.gif' alt='Back' /></div><div class='col2'><img id='nextBtn2' class='hover' src='/collection/img/order/btn_next_01.gif' alt='Next' /></div>"
		$("div#innerPanel").append(navigationBlock);
		$("table.orderTable input").change(changeItemQuantity);
		$("img#backBtn1").click(backOrderPanel);
		$("img#nextBtn2").click(showOrderForm);
		$("div#innerPanel").fadeIn("slow");
		$.lm.hover.init();
	});
}

// function changeItemQuantity (for COLLECTION)
function changeItemQuantity(evt){
	var parentID = evt.target.id.substr(0, 6);
	if(isNaN(evt.target.value)){
		orderData.items[parentID].subitems[evt.target.id].num = 0;
	} else {
		orderData.items[parentID].subitems[evt.target.id].num = evt.target.value;
	}
	var priceID = "#" + evt.target.id + "total";
	$(priceID).html("&yen;" + formatPrice(orderData.items[parentID].subitems[evt.target.id].num * orderData.items[parentID].subitems[evt.target.id].price));
	var totalPrice = 0;
	for(i in orderData.items){
		for(j in orderData.items[i].subitems){
			if(orderData.items[i].subitems[j].num > 0){
				totalPrice += orderData.items[i].subitems[j].price * orderData.items[i].subitems[j].num;
			}
		}
	}
	$("table.totalTable td").html("&yen;" + formatPrice(totalPrice));
}

// function backOrderPanel (for COLLECTION)
function backOrderPanel(evt){
	$("div#innerPanel").fadeOut("slow", function(){
		$("div#innerPanel").empty();

		var textImagePanel = document.createElement("div");
		textImagePanel.className = "orderText";
		var textImage = document.createElement("img");
		textImage.src = "/en/collection/img/order/en_col_ord_txt_" + currentData.id + ".gif";
		textImage.alt = orderData.text;
		textImagePanel.appendChild(textImage);
		$("div#innerPanel").append(textImagePanel);

		var selectPanel = document.createElement("div");
		selectPanel.className = "orderBlock";
		var itemID = 1;
		for (i in orderData.items){
			var selectItem = document.createElement("div");
			selectItem.className = "orderItem";
			var itemThumb = document.createElement("div");
			itemThumb.className = "thumb";
			var itemThumbImage = document.createElement("img");
			var itemThumbNum = itemID > 9 ? itemID : "0" + itemID;
			itemThumbImage.src = "/en/collection/img/order/en_col_ord_img_" + currentData.id + "_" + itemThumbNum + ".gif";
			itemThumbImage.alt = orderData.items[i].name;
			itemThumb.appendChild(itemThumbImage);
			selectItem.appendChild(itemThumb);
			
			var checkList = document.createElement("ul");
			checkList.className = "checkList";
			checkList.id = i;
			var listID = 1;
			for (j in orderData.items[i].subitems) {
				var listItem = document.createElement("li");
				var listImage = document.createElement("img");
				listImage.id = j;
				var listNum = listID > 9 ? listID : "0" + listID;
				if(orderData.items[i].subitems[j].num > 0){
					listImage.src = "/en/collection/img/order/en_col_ord_che_" + currentData.id + "_" + itemThumbNum + "_" + listNum + "_c.gif";
					orderData.items[i].subitems[j].num = 1;
				} else {
					listImage.src = "/en/collection/img/order/en_col_ord_che_" + currentData.id + "_" + itemThumbNum + "_" + listNum + ".gif";
				}
				listImage.className = "clickable";
				listImage.alt = orderData.items[i].subitems[j].name + ":&yen;" + orderData.items[i].subitems[j].price + "(In tax)";
				listItem.appendChild(listImage);
				checkList.appendChild(listItem);
				listID++;
			}
			selectItem.appendChild(checkList);
			itemID++;
			selectPanel.appendChild(selectItem);
		}
		$("div#innerPanel").append(selectPanel);

		var fabricBlock = document.createElement("div");
		fabricBlock.className = "fabricBlock";
		if(orderData.fabric){
			var fabricTitle = document.createElement("div");
			fabricTitle.className = "fabricTitle";
			var fabricTitleImage = document.createElement("img");
			fabricTitleImage.src = "/shared/img/order_text_01.gif";
			fabricTitleImage.alt = "FABRIC SAMPLE";
			fabricTitle.appendChild(fabricTitleImage);
			fabricBlock.appendChild(fabricTitle);
			var fabricList = document.createElement("ul");
			for(k in orderData.fabric){
				var fabricListElem = document.createElement("li");
				var fabricImage = document.createElement("img");
				switch(orderData.fabric[k]){
					case 1:
						fabricImage.src = "/shared/img/btn_fabric_01.gif";
						fabricImage.id = "fabric1";
						fabricImage.alt = "A TYPE-NS";
						break;
					case 2:
						fabricImage.src = "/shared/img/btn_fabric_02.gif";
						fabricImage.id = "fabric2";
						fabricImage.alt = "A TYPE-SU";
						break;
					case 3:
						fabricImage.src = "/shared/img/btn_fabric_03.gif";
						fabricImage.id = "fabric3";
						fabricImage.alt = "VINYL LEATHER A TYPE-LG";
						break;
					case 4:
						fabricImage.src = "/shared/img/btn_fabric_04.gif";
						fabricImage.id = "fabric4";
						fabricImage.alt = "B TYPE-CL";
						break;
					case 5:
						fabricImage.src = "/shared/img/btn_fabric_05.gif";
						fabricImage.id = "fabric5";
						fabricImage.alt = "B TYPE-FK";
						break;
					case 6:
						fabricImage.src = "/shared/img/btn_fabric_06.gif";
						fabricImage.id = "fabric6";
						fabricImage.alt = "C TYPE-EC";
						break;
					case 7:
						fabricImage.src = "/shared/img/btn_fabric_07.gif";
						fabricImage.id = "fabric7";
						fabricImage.alt = "D TYPE-NV";
						break;
					case 8:
						fabricImage.src = "/shared/img/btn_fabric_08.gif";
						fabricImage.id = "fabric8";
						fabricImage.alt = "D TYPE-EP";
						break;
				}
				fabricImage.className = "fabricBtn";
				fabricImage.className = "hover";
				fabricListElem.appendChild(fabricImage);
				fabricList.appendChild(fabricListElem);
			}
			fabricBlock.appendChild(fabricList);
		}
		$("div#innerPanel").append(fabricBlock);
		
		var attentionBlock = document.createElement("div");
		attentionBlock.className = "attentionBlock";
		var attentionCol1 = document.createElement("div");
		attentionCol1.className = "col1";
		var attentionTitle = document.createElement("div");
		attentionTitle.className = "attentionTitle";
		var attentionTitleImage = document.createElement("img");
		attentionTitleImage.src = "/shared/img/order_text_02.gif";
		attentionTitleImage.alt = "ATTENTION";
		attentionTitle.appendChild(attentionTitleImage);
		attentionCol1.appendChild(attentionTitle);
		if(orderData.attention){
			var attention = document.createElement("div");
			attention.className = "attentionText";
			attentionImage = document.createElement("img");
			attentionImage.src = "/en/collection/img/order/en_col_ord_att_" + currentData.id + ".gif";
			attentionImage.alt = orderData.attention;
			attention.appendChild(attentionImage);
			attentionCol1.appendChild(attention);
		}
		attentionBlock.appendChild(attentionCol1);
		var attentionCol2 = document.createElement("div");
		attentionCol2.className = "col2";
		var nextImage = document.createElement("img");
		nextImage.src = "/collection/img/order/btn_next_01.gif";
		nextImage.className = "hover";
		nextImage.id = "showOrderSum";
		attentionCol2.appendChild(nextImage);
		attentionBlock.appendChild(attentionCol2);
		$("div#innerPanel").append(attentionBlock);

		$("div.orderItem").addClassFLtoDiv(4);
		$("ul.checkList li img").click(checkItem);
		$("img#orderCloseBtn").click(hideOrderPanel);
		$("img#descriptionBtn2").click(showDescPanel);
		$("div.fabricBlock ul li img").click(showFabric);
		$("img#showOrderSum").click(showOrderSum);

		$("div#innerPanel").fadeIn("slow");
		$.lm.hover.init();
	});
}

// function showOrderForm (for COLLECTION)
function showOrderForm(){
	$("div#innerPanel").fadeOut("slow", function(){
		$("div#innerPanel").empty();
		
		var orderFormBlock = "<div class='orderFormBlock'><div class='col1'></div><div class='col2'></div><div class='col3'></div></div>";
		$("div#innerPanel").append(orderFormBlock);
		
		var totalPrice = 0;
		var orderTable = "<div class='orderTableBlock'><table class='orderTable2'><tr><th><img src='/collection/img/order/order_text_01.gif' alt='Item' /></th><th class='quantity'><img src='/collection/img/order/order_text_03.gif' alt='Quantity' /></th></tr><tbody>";
		for(i in orderData.items){
			for(j in orderData.items[i].subitems){
				if(orderData.items[i].subitems[j].num > 0){
					orderTable += "<tr><td>" + orderData.items[i].name + " - " + orderData.items[i].subitems[j].name + "</td><td class='quantity'>" + orderData.items[i].subitems[j].num + "</td></tr>";
					totalPrice += orderData.items[i].subitems[j].price * orderData.items[i].subitems[j].num;
				}
			}
		}
		orderTable += "</tbody></table></div>";
		$("div.orderFormBlock div.col1").append(orderTable);
		
		var totalTable = "<table class='totalTable'><tr><th><img src='/collection/img/order/order_text_05.gif' alt='Total Price(In tax)' /></th><td>&yen;" + formatPrice(totalPrice) + "</td></tr></table>";
		$("div.orderFormBlock div.col1").append(totalTable);

		var form1 = "<p class='label'><label for='name'><img src='/en/collection/img/order/order_text_06.gif' alt='NAME' width='32' height='10' /></label></p>\
		<p class='form'><input name='name' id='name' type='text' /></p>\
		<p class='label'><label for='zip'><img src='/en/collection/img/order/order_text_07.gif' alt='POST CODE' width='61' height='10' /></label></p>\
		<p class='form'><input name='zip' id='zip' type='text' /></p>\
		<p class='label'><label for='address'><img src='/en/collection/img/order/order_text_08.gif' alt='ADDRESS' width='52' height='10' /></label></p>\
		<p class='form'><input name='address' id='address' type='text' /></p>\
		<p class='label'><label for='phone'><img src='/en/collection/img/order/order_text_09.gif' alt='TELEPHONE NUMBER' width='117' height='10' /></label></p>\
		<p class='form'><input name='phone' id='phone' type='text' /></p>\
		<p class='label'><label for='fax'><img src='/en/collection/img/order/order_text_10.gif' alt='FAX' width='20' height='10' /></label></p>\
		<p class='form'><input name='fax' id='fax' type='text' /></p>\
		<p class='label'><label for='email'><img src='/en/collection/img/order/order_text_11.gif' alt='EMAIL' width='33' height='10' /></label></p>\
		<p class='form'><input name='email' id='email' type='text' /></p>\
		<input type='hidden' name='category' id='category' value='en' />";
		$("div.orderFormBlock div.col2").html(form1);
		
		var form2 = "	<p class='label'><img src='/en/collection/img/order/order_text_12.gif' alt='How would we get in touch with you?' width='194' height='12' /><input class='check' type='hidden' name='check1' id='check1' value='false' /><input class='check' type='hidden' name='check2' id='check2' value='false' /><input class='check' type='hidden' name='check3' id='check3' value='false' /></p>\
		<ul class='form'>\
			<li><img id='check1Btn' src='/en/collection/img/order/order_check_01.gif' alt='Email' width='49' height='10' class='check' /></li>\
			<li><img id='check2Btn' src='/en/collection/img/order/order_check_02.gif' alt='Tel' width='35' height='10' class='check' /></li>\
			<li><img id='check3Btn' src='/en/collection/img/order/order_check_03.gif' alt='Fax' width='37' height='10' class='check' /></li>\
		</ul>\
		<p class='label'><label for='comment'><img src='/en/collection/img/order/order_text_13.gif' alt='QUESTIONS / INQUIRIES' width='130' height='10' /></label></p>\
		<p class='form'><textarea name='comment' id='comment' cols='40' rows='20'></textarea></p>";
		$("div.orderFormBlock div.col3").html(form2);

		var navigationBlock = "<div class='orderNav'><div class='col1'><img id='backBtn2' class='hover' src='/collection/img/order/btn_back_01.gif' alt='Back' /></div><div class='col2'><img id='orderBtn2' class='hover' src='/collection/img/order/btn_order_01.gif' alt='Order' /></div>"
		$("div#innerPanel").append(navigationBlock);
		
		$("img#backBtn2").click(showOrderSum);
		$("div#innerPanel").fadeIn("slow");
		$("img#orderBtn2").click(postData);
		$("img.check").click(toggleCheck);
		$.lm.hover.init();
	});
}

// function postData (for COLLECTION)
function postData(){
	var data = {};
	var count = 0;
	var totalPrice = 0;
	data.product = currentData.title;
	data.order = "";
	for(i in orderData.items){
		for(j in orderData.items[i].subitems){
			if(orderData.items[i].subitems[j].num > 0){
				data.order += orderData.items[i].name + " - " + orderData.items[i].subitems[j].name + " ￥" + orderData.items[i].subitems[j].price + "×" + orderData.items[i].subitems[j].num + "\r\n";
				totalPrice += orderData.items[i].subitems[j].price * orderData.items[i].subitems[j].num;
				count++;
			}
		}
	}
	data.totalprice = totalPrice;
	data.category = $("input#category").val();
	data.name = $("input#name").val();
	data.zip = $("input#zip").val();
	data.address = $("input#address").val();
	data.email = $("input#email").val();
	data.phone = $("input#phone").val();
	data.fax = $("input#fax").val();
	data.check1 = $("input#check1").val();
	data.check2 = $("input#check2").val();
	data.check3 = $("input#check3").val();
	data.comment = $("textarea#comment").val();
	$.post("/collection/order/order.php", data, showResult, "text");
}

// function showResult (for CONTACT)
function showResult(data){
	sendStatus = data;

	$("img#submit").unbind("click").unbind("mouseover").unbind("mouseout").unbind("focus").unbind("blur").attr("src", "/contact/img/btn_01_o.gif");
	var message;

	if(data == 1){
		message = "Message was send.<br />Thank You.";
	} else if(data == 2){
		message = "Please input &ldquo;NAME&rdquo;.";
	} else if(data == 3){
		message = "Please input &ldquo;Kana&rdquo;.";
	} else if(data == 4){
		message = "Please input &ldquo;EMAIL&rdquo;.";
	} else if(data == 5){
		message = "Your E-mail address is not valid.<br />Please input your correct E-mail address.";
	} else if(data == 6){
		message = "Please input &ldquo;COMMENT&rdquo;.";
	} else if(data == 7){
		message = "Please input &ldquo;COMPANY&rdquo;.";
	} else if(data == 8){
		message = "Please input &ldquo;TEL&rdquo;.";
	} else if(data == 9){
		message = "Please input &ldquo;ADMINISTRATOR&rdquo;.";
	} else if(data == 10){
		message = "No item selected.<br />Please select item.";
	} else if(data == 11){
		message = "Please input &ldquo;NAME&rdquo;.";
	} else if(data == 12){
		message = "Please input &ldquo;POST CODE&rdquo;.";
	} else if(data == 13){
		message = "Please input &ldquo;ADDRESS&rdquo;.";
	} else if(data == 14){
		message = "Please input &ldquo;TELEPHONE NUMBER&rdquo;.";
	} else if(data == 15){
		message = "Please select &ldquo;How would we get in touch with you?&rdquo;.";
	} else {
		message = "An Error occurred.<br />Send a message to <a href='mailto:info@eandy.com'>Info</a> please.";
	}
	
	var resultPanel = document.createElement("div");
	resultPanel.id = "resultPanel";
	var resultMessage = document.createElement("p");
	resultMessage.innerHTML = message;
	resultPanel.appendChild(resultMessage);
	$("div#body").append(resultPanel);
	$("div#resultPanel").fadeIn("slow", function(){
		hideTimer = setTimeout("hideResult()", 3000);
	});
}

// function hideResult (for COLLECTION)
function hideResult(){
	$("div#resultPanel").fadeOut("slow", function(){
		$("div#resultPanel").remove();
		$("img#orderBtn2").attr("src", "/collection/img/order/btn_order_01.gif");
		$.lm.hover.init();
		$("img#orderBtn2").click(postData);
		if(sendStatus == 1){
			location.href = "/en/collection/";
		}
	});
}
