var sitePlanLocateImg, sitePlanImg, phasesBox, allPoints, legendDesktop, availabilityDesktop, housesBox, housesBoxFull, housesGallTitle, houseDetailbox;
// var urlToLoadSiteplan = "http://3.135.73.135/wp-content/themes/empire-theme/empire-touchscreen/lots.xml";
//var urlToLoadSiteplan = "http://3.135.73.135/general-services/?request=lots&tid=908";
// var urlToLoadSiteplan = "http://3.135.73.135/general-services/?request=lots&tid=47334";
// console.log("ready siteplan");
var XMLSiteplan;
var urlToLoadSiteplan;
var siteplanContent;
var isWeb = true;
var display_prices_siteplan = false;
var containerLeft;
var addedTop = 0;
//variables para el resize
// var screenHeight = jQuery(window).height();
// var screenWidth = jQuery(window).width();
function formatSiteplan(number) {
var num = number.replace(/\,/g, '');
if (!isNaN(num)) {
num = num.toString().split('').reverse().join('').replace(/(?=\d*\,?)(\d{3})/g, '$1,');
num = num.split('').reverse().join('').replace(/^[\,]/, '');
}
return num;
}
jQuery(window).resize(function () {
resizeSiteplan();
});
function createVarsSiteplan() {
containerLeft = jQuery('#containerLeft');
sitePlanLocateImg = jQuery('#sitePlanLocateImg');
sitePlanImg = jQuery('#sitePlanImg');
phasesBox = jQuery('#phasesBox');
allPoints = jQuery('#allPoints');
legendDesktop = jQuery('#legendDesktop');
availabilityDesktop = jQuery('#availabilityDesktop');
housesBox = jQuery('#housesBox');
housesBoxFull = jQuery('#housesBoxFull');
housesGallTitle = jQuery('#housesGallTitle');
houseDetailbox = jQuery('#houseDetailbox');
siteplanContent = jQuery('.siteplanContent');
sectionSiteplan = jQuery('.sectionSiteplan');
}
function loadSiteplanXML() {
console.log("loadSiteplanXML ajax: %o", urlToLoadSiteplan);
jQuery.ajax({
type: 'xml',
url: urlToLoadSiteplan,
method: "GET",
dataType: "xml",
success: function (receivedXML) {
XMLSiteplan = receivedXML;
loadSiteplan();
resizeSiteplan();
},
});
}
function resizeSiteplan() {
// console.log("resizeSiteplan");
setTimeout(function () {
if (screenWidth > 768) {
if (screenWidth > screenHeight) { //landscape
containerLeft.height("100%");
jQuery("#containerRight").height("100%");
jQuery("#siteplan").removeClass("largePortrait");
if (isWeb) {
//sectionSiteplan.height(screenHeight - 60 - addedTop).css("top", addedTop);
sectionSiteplan.height(screenHeight - 60 - addedTop);
}
} else {//portrait
jQuery("#siteplan").addClass("largePortrait");
jQuery("#containerRight").height("auto");
if (isWeb) {
sectionSiteplan.height(screenHeight - 60 - addedTop).css("top", addedTop);
containerLeft.height(screenHeight - 170);
} else {
containerLeft.height(screenHeight - jQuery("#containerRight").height() - 80);
}
}
} else {
jQuery("#siteplan").removeClass("largePortrait");
if (screenWidth > screenHeight) { //landscape
containerLeft.height(screenHeight - 120);
jQuery("#containerRight").height(screenHeight + 60);
} else { //portrait
containerLeft.height(screenHeight - 170);
jQuery("#containerRight").height("auto");
}
if (isWeb) {
sectionSiteplan.height(screenWidth).css("top", addedTop);
}
}
locateImageOn(sitePlanLocateImg, sitePlanImg, "img");
locateContainerOn(sitePlanLocateImg, allPoints);
}, 20);
}
var uniqueavailabilityOpts = ["Buildable Lot", "Move-In Ready", "Sold", "On Hold"];
var uniqueavailabilityOptsVars = ["available", "mooveinready", "sold", "hold"];
var catsAddedDisplay = "block";
function loadSiteplan() {
var display_prices_node = jQuery(XMLSiteplan).find('display_prices');
var hide_categories = jQuery(XMLSiteplan).find('hide_categories').text();
// var move_in_text = jQuery(XMLSiteplan).find('move_in_text').text();
if (hide_categories == "1") {
catsAddedDisplay = "none";
}
var buildable_text = jQuery(XMLSiteplan).find('buildable_lot_text').text();
var move_in_text_comm = jQuery(XMLSiteplan).find('move_in_ready_text').text();
var sold_text = jQuery(XMLSiteplan).find('sold_text').text();
var hold_text = jQuery(XMLSiteplan).find('on_hold_text').text();
uniqueavailabilityOpts[0] = buildable_text;
uniqueavailabilityOpts[1] = move_in_text_comm;
uniqueavailabilityOpts[2] = sold_text;
uniqueavailabilityOpts[3] = hold_text;
if (parseInt(display_prices_node.text()) == 1) {
display_prices_siteplan = true;
}
// aqui
var phases = jQuery(XMLSiteplan).find('phase');
let phaseId;
if (phases.length > 1) {
let content = '';
phasesBox.html(content);
phaseId = jQuery('#phasesSelect').val();
} else {
jQuery(".legendLine").css('display', 'none');
phasesBox.css('display', 'none');
phasesBox.prev().css('display', 'none');
phases.each(function () {
phaseId = jQuery(this).attr('phase_id');
})
}
changePhase(phaseId);
}
var pzObj_siteplan;
// console.log("________________222");
function visibleZoom() {
jQuery("#zoomInOutContainer").css("display", "block");
}
function zoomInSiteplan() {
console.log("zoom in 4");
//sitePlanImg.pinchzoomer({maxZoom:3, scaleMode:"smart"});
pzObj_siteplan = PinchZoomer.get("sitePlanImg");
pzObj_siteplan.zoomIn(0.3);
}
function zoomOutSiteplan() {
console.log("zoom out 4");
//sitePlanImg.pinchzoomer({maxZoom:3, scaleMode:"smart"});
pzObj_siteplan = PinchZoomer.get("sitePlanImg");
pzObj_siteplan.zoomOut(0.3);
}
var curHousesArray = [];
function lotCurHousesArray() {
curHousesArray = [];
allPoints.find(".lotPoint").each(function () {
var related = jQuery(this).attr("data-related");
var arr = related.split(",");
for (var i = 0; i < arr.length; i++) {
if (arr[i] != "") {
let homeID = arr[i];
if (!curHousesArray.includes(homeID)) {
curHousesArray.push(arr[i]);
}
}
}
});
}
function changePhase(phaseId) {
closeHouseDetail();
closeLotGallery();
let newPhase = jQuery(XMLSiteplan).find('phase');
jQuery('#phasesSelect').val(phaseId);
newPhase.each(function () {
if (jQuery(this).attr('phase_id') == phaseId) {
//image
let newImg = jQuery(this).find('phaseImg');
loadImageSiteplan(newImg);
//lots
let Lots = jQuery(this).find('lots').find('Lot');
var catArray = loadLotsSiteplan(Lots, phaseId)
//Legend Info
let Legend = jQuery(this).find('legend');
var LegendTitle = Legend.find('title').text();
let LegendItems = Legend.find('item');
loadLegendSiteplan(LegendItems, LegendTitle, catArray);
//Availability
let lotAvailability = jQuery(this).find('lots').find('Lot');
loadAvailabilitySiteplan(lotAvailability, phaseId);
//loadGalleryHouses
}
});
}
function loadImageSiteplan($image) {
allPoints.css({ "opacity": 0 });
sitePlanImg.animate({ "opacity": 0 }, 50, function () {
sitePlanLocateImg.attr('src', $image.text());
sitePlanLocateImg.on('load', function () {
allPoints.animate({ "opacity": 1 }, 450, function () {
sitePlanImg.animate({ "opacity": 1 }, 250);
});
resizeSiteplan();
});
})
}
var hasHold = false;
var hasBuildable = false;
var hasQuick = false;
var hasSold = false;
function loadLotsSiteplan($array, phaseId) {
var lotName;
var phasePosX, phasePosY;
var catArray = [];
allPoints.html('');
if (phaseId == 0) {
var phases = jQuery(XMLSiteplan).find('phase');
phases.each(function () {
phasePosX = jQuery(this).find('phasePosX');
phasePosY = jQuery(this).find('phasePosY');
phasePosX = phasePosX.text();
phasePosY = phasePosY.text();
if (phasePosX != '' || phasePosY != '') {
let name = jQuery(this).find('name');
let content = `
${name.text()}
`
allPoints.append(content);
curHousesArray = [];
}
});
} else {
hasHold = false;
hasBuildable = false;
hasQuick = false;
hasSold = false;
$array.each(function () {
let state = jQuery(this).attr('lot_ava');
let cat = jQuery(this).find('Lot_area').text();
let homeId;
let lotPosX = jQuery(this).find('posX').text();
let lotPosY = jQuery(this).find('posY').text();
let availability = jQuery(this).find('availability').text();
let isModelHome = jQuery(this).find('isModelHome').text();
let color_point = jQuery(this).find('color_point').text();
let size_point = jQuery(this).find('size_point').text();
let stage = jQuery(this).find('stage').text();
let lotId = jQuery(this).attr('lot_id');
let houses = jQuery(this).find('houses');
let eachHouse = jQuery(houses).find("house");
if (catArray.indexOf(cat) === -1) {
catArray.push(cat);
}
lotName = jQuery(this).find('Lot_name').text();
homeId = jQuery(this).find('houses').find('house').attr('house_id');
var actionOnClick = "";
var classOnClick = "hasPointer";
var relatedHomes = "";
if (eachHouse.length == 0) {
actionOnClick = "closeHouseDetail(); closeLotGallery();";
classOnClick = "noPointer";
relatedHomes = ",";
} else if ((eachHouse.length == 1) && (color_point == "blue")) {
actionOnClick = "openHouseDetailSiteplan('" + homeId + "','" + lotId + "');";
jQuery(eachHouse).each(function () {
relatedHomes += jQuery(this).attr("house_id") + ",";
});
} else {
actionOnClick = "openLotGallery('" + lotName + "','" + lotId + "');";
jQuery(eachHouse).each(function () {
relatedHomes += jQuery(this).attr("house_id") + ",";
});
}
if ((color_point == "red") || (color_point == "yellow") || (color_point == "black")) {
actionOnClick = "closeHouseDetail(); closeLotGallery();";
classOnClick = "noPointer";
relatedHomes = ",";
}
if (color_point == "black") {
hasHold = true;
}
if (color_point == "green" && stage !== 'Model') {
hasBuildable = true;
}
if (color_point == "blue") {
hasQuick = true;
}
if (color_point == "red") {
hasSold = true;
}
let content = ``;
allPoints.append(content);
lotCurHousesArray();
});
}
return catArray;
}
function loadLegendSiteplan($array, title, catArray) {
var htmlLegend = ''
htmlLegend += `
${title}
`;
htmlLegend += `
`;
$array.each(function (index) {
let icon = jQuery(this).find('itemIcon').text();
let name = jQuery(this).find('itemName').text();
let color = jQuery(this).find('itemColor').text();
let addedClass = "";
if (!catArray.includes(name)) {
addedClass = "inv";
}
if (index == 0) {
htmlLegend += `