<krpano version="1.20.9">

<action name="deeplinking_script" type="Javascript" autorun="preinit" protect="true" ><![CDATA[
	window.parent_url = window.location.href;
	window.deeplinking_script_handler = function(){
		var url = new URL(window.parent_url);
		url.searchParams.set('s', krpano.get("xml.scene"));
		url.searchParams.set('h', parseFloat(krpano.get("view.hlookat")).toFixed(2));
		url.searchParams.set('v', parseFloat(krpano.get("view.vlookat")).toFixed(2));
		url.searchParams.set('f', parseFloat(krpano.get("view.fov")).toFixed(0));
		krpano.set("share_url",url.toString());
		// console.log(url.toString());
	}
	krpano.set("events[deeplinking_script].keep", true);
	krpano.set("events[deeplinking_script].onnewpano", deeplinking_script_handler);
	krpano.set("events[deeplinking_script].onidle", deeplinking_script_handler);
	
	window.getUrlParameter_custome = function(sParam,page_url) {
		if(typeof page_url == "undefined"){
			page_url = window.location;
		}else{
			page_url = new URL(page_url);
		}
		var sPageURL = page_url.search.substring(1), sURLVariables = sPageURL.split("&"), sParameterName, i;for (i = 0; i < sURLVariables.length; i++) {sParameterName = sURLVariables[i].split("=");if (sParameterName[0] === sParam) {return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);}}
	};
	window.onPingMessageRecive = function(e) {
		// console.log("onPingMessageRecive",e);
		if("parent_url" in e.data){
			window.parent_url = e.data.parent_url;
			if(window.deeplinking_done==undefined){
				window.deeplinking_done = true;
				var s = getUrlParameter_custome("s",parent_url);
				var h = getUrlParameter_custome("h",parent_url);
				var v = getUrlParameter_custome("v",parent_url);
				var f = getUrlParameter_custome("f",parent_url);
				// var show_shops = getUrlParameter_custome("show_shops",parent_url);
				// console.log("parent_url",parent_url);
				// console.log("s",s);
				// console.log("h",h);
				// console.log("v",v);
				// console.log("f",f);
				if(s!=null){
					if(getUrlParameter_custome("show_shops")!="true"){
						var style_shop = krpano.get("style[shop]");
						style_shop.visible = false;
						style_shop.enabled = false;
						style_shop.onloaded = "";

						var action_shop = krpano.get("action[set_hotspot_data]");
						action_shop.content = "";

						krpano.set("plugin[fuzzysearch].placeholder","Enter a shop name");
						window.search_on_shopid = false;
					}
				
					var startup = krpano.action.getItem("startup");
					startup.content = "";
					krpano.set("h",h);
					krpano.set("v",v);
					krpano.call("loadscene(" + s + ", null, MERGE);" + (h!=null && v!=null?"lookat(" + h + "," + v + (f!=null?"," + f:"") +  ");":"") + "show_ui();if(startactions !== null, startactions() );");
				}
			}
		}
	}
	if(window.addEventListener)
		window.addEventListener('message', onPingMessageRecive, false);
	else if (window.attachEvent)
		window.attachEvent('message', onPingMessageRecive, false);
		
	function inIframe(){try{return window.self !== window.top;}catch(e){return true;}}
	if(!inIframe()){
		var s = getUrlParameter_custome("s");
		var h = getUrlParameter_custome("h");
		var v = getUrlParameter_custome("v");
		var f = getUrlParameter_custome("f");
		if(s!=null){
			if(getUrlParameter_custome("show_shops")!="true"){
				var style_shop = krpano.get("style[shop]");
				style_shop.visible = false;
				style_shop.enabled = false;
				style_shop.onloaded = "";

				var action_shop = krpano.get("action[set_hotspot_data]");
				action_shop.content = "";

				krpano.set("plugin[fuzzysearch].placeholder","Enter a shop name");
				window.search_on_shopid = false;
			}
			var startup = krpano.action.getItem("startup");
			startup.content = "";
			krpano.set("h",h);
			krpano.set("v",v);
			krpano.call("loadscene(" + s + ", null, MERGE);" + (h!=null && v!=null?"lookat(" + h + "," + v + (f!=null?"," + f:"") +  ");":"") + "show_ui();if(startactions !== null, startactions() );");
		}
	}
]]></action>


// hide the shop hotspots if the user not loged-in
<action name="check_is_staging_server" type="Javascript" autorun="preinit" protect="true" ><![CDATA[
	window.staging_server = false;
	if(location.hostname.endsWith('vicinity.atomic3d.com.au'))
		window.staging_server = true;

	if(window.staging_server==false){
		krpano.set("debugkeys",false);
		krpano.set("logkey",false);
		krpano.set("showerrors",false);
	}

	// window.exitfullscreen_handler = function(){
		// console.log("00000000000");
		// $("#krpanoSWFObject").focus();
		// setTimeout(function(){
			// $("#krpanoSWFObject").focus();
		// },100);
	// }
	// krpano.set("events[fullscreener].keep", true);
	// krpano.set("events[fullscreener].onexitfullscreen", exitfullscreen_handler);


]]></action>
<action name="hide_shop_hotspot" type="Javascript" autorun="preinit" protect="true" ><![CDATA[
var getUrlParameter = function getUrlParameter(sParam) {
  var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split("&"), sParameterName, i;
  for (i = 0; i < sURLVariables.length; i++) {sParameterName = sURLVariables[i].split("=");if (sParameterName[0] === sParam) {return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);}}
};

krpano.set("plugin[fuzzysearch].placeholder","Enter a shop name or ID");
window.search_on_shopid = true;

if(getUrlParameter("show_shops")!="true"){
	var style_shop = krpano.get("style[shop]");
	style_shop.visible = false;
	style_shop.enabled = false;
	style_shop.onloaded = "";

	var action_shop = krpano.get("action[set_hotspot_data]");
	action_shop.content = "";

	krpano.set("plugin[fuzzysearch].placeholder","Enter a shop name");
	window.search_on_shopid = false;
}
]]></action>


<action name="get_xml_content_to_double_check_search_shops" autorun="preinit" type="Javascript"><![CDATA[
if(window.staging_server==true){
	window.xml_content = krpano.get("xml.content");
	var scenes = krpano.get('scene').getArray();
	var scenesArraySize = scenes.length;
	var shopsInScene = [];
	window.Scenes_With_No_Shop = {};
	
	for (var i = 0; i < scenesArraySize; i++) {
		if (!scenes[i].shops) {
			continue;
		}
		try {
			var shops = scenes[i].shops;
			var shopsArray = shops.split(',');
			for (var index in shopsArray) {
				shopsInScene.push(parseInt(shopsArray[index]));
			}
		} catch (e) {}
	}
	
	if(krpano.get("ediths")=="true"){
		var js_url = "https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js";
		var integrity = "sha512-csNcFYJniKjJxRWRV1R7fvnXrycHP6qDR21mgz1ZP55xY5d+aHLfo9/FcGDQLfn2IfngbAHd8LdfsagcCqgTcQ==";
		$('<script />', { type : 'text/javascript', src : js_url, integrity : integrity, crossorigin : "crossorigin", referrerpolicy : "referrerpolicy"}).appendTo('head');
	}

	var parseXml;
	if (window.DOMParser) {parseXml = function(xmlStr) {return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");};} else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) {parseXml = function(xmlStr) {var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");xmlDoc.async = "false";xmlDoc.loadXML(xmlStr);return xmlDoc;};} else {parseXml = function() { return null; }}
	
	window.xmlDoc = parseXml(xml_content);
	window.DOMParser_init = function(){
		if(window.find_shop==undefined || window.mal_data==undefined || window.shopInService == undefined || window.shopInService == [])
			return true;
		if(window.token==undefined)
			return true;
		
		clearInterval(window.DOMParser_init_Interval);
		if(xmlDoc){
			window.MissedShopsList = {};
			window.xmlScenes = xmlDoc.getElementsByTagName('scene');
			for(var i = 0; i < xmlScenes.length; i++) {
				Scenes_With_No_Shop[xmlScenes[i].getAttribute("name")] = true;
				
				// window.xmlShops = xmlScenes[i].getAttribute("shops");
				window.xmlHotspots = xmlScenes[i].getElementsByTagName('hotspot');
				for(var ii = 0; ii < xmlHotspots.length; ii++) {
					var Shops_unit_key = xmlHotspots[ii].getAttribute("unit_key");
					if((Shops_unit_key!=null && parseInt(Shops_unit_key)>9) || xmlScenes[i].getAttribute("name").indexOf("aerial")>-1 ){
						Scenes_With_No_Shop[xmlScenes[i].getAttribute("name")] = false;
					}
					if(Shops_unit_key!=null && shopsInScene.indexOf(parseInt(Shops_unit_key))==-1){
						// console.log("add" , Shops_unit_key , "to" , xmlScenes[i].getAttribute("name"));
						// shopsInScene.push(parseInt(Shops_unit_key));
						
						if(!(parseInt(Shops_unit_key).toString() in MissedShopsList))
							MissedShopsList[parseInt(Shops_unit_key).toString()] = {};
						var url = new URL(window.location.href);
						url.searchParams.set('startscene', xmlScenes[i].getAttribute("name"));
						url.searchParams.set('show_shops', "true");
						MissedShopsList[parseInt(Shops_unit_key).toString()][xmlScenes[i].getAttribute("name")] = url.toString();
					}
				}
			}
			// console.log("MissedShopsList: ",MissedShopsList);
			// var html = "Missed Shops List: \n\r\n\r";
			var html = "– we have to add these shops at the scene's \"shops\" attribute in the XML file to have them on the search function: \n\r\n\r";
			$.each(MissedShopsList, function(index, value) {
				// console.log(value);
				var html_temp = "\n\r";
				$.each(value, function(index2, value2) {
					html_temp += "- " + index2 + " (" + value2 + ")" + "\n\r";
				});
				if(index in mal_data)
					html += "add " + index  + " (\"" + mal_data[index].leasing_tenant + "\")" + " to: " + html_temp + "\n\r\n\r";
				else
					html += "add " + index  + " (\"" + "no data" + "\")" + " to: " + html_temp + "\n\r\n\r";
			}); 
			console.log(html);
			
			
			var html = "– Scenes without any shop: \n\r";
			var Scenes_With_No_Shop_Counter = 0;
			$.each(Scenes_With_No_Shop, function(index, value) {
				if(value){
					// console.log(value);
					Scenes_With_No_Shop_Counter++;
				
					var url = new URL(window.location.href);
					url.searchParams.set('startscene', index);
					url.searchParams.set('show_shops', "true");
					
					html += Scenes_With_No_Shop_Counter + "- " + index + " ==> " + url.toString() + "\n\r";
				}
			}); 
			console.log(html);
			
			window.GetMap_list_result = {};
			
			function GetMap_list(){
				var url = "https://www.vicinity.atomic3d.com.au/api.php";
				var xhr = new XMLHttpRequest();
				xhr.open("POST", url, true);
				xhr.setRequestHeader('Authorization', "Bearer " + window.token);
				var formData = new FormData()
				
				formData.append('url', 'https://api.vicinity.com.au/v3/floors?filter=centre_key==' + krpano.get("centre_key") + '');
				/*
				if(krpano.get("mall_name")!=null)
					formData.append('url', 'https://api.vicinity.com.au/v3/floors?filter=centre_name=="' + krpano.get("mall_name") + '"');
				else
					formData.append('url', 'https://api.vicinity.com.au/v3/floors?filter=centre_key==' + krpano.get("centre_key"));
				*/
				
				formData.append('method', "GET");
				xhr.send(formData);
				xhr.onreadystatechange = function () {
					if (this.readyState == 4 && this.status == 200) {
						temp = JSON.parse(this.response)
						// console.log(temp);
						if("data" in temp && 0 in temp.data){
							$.each(temp.data, function(index, value) {
								window.GetMap_list_result[value.map_name] = {};
							});
							$.each(temp.data, function(index, value) {
								GetMap(value.map_name);
							});
						}
					}
				}
			}
			GetMap_list();
			function GetMap(map_name){
				var url = "https://www.vicinity.atomic3d.com.au/api.php";
				var xhr = new XMLHttpRequest();
				xhr.open("POST", url, true);
				xhr.setRequestHeader('Authorization', "Bearer " + window.token);
				var formData = new FormData()
				formData.append('url', 'https://api.vicinity.com.au/v3/maps?filter=map_name=="' + map_name + '"');
				formData.append('method', "GET");
				xhr.send(formData);
				xhr.onreadystatechange = function () {
					if (this.readyState == 4 && this.status == 200) {
						temp = JSON.parse(this.response)
						// console.log(temp);
						if("data" in temp && 0 in temp.data && "map_data" in temp.data[0]){
							// console.log(map_name);
							// console.log(temp);
							GeoJSON = JSON.stringify(temp.data[0].map_data);
							window.GetMap_list_result[map_name] = GeoJSON;
						}else{
							window.GetMap_list_result[map_name] = map_name;
							// console.log(map_name);
							// console.log(temp);
						}
						
						var GetMap_xhr_request_finished = true;
						$.each(GetMap_list_result, function(index, value) {
							// console.log(value);
							if(typeof value == "object")
								GetMap_xhr_request_finished = false;
						});
						if(GetMap_xhr_request_finished == true){
							print_result_GetMap();
						}
					}
				}
			}
			function print_result_GetMap(){
				// if(krpano.get("ediths")=="true" && window.print_result_GetMap_done==undefined){
				if(krpano.get("ediths")=="true"){
					window.print_result_GetMap_done = true;
					$("#print_result_GetMap").remove();
					$("body").append("<div id='print_result_GetMap' style='position: absolute;z-index: 10;width: auto;top: 10px;left: 10px;margin: auto;pointer-events: none;backdrop-filter: blur(3px);' ><div style='margin-bottom: 8px;'>Download GeoJSON & Spreadsheet:</div></div>");
					$("#print_result_GetMap").append("<button onclick='download_spreadsheet_sheet();' style='display: block;pointer-events: auto;cursor: pointer !important;margin-bottom: 8px !important;'>Spreadsheet Sheet</button>");
					$("#print_result_GetMap").append("<button onclick='window.open(\"https://www.vicinity.atomic3d.com.au/download_map.php?centre_key=" + krpano.get("centre_key") + "\", \"_blank\");' style='display: block;pointer-events: auto;cursor: pointer !important;margin-bottom: 8px !important;'>Download All Maps</button>");
					$.each(GetMap_list_result, function(index2, value2) {
						$("#print_result_GetMap").append("<button onclick='download_GeoJSON(\"" + index2 +"\");' style='display: block;pointer-events: auto;cursor: pointer !important;margin-bottom: 8px !important;'>" + index2 +"</button>");
					});
					window.download_spreadsheet_sheet = function(){
						alert("Please open the developer console");
						var ExcelArray = [];
						var arraySize = search_date.length;
						for(var i = 0; i < arraySize; i++){
							ExcelArray.push([search_date[i].unit_key,search_date[i].unit_code,search_date[i].leasing_tenant,search_date[i].category,search_date[i].floor]);
						}
						console.log(JSON.stringify(ExcelArray));
						console.log("Please copy this string and paste it on this website: \n\rhttps://data.page/json/csv");
					}
					window.download_GeoJSON = function(map_name){
						var blob = new Blob([GetMap_list_result[map_name]], {type: "text/plain;charset=utf-8"});
						saveAs(blob, map_name + ".json");
					}
				}
			
				var NOT_EXISTS = [];
				
				var html = "– we can’t find any images for these shops: \n\r\n\r";
				$.each(shopInService, function(index, value) {
					var GeoJSON_file = "NOT-EXISTS";
					$.each(GetMap_list_result, function(index2, value2) {
						if(value2.indexOf('"' + mal_data[value].unit_code + '"')>-1)
							GeoJSON_file = index2;
					});
					// console.log(value);

					var html_temp = "\n\r";
					
					if(GeoJSON_file!="NOT-EXISTS"){
						if(value in mal_data)
							html += "add " + value  + " (\"" + (mal_data[value].leasing_tenant==""?"NO NAME":mal_data[value].leasing_tenant) + " ==> " + mal_data[value].unit_code + "\")" + " to floor: " + mal_data[value].floor + " ==> GeoJSON:" + GeoJSON_file + "\n\r";
						else
							html += "add " + value  + " (\"" + "no data" + "\")" + " to: " + html_temp + "\n\r";
					}else{
						NOT_EXISTS.push(value);
					}
				}); 
				console.log(html);
				console.log('– these shops don\'t exist in the GeoJSON:', JSON.stringify(NOT_EXISTS));
				
				window.removeDuplicates = function(array) {return [...new Set(array)];}
				if(window.temp_shopInService!=undefined){
					var filteredArray = window.temp_shopInService.filter(item => !NOT_EXISTS.includes(item));
					console.log('– we have these shops in the API but we can\'t find any images for them and also they are not exist in the GeoJSON:', JSON.stringify(removeDuplicates(filteredArray)));
				}else if(window.shopInService!=undefined){
					var filteredArray = window.shopInService.filter(item => !NOT_EXISTS.includes(item));
					console.log('– we have these shops in the API but we can\'t find any images for them and also they are not exist in the GeoJSON:', JSON.stringify(removeDuplicates(filteredArray)));
				}
			}
		}
	}
	window.DOMParser_init_Interval = setInterval(DOMParser_init, 20);
}

]]></action>



// init analytics functions
<action name="init_analytics" type="Javascript" autorun="preinit" protect="true" ><![CDATA[
	window.getUrlParameter = function getUrlParameter(sParam) {
	  var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split("&"), sParameterName, i;
	  for (i = 0; i < sURLVariables.length; i++) {sParameterName = sURLVariables[i].split("=");if (sParameterName[0] === sParam) {return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);}}
	};
	window.center_name = "";
	window.send_analytics = function(type,data1,data2,data3,data4){
		if(typeof data1 == "string")
			data1 = data1.replace(/````/g, "'");
		if(typeof data2 == "string")
			data2 = data2.replace(/````/g, "'");

		if(type=="open_popup"){
			console.log("send_analytics"," | event_id: " + type, " | label: " + data1, " | text: " + data2, " | category: " + data3);
			if(window.parent && window.self !== window.top){
				window.parent.postMessage({
					event_id: type,
					data: {
						'label' : data1,
						'text': data2,
						'category': data3
					}
				},"*");
			}
		}else if(type=="download_content"){
			data1 = data1.replace(/````/g, "'");
			data2 = data2.replace(/````/g, "'");
			data3 = data3.replace(/````/g, "'");
			data4 = data4.replace(/````/g, "'");
			console.log("send_analytics"," | event_id: " + type, " | label: " + data1, " | text: " + data2, " | category: " + data3, " | retailer: " + data4);
			if(window.parent && window.self !== window.top){
				window.parent.postMessage({
					event_id: type,
					data: {
						'label' : data1,
						'text': data2,
						'category': data3,
						'retailer': data4
					}
				},"*");
			}
		}else{
			console.log("send_analytics"," | event_id: " + type, " | data: " + data1);
			if(window.parent && window.self !== window.top){
				window.parent.postMessage({
					event_id: type,
					data: {
						data: data1
					}
				},"*");
			}
		}
	}

	krpano.set("events[analytics].keep", true);
	window.wait_for_user_first_interaction = false;

	if(getUrlParameter("startscene")==undefined || getUrlParameter("startscene")==""){
		window.wait_for_user_first_interaction = true;
		window.first_interaction = function(){
			if(window.wait_for_user_first_interaction == true)
				send_analytics("change_scene",krpano.get("xml.scene"),"");
			window.wait_for_user_first_interaction = false;
			krpano.set("events[analytics].onmousedown", "");
		}
		krpano.set("events[analytics].onmousedown", first_interaction);
	}

	window.analytics_change_scene = function(){
		if(window.wait_for_user_first_interaction == false){
			send_analytics("change_scene",krpano.get("xml.scene"),(window.previous_scene==undefined?"":window.previous_scene));
		}
		//if(window.previous_scene == undefined)
			window.previous_scene = krpano.get("XML.scene");
	}
	krpano.set("events[analytics].onnewpano", analytics_change_scene);

	krpano.set("layer[helicopter_button].onclick",  krpano.get("layer[helicopter_button].onclick") + ";send_analytics_helicopter_btn();");
]]></action>
<action name="send_analytics_helicopter_btn" type="Javascript" ><![CDATA[
	send_analytics("helicopter_btn","","");
]]></action>



//HAMID Search plugin
	<layer name="fuzzysearch_placeholder" align="topright" type="container" alpha="1"
	x="165"
	y="46"
	zorder="9"
	width.normal="30%"
	width.mobile="50%"
	keep="true"
	scalechildren="true"
	onhover="showtext(Search for a shop,DEFAULT_search)"
		   />

	<plugin name="fuzzysearch"
			url="%SWFPATH%/plugins/fuzzysearch.js?3"
			keep="true"
			devices="html5"
			width="100%"
			x="0"
			y="0"
			align="topright"
			parent="fuzzysearch_placeholder"
			include_jquery="true"
			auto_generate_scenes_list="false"
			group_scenes="false"
			theme="style_01"
			font_size="13"
			font_name="Primary"
			textcolor="0x000000"
			bgcolor="0xffffff"
			bgalpha="1"
			bordercolor="0xaaaaaa"
			borderalpha="1"
			selected_item_textcolor="0x000000"
			selected_item_bgcolor="0xf2f2f2"
			selected_item_bgalpha="1"
			button_bgcolor="0xed143d"
			button_bgalpha="1"
			button_textcolor="0xffffff"
			categorybgcolor="0xeeeeee"
			categorybgalpha="1"
			categorytextcolor="0xaaaaaa"
			maxheight="200px"
			text_direction="ltr"
			placeholder="Enter a shop name or ID"
			onInitialized="get_data_from_api()"
			responsive222="true"
	/>
<events name="close_search_box" onviewchange222="close_search_box()" onmousedown="close_search_box_click()" keep="true" devices="mobile|tablet" />
<action name="close_search_box_click" type="Javascript"  ><![CDATA[
	if(window.jQuery){
		if($(".open .chosen-with-drop").length > 0){
			$(".open .chosen-with-drop").removeClass("chosen-with-drop");
			$(".fuzzysearch_plugin div").removeClass("open");
			$(".chosen-search-input").blur();
			$(".chosen-select").blur();
			$("#krpanoSWFObject").focus();
		}
	}
]]></action>
<action name="close_search_box" type="Javascript"  ><![CDATA[
	if(window.jQuery){
		var view_hlookat = Math.round(krpano.get("view.hlookat")/2)*2;
		var view_vlookat = Math.round(krpano.get("view.vlookat")/2)*2;
		var view_fov	 = Math.round(krpano.get("view.fov"));

		if(typeof previous_view_hlookat=="undefined"){
			previous_view_hlookat = view_hlookat;
			previous_view_vlookat = view_vlookat;
			previous_fov = view_fov;
		}

		var do_we_have_any_changes = false;

		if(previous_view_hlookat != view_hlookat)
		{
			previous_view_hlookat = view_hlookat;
			do_we_have_any_changes = true;
		}
		if(previous_view_vlookat != view_vlookat)
		{
			previous_view_vlookat = view_vlookat;
			do_we_have_any_changes = true;
		}
		if(previous_fov != view_fov)
		{
			previous_fov = view_fov;
			do_we_have_any_changes = true;
		}
		if(do_we_have_any_changes)
		{
			if($(".open .chosen-with-drop").length > 0){
				$(".open .chosen-with-drop").removeClass("chosen-with-drop");
				$(".fuzzysearch_plugin div").removeClass("open");
				$(".chosen-search-input").blur();
				$(".chosen-select").blur();
				$("#krpanoSWFObject").focus();
			}
		}
	}
]]></action>

//HAMID FETCH SHOP HS DATA

<action name="get_data_from_api" type="Javascript" protect2="true" ><![CDATA[
			if(getUrlParameter("startscene")==undefined || getUrlParameter("startscene")==""){
				$(".fuzzysearch_plugin").click(function(){
					first_interaction();
				});
				$("body").click(function(){
					first_interaction();
				});
			}

			$(".fuzzysearch_plugin .chosen-container").mouseenter(function() {
				krpano.set("layer[fuzzysearch_placeholder].onhover","");
			}).mouseleave(function() {
				krpano.set("layer[fuzzysearch_placeholder].onhover","showtext(Search for a shop,DEFAULT_search)");
			});

			window.staging_server = false;
			if(location.hostname.endsWith('vicinity.atomic3d.com.au'))
				window.staging_server = true;

			var url = "https://api.vicinity.com.au/oauth/accesstoken?grant_type=client_credentials";
			if(staging_server)
				var url = "https://www.vicinity.atomic3d.com.au/api.php";

			var xhr = new XMLHttpRequest();
			if(staging_server)
				xhr.open("POST", url, true);
			else
				xhr.open("GET", url, true);
			xhr.setRequestHeader('Authorization', 'Basic WjgxdHBIcTlXS3dPQU1zWHZyVVRsQ0F5YU05YU9zamY6MlMybkFqRTg4RXZUY25uUw==');
			xhr.setRequestHeader('Accept', '*/*');

			var formData = new FormData()

			if(staging_server)
				formData.append('url', "https://api.vicinity.com.au/oauth/accesstoken?grant_type=client_credentials");

			xhr.send(formData);
			xhr.onreadystatechange = function () {
				if (this.readyState == 4 && this.status == 200) {
					var response = JSON.parse(this.response);
					window.token = response.access_token;
					getData(token);
				}
			};

function getData(token) {
	if(krpano.get("mall_name")!=null)
		var url = 'https://api.vicinity.com.au/v3/leasing-digital-info?filter=centre_name=="' + krpano.get("mall_name") + '"';
	else
		var url = 'https://api.vicinity.com.au/v3/leasing-digital-info?filter=centre_key==' + krpano.get("centre_key");
    if(staging_server)
		var url = "https://www.vicinity.atomic3d.com.au/api.php";

    var xhr = new XMLHttpRequest();
	if(staging_server)
		xhr.open("POST", url, true);
	else
		xhr.open("GET", url, true);
    xhr.setRequestHeader('Authorization', "Bearer " + token);

    var formData = new FormData();
	if(staging_server){
		if(krpano.get("mall_name")!=null)
			formData.append('url', 'https://api.vicinity.com.au/v3/leasing-digital-info?filter=centre_name=="' + krpano.get("mall_name") + '"');
		else
			formData.append('url', 'https://api.vicinity.com.au/v3/leasing-digital-info?filter=centre_key==' + krpano.get("centre_key") + '');
		formData.append('method', "GET");
	}
    xhr.send(formData);
    xhr.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            var response = JSON.parse(this.response);
            var data = response.data;
            var arraySize = data.length;
            var tempArray = [];
            //set data for search
            var searchData = [];
            for(var i = 0; i < arraySize; i++){
                tempArray[data[i].unit_key] = data[i];
                searchData.push(data[i]);
				window.center_name = data[i].centre_name;
            }
            // console.log("tempArray",tempArray);

			/*
			// https://data.page/json/csv
			var ExcelArray = [];
			var arraySize = search_date.length;
			for(var i = 0; i < arraySize; i++){
				ExcelArray.push([search_date[i].unit_key,search_date[i].unit_code,search_date[i].leasing_tenant,search_date[i].category,search_date[i].floor]);
			}
			console.log("ExcelArray",ExcelArray);
			console.log(JSON.stringify(ExcelArray));
			*/

            window.mal_data = tempArray;
            window.search_date = searchData;

            krpano.call("set_hotspot_data()");

            /*set fuzzy search*/
            var scenes = krpano.get('scene').getArray();
            var scenesArraySize = scenes.length;
            var shopsInScene = [];
            for (var i = 0; i < scenesArraySize; i++) {
				//console.log('scenes[i]', scenes[i]);
                if (!scenes[i].shops) {
                    continue;
                }

                try {
                    var shops = scenes[i].shops;
                    var shopsArray = shops.split(',');
                    for (var index in shopsArray) {
                        shopsInScene.push(parseInt(shopsArray[index]));
                    }
                } catch (e) {

                }
            }

			window.shopInService = [];
    var shopInXml = [];
    window.added_item = [];
            for (var i = 0; i < arraySize; i++) {
                if (shopsInScene.includes(data[i].unit_key) && !(data[i].unit_key in added_item)) {
					added_item[data[i].unit_key] = true;
                    // krpano.call('plugin[fuzzysearch].addItem("' + data[i].unit_code + '","jscall(find_shop(' + i + '))")');
                    // krpano.call('plugin[fuzzysearch].addItem("' + data[i].leasing_tenant  + '","jscall(find_shop(' + i + '))")');
                    if(window.search_on_shopid == true)
						krpano.call('plugin[fuzzysearch].addItem("' + data[i].unit_code       + '","jscall(find_shop(' + i + ');send_analytics(\'search\',\'' + (data[i].leasing_tenant==""?data[i].unit_code:data[i].leasing_tenant.replace(/'/g, "````")) + '\',\'\');)")');
					krpano.call('plugin[fuzzysearch].addItem("' + data[i].leasing_tenant  + '","jscall(find_shop(' + i + ');send_analytics(\'search\',\'' + (data[i].leasing_tenant==""?data[i].unit_code:data[i].leasing_tenant.replace(/'/g, "````")) + '\',\'\');)")');
                }else if(!(data[i].unit_key in added_item)){
                    //console.log('not include data => ', json.data[i].unit);
					shopInService.push(data[i].unit_key)
                }
            }

			// sort the list order/////////////////////////////////
			var options = $('select.chosen-select option');
			var arr = options.map(function(_, o) { return { t: $(o).text(), v: o.value, d: $(o).attr("data-click") }; }).get();
			// arr.sort(function(o1, o2) { return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0; });
			// arr.sort((o1, o2) => isFinite(o1.t[0]) - isFinite(o2.t[0]) || o1.t.localeCompare(o2.t, undefined, { numeric: true, sensitivity: 'base' }));
			arr.sort((o1, o2) => isFinite(o1.t[0]) - isFinite(o2.t[0]) || o1.t.replace(/_/, 'z').localeCompare(o2.t.replace(/_/, 'z'), undefined, { numeric: true, sensitivity: 'base' }));
			options.each(function(i, o) {
			  o.value = arr[i].v;
			  $(o).attr("data-click",arr[i].d);
			  $(o).text(arr[i].t);
			});
			$(".chosen-select").trigger('chosen:updated');
			/**/

			var keyArray = Object.keys(tempArray);
			for(var index in shopsInScene){
        if(!keyArray.includes(shopsInScene[index].toString())){
            shopInXml.push(shopsInScene[index]);
			// console.log('****',shopsInScene[index]);
        }
    }
	if(window.staging_server==true){
		console.log('– we have these shops in the API but we can’t find any images for them:', JSON.stringify(shopInService));
		console.log('– we have these shops in the XML but we can’t find them on the API:', JSON.stringify(shopInXml));
	}

            window.find_shop = function(searchKey, data2) {
                try {
                    var data = window.search_date[searchKey];
                    var scenes = krpano.get('scene').getArray();
                    var arraySize = scenes.length;
                    var sceneFound = false;
                    for (var i = 0; i < arraySize; i++) {
                        if (!scenes[i].shops) {
                            continue;
                        }

                        try {
                            var shops = scenes[i].shops;
                            var shopsArray = shops.split(',');
                            for (var index in shopsArray) {
                                if (parseInt(shopsArray[index]) === data.unit_key) {
                                    var sceneName = scenes[i].name;

                                    krpano.call('loadscene("' + sceneName + '", null, MERGE, BLEND(1))');

                                    var hotspots = krpano.get('hotspot').getArray();
                                    for (var hotspotIndex in hotspots) {
                                        if (parseInt(hotspots[hotspotIndex].unit_key) === data.unit_key) {
                                            var name = hotspots[hotspotIndex].name;
                                            krpano.call('looktohotspot("' + name + '","130")');
                                        }
                                    }

                                    sceneFound = true;
                                    break;
                                }
                            }

                            if (sceneFound) {
                                break;
                            }
                        } catch (e) {
                            console.log('error slave', e.message);
                        }
                    }
                } catch (e) {
                    console.log('error master', e.message);
                }
            }
        }
    };
}



	]]></action>

	<events onnewpano="set_hotspot_data();" keep="true"></events>

	<style name="shop_unset"></style>

	<action name="set_hotspot_data" type="Javascript" protect="true" ><![CDATA[
	  if(window.mal_data){
		var hotspots = krpano.get("hotspot").getArray();
		var arraySize = hotspots.length;
		for(var i = 0; i< arraySize; i++){
			if(hotspots[i] === undefined || hotspots[i].style === undefined || hotspots[i].style === null){
					try{
						// console.log(i, hotspots[i], hotspots[i].unit_key);
						// console.log(dataItem);
						// krpano.removehotspot(hotspots[i].myicon);
						// krpano.removehotspot(hotspots[i].mytext);
						// krpano.removehotspot(hotspots[i].name);
					}catch(error){
						// console.log('error in array', error);
					}
			}else{
				
				if(hotspots[i].style === 'shop_unset'){
				  try{
					// console.log(hotspots[i].unit_key);
					var dataItem = window.mal_data[hotspots[i].unit_key];
					// krpano.set("hotspot["+hotspots[i].name+"].title", dataItem.retailer);
					krpano.set("hotspot["+hotspots[i].name+"].title", dataItem.unit_key);
					krpano.call("hotspot["+hotspots[i].name+"].loadstyle(shop)");
				  }catch(error){
					//console.log('error in array', error);
				  }
				}

				if(hotspots[i].style === 'shop'){
					try{
						//console.log("set hotpspot title",hotspots[i].unit_key);
						var dataItem = window.mal_data[hotspots[i].unit_key];
						// krpano.set("hotspot["+hotspots[i].name+"].title", dataItem.retailer);
						// krpano.set("hotspot["+hotspots[i].name+"].title", dataItem.unit_code);
						if(dataItem === undefined || dataItem === null || dataItem==undefined || dataItem==""){
							// console.log(hotspots[i].myicon);
							// console.log(hotspots[i].mytext);
							// console.log(hotspots[i].name);
							// if(typeof getUrlParameter_custome("not_remove_empty_shops")=="undefined"){
							if(typeof getUrlParameter != "function" || getUrlParameter("not_remove_empty_shops")!="true"){
								eval(`
									setTimeout(function(){
										krpano.removehotspot("icon_` + hotspots[i].name + `");
										krpano.removehotspot("text_` + hotspots[i].name + `");
										krpano.removehotspot("` + hotspots[i].name + `");
										// console.log("eval icon_` + hotspots[i].name + `");
										// console.log("eval text_` + hotspots[i].name + `");
										// console.log("eval ` + hotspots[i].name + `");
									}, 72);
								`);
							}
							// krpano.removehotspot(hotspots[i].myicon);
							// krpano.removehotspot(hotspots[i].mytext);
							// krpano.removehotspot(hotspots[i].name);
							
							// console.log(i, hotspots[i], hotspots[i].unit_key);
							// console.log(dataItem);
						}else{
							if(dataItem.leasing_tenant=="" || dataItem.leasing_tenant==null || dataItem.leasing_tenant==undefined)
								dataItem.leasing_tenant = "---";
								
							krpano.set("hotspot["+hotspots[i].name+"].title", dataItem.leasing_tenant.replace("[","&#91;").replace("]","&#93;"));
							krpano.set("hotspot["+hotspots[i].mytext+"].html", dataItem.leasing_tenant.replace("[","&#91;").replace("]","&#93;"));

							//add generation of krpano data by jerome for VR version

							var content = "";

							content += "<h1>" + dataItem.leasing_tenant + "</h1>";
							content += "<p>";
							content += '<ul class="shoplist">';
							content += '<li class="catname">Category : ' + dataItem.category + '</li>';
							content += '<li class="catname">Area : ' + dataItem.gla + '</li>';
							content += '<li class="catname">Level : ' + dataItem.floor + '</li>';
							content += '<li class="catname">Shop ID : ' + dataItem.unit_code + '</li>';
							content += '</ul>';
							content += '</p>';

							krpano.set("data["+hotspots[i].name+"].content", content);
						}
					}catch(error){
						// console.log('error in array', error);
					}
				}
			}
		  }
		}
	]]></action>

// Temporary style for hotspots - added by Hamid on 2021-05-05
<style name="skin_hotspotstyle" url="vtourskin_hotspot.png" edge="center" align="center" distorted="false"
	   tooltip=""
	   linkedscene=""
	   linkedscene_lookat=""
	   onclick="skin_hotspotstyle_click();"
	   depth="1000"
	   scale="0.5"
	   onover.addevent="tween(scale,0.5);"
	   onout.addevent="tween(scale,0.5);"
	   onloaded.addevent="skin_hotspotstyle_setup();"
	   onloaded="add_all_the_time_tooltip();"
	   />
<action name="add_all_the_time_tooltip">
txtadd(tooltipname, 'tooltip_', get(name));
addplugin(get(tooltipname)); txtadd(plugin[get(tooltipname)].parent, 'hotspot[',get(name),']');
set(plugin[get(tooltipname)].url,'%SWFPATH%/plugins/textfield.swf');
set(plugin[get(tooltipname)].align,center);
set(plugin[get(tooltipname)].edge,center);
set(plugin[get(tooltipname)].x,0);
set(plugin[get(tooltipname)].y,0);
set(plugin[get(tooltipname)].width,200);
set(plugin[get(tooltipname)].autoheight,true);
set(plugin[get(tooltipname)].background,false);
set(plugin[get(tooltipname)].border,false);
set(plugin[get(tooltipname)].css,'text-align:center; color:#FFFFFF; font-family:Arial; font-weight:bold; font-size:16px;');
set(plugin[get(tooltipname)].textshadow,1); set(plugin[get(tooltipname)].textshadowrange,6.0); set(plugin[get(tooltipname)].textshadowangle,90);
copy(plugin[get(tooltipname)].html,hotspot[get(name)].unit_key);
set(plugin[get(tooltipname)].enabled,false);
</action>


<action name="popup" type="Javascript" protect="true"><![CDATA[
// Start edit by Hamid - 2021-05-03 -------------------------------------------------------------
var popupcontent = "";
try {
    var item = window.mal_data[krpano.get("hotspot[" + args[1] + "].unit_key")];
    if (item) {
        //content += "<h1>" + item.retailer + "<span class='shopid'>"+item.unit_code+"</span></h1>";
        popupcontent += "<h1>" + item.leasing_tenant + "</h1>";
        popupcontent += "<p>";
        popupcontent += '<ul class="shoplist">';
        popupcontent += '<li class="category">' + item.category + '</li>';
        popupcontent += '<li class="area">' + item.gla + '</li>';
        popupcontent += '<li class="level">' + item.floor + '</li>';
        popupcontent += '<li class="shopid">' + item.unit_code + '</li>';
        try {
            if (item.controls) {
                for (var index in item.controls) {
                    var listItem = item.controls[index];
                    var nameClass =  listItem.name.replace(' ', '').toLowerCase();

					// console.log(listItem);
					// console.log(item.category);

					// send_analytics("open_popup",item.centre_name + " - " + item.unit_key,listItem.name, item.category,(item.leasing_tenant==""?item.unit_code:item.leasing_tenant));
					// console.log('<li class="' + nameClass + '" onclick=\'send_analytics("download_content","' + item.centre_name + " - " + item.unit_key + '","' + listItem.name + '","' + item.category + '","' + (item.leasing_tenant==""?item.unit_code:item.leasing_tenant) + '");\' >' + '<a target="_blank" href="' + listItem.url + '">Download</a></li>');
					// popupcontent += '<li class="' + nameClass + '" onclick=\'send_analytics("download_content","' + item.centre_name + " - " + item.unit_key + '","' + listItem.name + '","' + item.category.replace(/'/g, "````") + '","' + (item.leasing_tenant==""?item.unit_code:item.leasing_tenant) + '");\' >' + '<a target="_blank" href="' + listItem.url + '">Download</a></li>';
					// popupcontent += '<li class="' + nameClass + '" onclick=\'send_analytics("download_content","' + item.centre_name + " - " + item.unit_key + '","' + listItem.name.replace(/'/g, "````") + '","' + item.category.replace(/'/g, "````") + '","' + (item.leasing_tenant==""?item.unit_code:item.leasing_tenant) + '");\' >' + '<a target="_blank" href="' + listItem.url + '">Download</a></li>';
					popupcontent += '<li class="' + nameClass + '" onclick=\'send_analytics("download_content","' + item.centre_name.replace(/'/g, "````") + " - " + item.unit_key + '","' + listItem.name.replace(/'/g, "````") + '","' + item.category.replace(/'/g, "````") + '","' + (item.leasing_tenant==""?item.unit_code:item.leasing_tenant).replace(/'/g, "````") + '");\' >' + '<a target="_blank" href="' + listItem.url + '">Download</a></li>';
                }
            }
        } catch (e) {
			// console.log(e);
        }
        popupcontent += '</ul>';
        popupcontent += '</p>';
    }
} catch (error) {
    console.log('error***', error);
}
// End edit by Hamid - 2021-05-03 -------------------------------------------------------------

let scroller = document.getElementById("scroller");
let inner_scroller = document.getElementById("inner_scroller");

// Start edit by Hamid - 2021-05-03 -------------------------------------------------------------
// let datacontent = '<div class="text_content">' + krpano.get("data["+args[1]+"].content")+ '</div>';
let datacontent = '<div class="text_content">' + popupcontent + '</div>';
// End edit by Hamid - 2021-05-03 -------------------------------------------------------------

inner_scroller.innerHTML = datacontent;
window.krpano = krpano;
if(!krpano.device.ios){$("#scroller").niceScroll({autohidemode:"scroll",cursorcolor:"#fff",cursoropacitymax:0.7,cursorwidth:3,cursorborder:"1px solid #fff",cursorborderradius:"0px"});};
krpano.call("show_html_div()");
// console.log(item);
// send_analytics("open_popup",(item.leasing_tenant==""?item.unit_code:item.leasing_tenant),"");
send_analytics("open_popup",item.centre_name + " - " + item.unit_key,(item.leasing_tenant==""?item.unit_code:item.leasing_tenant), item.category);
]]></action>

</krpano>
