


// Requires layer.js

// Global Constants values

	var toolTipTypeHotel = 1;
	var toolTipTypePOI = 2;
	var toolTipTypeLocation = 3;
	var toolTipTypeHotelDetail = 4;

	var toolTipClassHotel = "iconHotelNumber";
	var toolTipClassHotelNotAvailable = "iconHotelNumberNotAvailable";
	var toolTipClassPOI = "iconPOI";
	var toolTipClassLocation = "iconLocation";
	var toolTipClassHotelDetail = "iconHotel";

	var section = new Array(new Array(1,2),new Array(5,6),new Array(3,4));

	var icoHeight = 12;
	var icoWidth = 16;

	var icoHeightLocation = 19;
	var icoWidthLocation = 19;

	var icoHeightHotelDetail = 16;
	var icoWidthHotelDetail = 23;

	var icoHeightPOI = 14;
	var icoWidthPOI = 14;

	var toolTipArrowHSpaceR = 5;
	var toolTipArrowHSpaceL = 15;

	var id_toolTip_prefix = "hotelLayer_";

	var POIImageTypeURLPrefix = '/nh/_css/gfx/icons/poi_category_';
	var POIImageTypeURLSufix = '.gif';
// HotelLayersGroup CLASS

HotelLayersGroup.prototype.createNewToolTip = createNewToolTip;
HotelLayersGroup.prototype.showHideToolTip = showHideToolTip;
HotelLayersGroup.prototype.eraseHotelLayersDivs = eraseHotelLayersDivs;

// HotelLayer CLASS

function HotelLayer (id, ico, toolTip, divPosition) {
	this.id = id;
	this.ico = ico;
	this.div = toolTip;
	if (divPosition != null) this.divPosition = divPosition;
}

function HotelLayersGroup(toolTipsParentDiv, hotelToolTipHeight, hotelToolTipWidth, instanceName) {
	this.layersGroup = new Array(0);
	// Hotel Layers DIV Parent element
	this.toolTipsParentDiv = toolTipsParentDiv;
	this.hotelToolTipHeight = hotelToolTipHeight;
	this.hotelToolTipWidth = hotelToolTipWidth;
	this.nextHotelIndex = 1;
	this.instanceName = instanceName;
}

function createNewToolTip(id, top, left, toolTipType) {

	var hotelLayersParentDiv = document.getElementById(this.toolTipsParentDiv);

	// Hotel ICO
	var ico;
	var toolTip;
	// Hotel INFO Layer
	switch (toolTipType) {
		case toolTipTypeHotel:
			var hotelData = getHotelData(id);
			var hotelPrice = getHotelPrices(hotelData[0]);
			// ICO
			if (hotelPrice[1] != '') { ico = createDiv(toolTipClassHotel, id, top, left, icoHeight, icoWidth);
			} else { ico = createDiv(toolTipClassHotelNotAvailable, id, top, left, icoHeight, icoWidth); }

			ico.appendChild(document.createTextNode(hotelData[4]));

			var divPosition = getDivPosition(top, left, extractDimFromStyle(hotelLayersParentDiv.style.height), extractDimFromStyle(hotelLayersParentDiv.style.width));
			var newTop = top;
			var newLeft = getNewLeftFromDivPosition(divPosition, left, this.hotelToolTipWidth);
			toolTip = createDiv("", id, newTop, newLeft, 0, this.hotelToolTipWidth);

			var innerTable = fillHotelData(getRigthClassFromPosition(divPosition), 1, hotelData, hotelPrice, this.instanceName);

			toolTip.innerHTML = innerTable.innerHTML;

			// add ToolTip to the parent Layer
			hotelLayersParentDiv.appendChild(toolTip);
			break;
		case toolTipTypePOI:
			var poiData = getPOIData(id);
			// ICO
			ico = createDiv(toolTipClassPOI, id, top, left, icoHeightPOI, icoWidthPOI);
            // ICO IMAGE
			var poiImage = document.createElement("IMG");
			poiImage.src = POIImageTypeURLPrefix + poiData[3] + POIImageTypeURLSufix;
			ico.appendChild(poiImage);

			var divPosition = getDivPosition(top, left, extractDimFromStyle(hotelLayersParentDiv.style.height), extractDimFromStyle(hotelLayersParentDiv.style.width));
			var newTop = top;
			var newLeft = getNewLeftFromDivPosition(divPosition, left, this.hotelToolTipWidth);
			toolTip = createDiv("", id, newTop, newLeft, 0, this.hotelToolTipWidth);

			var innerTable = fillPOIData(getRigthClassFromPosition(divPosition), 1, poiData, this.instanceName);

			// add innerTable to the ToolTip
			toolTip.innerHTML = innerTable.innerHTML;

			// add ToolTip to the parent Layer
			hotelLayersParentDiv.appendChild(toolTip);

			// need to paint [appenchild] to calculate div offsetHeight
			toolTip.style.top = getNewTopFromDivPosition(divPosition, top, toolTip.offsetHeight) + "px";
			break;
		case toolTipTypeLocation:
			ico = createDiv(toolTipClassLocation, id, top, left, icoHeightLocation, icoWidthLocation);
			break;
		case toolTipTypeHotelDetail:
			ico = createDiv(toolTipClassHotelDetail, id, top, left, icoHeightHotelDetail, icoWidthHotelDetail);
			break;
	}
	ico.style.display = "block";
	// Hotel ICO events
	var me = this;
	ico.onclick = function () { me.showHideToolTip(id, true); };
	hotelLayersParentDiv.appendChild(ico);

	this.layersGroup.push(new HotelLayer(id, ico, toolTip, divPosition));
}

function showHideToolTip(hotelLayerId, show) {
	var hotelLayersParentDiv = document.getElementById(this.toolTipsParentDiv);

	for (var i = 0; i < this.layersGroup.length; i++) {
		if (show != null && this.layersGroup[i].id == hotelLayerId) {
			if (this.layersGroup[i].div != null) {
				var style = this.layersGroup[i].div.style;
				style.display = "block";
				style.zIndex = "9999";
				if ((this.layersGroup[i].divPosition) != 0 ) { // Pair divPosition means layer is shwon above the icon
					style.top = getNewTopFromDivPosition(this.layersGroup[i].divPosition, extractDimFromStyle(style.top), this.layersGroup[i].div.childNodes[0].offsetHeight) + "px";
					this.layersGroup[i].divPosition = 0;
				}
			}
		}
		else { if (this.layersGroup[i].div != null) this.layersGroup[i].div.style.display = "none"; }
	}
}

function eraseHotelLayersDivs() {
	// Delete old layers
	hotelLayersParentDiv = document.getElementById(this.toolTipsParentDiv);
	for (var i = 0; i < this.layersGroup.length; i++) {
		// Erase Ico
		eraseChilds(this.layersGroup[i].ico);
		hotelLayersParentDiv.removeChild(this.layersGroup[i].ico);
		// Erase Div
		if (this.layersGroup[i].div != null ) {
			eraseChilds(this.layersGroup[i].div);
			hotelLayersParentDiv.removeChild(this.layersGroup[i].div);
		}
	}
	this.layersGroup = new Array(0);
	this.nextHotelIndex = 1;
}

function eraseChilds(parent) {
	for (var i = 0; i < parent.childNodes.length; i++) {
		eraseChilds(parent.childNodes[i]);
		parent.removeChild(parent.childNodes[i]);
	}
}

function getDivPosition(centerTop, centerLeft, parentDivHeight, parentDivWidth) {
	return section[getHorizontalSection(centerLeft, parentDivWidth)][getVerticalSection(centerTop, parentDivHeight)];
}

function getNewTopFromDivPosition(position, oldTop, divHeight) {
	if (position%2 != 0) { return parseInt(oldTop) + (icoHeight/2); } // Bottom layer
	if (position%2 == 0) { return parseInt(oldTop) - divHeight + 6; } // Top layer
}

function getNewLeftFromDivPosition(position, oldLeft, divWidth) {
	if (position == rightBottom) { return parseInt(oldLeft) + (icoWidth/2) - toolTipArrowHSpaceR; }
	if (position == rightTop) { return parseInt(oldLeft) + (icoWidth/2) - toolTipArrowHSpaceR; }
	if (position == leftBottom) { return parseInt(oldLeft) + (icoWidth/2) - divWidth + toolTipArrowHSpaceL; }
	if (position == leftTop) { return parseInt(oldLeft) + (icoWidth/2) - divWidth + toolTipArrowHSpaceL; }
	if (position == middleTop || position == middleBottom) { return parseInt(oldLeft) + (icoWidth/2)  - (divWidth/2) + toolTipArrowHSpaceR ;}
}

function getHorizontalSection(centerLeft, parentDivWidth) {
	var horizontalSection3 = parentDivWidth/3;
	var left = parseInt(centerLeft) + (icoWidth/2);
	if (left > (horizontalSection3 * 2)) { // left > horizontalSection3 * 2
		return 2;
	} else if (left > horizontalSection3) { // left > horizontalSection3 * 1
		return 1;
	} else { // left > horizontalSection3 * 0
		return 0;
	}
}

function getVerticalSection(centerTop, parentDivHeight) {
	var verticalSection2 = parentDivHeight/2
	var top = parseInt(centerTop) + (icoHeight/2);
	if (top > verticalSection2) { // top > verticalSection2 * 1
		return 1;
	} else { // top > verticalSection2 * 0
		return 0;
	}
}

function createHotelImage(imageURL) {
	var hotelImage = document.createElement("IMG");
	hotelImage.src = imageURL;
	hotelImage.className = "photo";
	hotelImage.width = "50";
	hotelImage.height = "50";
	return hotelImage;
}