
//  Page set Items detail
//---------------------------------------------------------------------------------------
var imageDir = "/scripts/";
var puTarget = "./items/reservation.html"; //  ""; = no link
var puOff = imageDir + "sp_off.gif";
var puOn = imageDir + "sp_on.gif";
var puWidth = 400;

var pictitle;
var pu;


//  Popup
//---------------------------------------------------------
function puMove(e) {
	pu.style.left =	getMouseX(e) + 5 + "px";
	pu.style.top = getMouseY(e) + -30 + "px";
}
function getMouseX(e){
	if(window.opera)      { return e.clientX;}
	else if(document.all) { return document.body.scrollTop+event.clientX;}
	else                  { return e.pageX;}
}
function getMouseY(e){
	if(window.opera)      { return e.clientY;}
	else if(document.all) { return document.body.scrollTop+event.clientY;}
	else                  { return e.pageY;}
}
//  pop up down
function set_popUp(BRAND)   {
	var func =function () {
		pu.innerHTML = "<img src=\"" + imageDir + BRAND + ".gif\" alt=\"" + BRAND.toUpperCase() + "\">";
		pu.style.display = "block";
	}
	return func;
}
function set_popDown() {
	var func = function () {
		pu.innerHTML = "";
		pu.style.display = "none";
	}
	return func;
}

//  Function set
//---------------------------------------------------------
function img_change(_uri, _text) {
	var func = function() {
		var uri = _uri;
		document.getElementById("main-picture").src = uri;
		pictitle.innerHTML = _text;
	}
	return func;
}

//  Page set Items detail
//----------------------------------------------------------
function pageset_items_detail() {
	//  get thumbnail list
	var max = document.getElementById("thumbs").childNodes.length;
	var thumb_list;
	for (i=0;i<max;i++) {
		if (document.getElementById("thumbs").childNodes[i].nodeName.toLowerCase() == "ul") {
			thumb_list = document.getElementById("thumbs").childNodes[i].childNodes;
		}
	}
	
	//  set function
	max = thumb_list.length;
	for (i=0;i<max;i++) {
		thumb_list[i].onmouseover = img_change(thumb_list[i].firstChild.src,thumb_list[i].firstChild.alt);
	}
	
	//  set pictitle
	pictitle = document.createElement("p");
	pictitle.style.position = "absolute";
	var left = document.getElementById("content").offsetLeft + 179;
	var top = document.getElementById("content").offsetTop + 31;
	pictitle.style.left = left + "px";
	pictitle.style.top =top + "px";
	pictitle.style.padding = "0px 3px";
	pictitle.style.fontSize = "135%";
	pictitle.style.fontWeight = "bold";
	pictitle.innerHTML = thumb_list[0].firstChild.alt;
	document.body.appendChild(pictitle);
}

//  Page set Items new
//----------------------------------------------------------
function pageset_items_new() {
	var itemlist = document.getElementById("item-list").childNodes;
	var imax = itemlist.length;
	var b = "";
	var brand = "";
	for (i=0;i<imax;i++) {
		if (itemlist[i].firstChild) {
			b = itemlist[i].firstChild.firstChild.alt.substr(0,1);
			switch (b) {
				case "M":
					brand = "manufactory";
					break;
				case "S":
					brand = "suspereal";
					break;
				case "A":
					brand = "allyanddia";
					break;
				case "h":
				case "H":
					brand = "haughty";
					break;
				case "f":
					brand = "footgear";
					break;
				/*
				case "V":
					brand = "virgo";
					break;
				case "R":
					brand = "ropesambas";
					break;
				*/
				default:
					brand = "other";
			}
			itemlist[i].firstChild.onmouseover = set_popUp(brand);
			itemlist[i].firstChild.onmouseout = set_popDown();
		}
	}
	
	//  create popup layer
	pu =document.createElement("div");
	pu.id = "PopUp"
	document.body.appendChild(pu);

	//  set popup style
	pu.style.position = "absolute";
	pu.style.display  = "none";

	//  set popup move
	document.onmousemove = puMove;
}

//  Page set Toppage
//----------------------------------------------------------
function pageset_toppage() {

	//  create layer
	sp =document.createElement("div");
	sp.id = "sp"
	document.body.appendChild(sp);

	//  set style
	var left = document.getElementById("gn").offsetLeft + 480;
	var top = 20;
	sp.style.position = "absolute";
	sp.style.left = left + "px";
	sp.style.top = top + "px";
	sp.style.width = puWidth + "px";
	sp.style.textAlign = "center";
	sp.style.backgroundColor = "#FFFFFF";
	sp.style.border = "1px #666666 solid";
	sp.innerHTML = "<a id=\"sp-button\" href=\"javascript:void(0);\" style=\"display: block; text-align: right; padding: 5px;\">CLOSE</a>";
	if (puTarget.length > 0) {
		sp.innerHTML += "<a href=\"" + puTarget + "\" id=\"sp-link\"><img id=\"sp-img\" style=\"margin-bottom: 5px;\"/></a>";
		document.getElementById("sp-link").onmouseover = rollover_sp;
		document.getElementById("sp-link").onmouseout = rollout_sp;
	} else {
		sp.innerHTML += "<a name=\"image\" id=\"sp-link\"><img id=\"sp-img\" style=\"margin-bottom: 5px;\"/></a>";
	}
	document.getElementById("sp-button").onclick = close_sp;
	rollout_sp();
}
function close_sp() {
	document.getElementById("sp").style.display = "none";
}
function rollover_sp() {
	document.getElementById("sp-img").src = puOn;
}
function rollout_sp() {
	document.getElementById("sp-img").src = puOff;
}


//---------------------------------------------------------
//  Page set
//---------------------------------------------------------
function global_pageset() {
	if (document.getElementById("toppage")) { pageset_toppage();}
	if (document.getElementById("items-detail")) { pageset_items_detail();}
	if (document.getElementsByTagName("h1")[0].firstChild.nodeValue == "New") { pageset_items_new();}
}

//  set
window.onload = global_pageset;