﻿/// <reference path="common6.js" />

var g_aLocaleList = null;
var g_aMapPanelZoomFrameCoords = null;
var g_aSelectedLocaleFrameCoords = null;
var g_iLocaleZoomCounter = 0;
var g_iSelectedLocaleID = 0;
var g_iSelectedCatID = 0;

var g_divMapPanel = null;
var g_divListPanel = null;
var g_divMapPanelZoomFrame = null;

function fnAppInit() {

    fnCommonInit();
    
	g_divMapPanel = fnGetClientElem("divHomeMapPanel");
	g_divListPanel = fnGetClientElem("divHomeListPanel");
	g_divMapPanelZoomFrame = fnGetClientElem("divMapPanelZoomFrame");
	g_aMapPanelZoomFrameCoords = new Array(0, "zoomframe", 0, 0, 336, 474);

	g_aLocaleList = new Array();
	var sLocaleListString = fnGetElem("hfLocaleList").value;

	if (sLocaleListString != "") {

		var aLocaleListString = sLocaleListString.split("|");

		var x;
		for (x = 0; x < aLocaleListString.length; x++) {
			var aLocale = aLocaleListString[x].split(",");
			g_aLocaleList[x] = new Array(aLocale[0] * 1, aLocale[1], aLocale[2] * 1, aLocale[3] * 1, aLocale[4] * 1, aLocale[5] * 1);
		}

		var divProto = fnGetClientElem("divLocaleLabelProto");


		var x;
		for (x = 0; x < g_aLocaleList.length; x++) {
			var divNew = divProto.cloneNode(true);
			divNew.innerHTML = g_aLocaleList[x][1];
			divNew.style.left = g_aLocaleList[x][2] + "px";
			divNew.style.top = g_aLocaleList[x][3] + "px";
			divNew.style.width = g_aLocaleList[x][4] + "px";
			divNew.style.height = g_aLocaleList[x][5] + "px";
			divNew.localeordinal = x;
			divNew.localeid = g_aLocaleList[x][0];

			g_divMapPanel.appendChild(divNew);
			divNew.style.display = "inline";
		}
	}

}

function fnMapLocaleClick(theDiv) {

	var iLocaleOrdinal = theDiv.localeordinal * 1;
	g_iSelectedLocaleID = theDiv.localeid * 1;
	g_aSelectedLocaleFrameCoords = g_aLocaleList[iLocaleOrdinal];
	g_iLocaleZoomCounter = 10;
	fnMapLocaleZoom();
}



function fnMapLocaleZoom() {

	g_divMapPanelZoomFrame.style.left = g_aSelectedLocaleFrameCoords[2] - ((g_aSelectedLocaleFrameCoords[2] - g_aMapPanelZoomFrameCoords[2]) / g_iLocaleZoomCounter) + "px";
	g_divMapPanelZoomFrame.style.top = g_aSelectedLocaleFrameCoords[3] - ((g_aSelectedLocaleFrameCoords[3] - g_aMapPanelZoomFrameCoords[3]) / g_iLocaleZoomCounter) + "px";
	g_divMapPanelZoomFrame.style.width = g_aSelectedLocaleFrameCoords[4] + ((g_aMapPanelZoomFrameCoords[4] - g_aSelectedLocaleFrameCoords[4]) / g_iLocaleZoomCounter) + "px";
	g_divMapPanelZoomFrame.style.height = g_aSelectedLocaleFrameCoords[5] + ((g_aMapPanelZoomFrameCoords[5] - g_aSelectedLocaleFrameCoords[5]) / g_iLocaleZoomCounter) + "px";
	g_divMapPanelZoomFrame.style.display = "inline";

	g_iLocaleZoomCounter--;

	if (g_iLocaleZoomCounter > 0) {
		window.setTimeout("fnMapLocaleZoom();", 30);
	} else {
		g_divMapPanelZoomFrame.style.display = "none";
		window.setTimeout("fnMapPanelSwitch(2);", 10);
	}
}

function fnMapPanelSwitch(iMode) {

	if (iMode == 1) {
		if (g_iSelectedLocaleID > 0) {
			var divL = fnGetClientElem("divL" + g_iSelectedLocaleID);
			divL.style.height = "0px";
		}

		g_divMapPanel.style.display = "inline";
		g_divListPanel.style.display = "none";
	} else {
		g_divMapPanel.style.display = "none";
		g_divListPanel.style.display = "inline";
		if (g_iSelectedLocaleID > 0) {
			var divL = fnGetClientElem("divL" + g_iSelectedLocaleID);
			divL.style.height = "458px";
		}
	}
}

function fnListLocaleClick() {

	if (g_iSelectedCatID > 0) {
		fnCatClick(g_iSelectedLocaleID, g_iSelectedCatID, 0);
	}

	fnMapPanelSwitch(1);
}


function fnCatClick(iLocaleID, iCategoryID, iOnOff) {

	var divLC = fnGetClientElem("divLC" + iLocaleID);
	var divLCO = fnGetClientElem("divLCO" + iLocaleID + "c" + iCategoryID);

	if (iOnOff == 1) {
		divLC.style.height = "0px";
		divLCO.style.height = "436px";
		g_iSelectedCatID = iCategoryID;
	} else {
		divLC.style.height = "436px";
		divLCO.style.height = "0px";
		g_iSelectedCatID = 0;
	}
}