";
var bubble = new H.ui.InfoBubble(event.target.getGeometry(), {
content: info
});
ui.addBubble(bubble);
}
} else {
var point = new H.geo.Point(markd['b']['lat'],markd['b']['lng']);
map.setCenter(point);
var zoom = map.getZoom();
map.setZoom(zoom+2,true);
}
});
}
// Display number of results in div#listings-results
function showResults(map,params) {
var tcount=0;
$('.listing-info').each( function() {
tcount++;
});
// Display number of results displayed on map
$("#listings-loading").css("display","none");
var s=''; if (tcount>1) s = 's';
$("#listings-results").html("
"+tcount+" Map Result"+s+"
");
}
// Get all the listings = magic
function getListings(map,params) {
var bounds = map.getViewModel().getLookAtData().bounds.getBoundingBox();
//console.log("listings");
//console.log(bounds.getBoundingBox());
if (bounds) {
// Figure out the map bounds
var left = bounds.getLeft();
var right = bounds.getRight();
var top = bounds.getTop();
var bottom = bounds.getBottom();
$("#listings-footer").css("display","none");
$("#listings-loading").css("display","block");
$("#listings").css("height","0px");
$("#up-arrow").css("opacity","0.2");
$("#listings").scrollTop(0);
var course = ''; var city = ''; var par = ''; var holes = '';
if (params!==undefined) {
course = params.course;
city = params.city;
par = params.par;
holes = params.holes;
}
$.ajax({
type: "POST",
data: {
course: course,
city: city,
par: par,
holes: holes
},
url: "_xml.php",
dataType: "xml",
success: function(result){
var listings = ''; var j = 0;
var reccount = 1;
$(result).find("row").each(function(){
var rowlat = $(this).find("lat").text();
var rowlong = $(this).find("long").text();
if (rowlat*1>=bottom && rowlat*1<=top && rowlong*1>=left && rowlong*1<=right) {
var courseid = $(this).find("id").text();
var name = $(this).find("name").text();
var desc = $(this).find("desc").text();
var holes = $(this).find("holes").text();
var par = $(this).find("par").text();
var website = $(this).find("website").text();
var teetime = $(this).find("teetime").text();
var address = $(this).find("address").text();
var city = $(this).find("city").text();
var phone = $(this).find("phone").text();
var inc = $(this).find("inc").text();
if (address.length>=25) address = address.substr(0,25)+"...";
var mtop = '';
if (name.length>30) mtop = "margin-top:60px;";
var subtitle = holes+" holes, par "+par;
if (name.indexOf('Practice') >=0) { mtop = "margin-top:84px;"; subtitle = '�'; }
j++;
// Add all the info to the listings array
listings += "
";
if (isFullscreen==1) {
var medrec1 = document.getElementById("re_medrec1").innerHTML;
var medrec2 = document.getElementById("re_medrec1").innerHTML;
if (window.innerWidth>1280) {
// Insert ads for double-column layout
// Place ads after first 10 listings, then 20 more, and every successive 30 ads
if (j%30==0||j==10) {
// use 'medrec2' first, since we have medrec1 on the page already
listings += "
"+medrec2+"
"+medrec1+"
";
}
} else {
if (j%5==0) {
if (reccount%2==1) {
listings += "
"+medrec2+"
";
} else {
listings += "
"+medrec1+"
";
}
reccount++;
}
}
} else if (isFullscreen==0) {
// Add in an advertisement every 5 listings
if (j%5==0) {
var medrec1 = document.getElementById("re_medrec1").innerHTML;
var medrec2 = document.getElementById("re_medrec1").innerHTML;
// use 'medrec2' first, since we have medrec1 on the page already
if (reccount%2==1) {
listings += "
"+medrec2+"
";
} else {
listings += "
"+medrec1+"
";
}
reccount++;
}
}
}
});
// If there are less than 5 listings, add in medrec2 to the listings
if (j<5 && isFullscreen==0) {
var medrec2 = document.getElementById("re_medrec1").innerHTML;
listings += "
"+medrec2+"
";
}
if (j<10 && isFullscreen==1) {
var medrec1 = document.getElementById("re_medrec1").innerHTML;
var medrec2 = document.getElementById("re_medrec1").innerHTML;
// Place ads at bottom of div#listings-container
//console.log($('#listings-container').outerHeight());
var numrows = Math.floor($('#listings-container').outerHeight()/160)-4;
//console.log(numrows);
// Complicated calculation involving the number of stars in the Universe and atomic weights of multiple elements
//var margin = (numrows*160)-(Math.ceil(j/2)*160)+30;
var margin = 0;
listings += "
"+medrec1+"
";
}
// Populate the Listings
and remove bottom margin from last listing
$("#listings").html(listings);
$('.listing:last-child').css('margin','0px');
// Lazy-load listing images
$(".lazy").lazy({
appendScroll: $("#listings"),
afterLoad: function() {
// Show the listings and footer ONLY AFTER images have loaded
$("#listings-loading").css("display","none");
$("#listings").css("height","625px");
$("#listings-header").show();
$("#listings-footer").show();
$("#listings-results-text").css("display","block");
if (isFullscreen==1) {
var winwidth = window.innerWidth;
var winheight = window.innerHeight;
$("#listings").css({
"height": winheight-111,
"margin-left": "10px",
});
}
}
});
showResults(map);
// If there are no listings returned, display zero results
if(j==0) {
if (isFullscreen==0) {
$('#listings').css("height", "625px");
} else { $('#listings').css("height", window.innerHeight-111); }
$('#listings-header').css("display","block");
$('#listings-footer').css("display","block");
$('#listings-results-text').css("display","block");
}
}
});
}
}
// Do something to highlight the marker on the map
function highlightMarker(id) {
for (var m=0;m4) {
var isscrolling = 0;
function clearScroll() {
isscrolling = 0;
$("#listings-header").css("background-color","#f2edef");
$("#listings-footer").css("background-color","#f2edef");
clearInterval(int);
}
function stopScrollDown() {
isscrolling = 0;
$("#listings-footer").css("background-color","#f2edef");
clearInterval(int);
}
// Scroll down
function scrollDown() {
$("#up-arrow").css("opacity","1.0");
if (isscrolling == 0) {
// Only change the footer background color if the 'down' arrow is visible
if ($("#down-arrow").css("opacity")>"0.2") { $("#listings-footer").css("background-color","#fdcf01"); }
isscrolling = 1;
int = setInterval(function(){
var pos = $("#listings").scrollTop();
var bottom = $("#listings")[0].scrollHeight;
if (pos==bottom) {
$("#down-arrow").css("opacity","0.2");
$("#listings-footer").css("background-color","#f2edef");
} else {
$("#listings").scrollTop(pos+25);
}
},100);
} else {
stopScrollDown();
}
}
function stopScrollUp() {
isscrolling = 0;
$("#listings-header").css("background-color","#f2edef");
clearInterval(int);
}
// Scroll up
function scrollUp() {
$("#down-arrow").css("opacity","1.0");
if (isscrolling == 0) {
// Only change the header background color if the 'up' arrow is visible
if ($("#up-arrow").css("opacity")>"0.2") { $("#listings-header").css("background-color","#fdcf01"); }
isscrolling = 1;
int = setInterval(function(){
var pos = $("#listings").scrollTop();
if (pos==0) {
$("#up-arrow").css("opacity","0.2");
$("#listings-header").css("background-color","#f2edef");
} else {
$("#listings").scrollTop(pos-25);
}
},100);
} else {
stopScrollUp();
}
}
function isMobile() {
try{ document.createEvent("TouchEvent"); return true; }
catch(e){ return false; }
}
if (isMobile()) {
$("#listings-header").on("touchstart",scrollUp);
$("#listings-footer").on("touchstart",scrollDown);
$("#listings").on("touchstart",clearScroll);
} else {
$("#listings-footer").on("mouseover",scrollDown);
$("#listings-footer").on("mouseout",stopScrollDown);
$("#listings-header").on("mouseover",scrollUp);
$("#listings-header").on("mouseout",stopScrollUp);
}
//}
// Display the 'up' arrow when scrolling begins, unless we're at the top, and
// Display the 'down' arrow unless we're at the bottom
$("#listings").scroll(function(){
// Show both arrows as soon as we start scrolling
$("#up-arrow").css("opacity","1.0");
$("#down-arrow").css("opacity","1.0");
// Hide arrows if we reach top or bottom
if ($(this).scrollTop() == 0) {
$("#up-arrow").css("opacity","0.2");
$("#listings-header").css("background-color","#f2edef");
} else if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
$("#down-arrow").css("opacity","0.2");
$("#listings-footer").css("background-color","#f2edef");
}
});
// Only show the fullscreen button if screen width is higher than 1632px
if (window.innerWidth>=1632) { $('#fullscreen').css("display","block"); }
});
function fsYO(){
isFullscreen = 1;
var winwidth = window.innerWidth;
var winheight = window.innerHeight;
$("#overlay").css({
"background": "#ffffff",
"display": "block",
"position": "fixed",
"top": 0,
"left": 0,
"width": screen.width,
"height": winheight+100,
"z-index": 1000
});
$("#listings").css("height","0px");
$("#map-container").css({
"background": "#ffffff",
"position": "fixed",
"left": "0px",
"top": "76px",
"z-index": "1002"
});
$("#map").css({
"height": winheight-76,
"width": winwidth-630,
"margin-top": 0
});
$("#listings-container").css({
"background": "#ffffff",
"height": winheight,
"margin": "0px",
"padding-top": "10px",
"position": "fixed",
"left": winwidth-630,
"top": "0px",
"width": "630px",
"z-index": "1002"
});
$("#listings-header").css("margin","0 10px");
$("#listings-footer").css("margin","0 10px");
$("#closeFS").css({
"display": "block",
"position": "fixed",
"top": "10px",
"left": winwidth-40,
"z-index": "10000"
});
$('#header-search-container').html($('#search-form'));
$('#header-search-container').css({
"width": "initial"
});
$('#FSHead').css({
"display": "block",
"height": 76,
"width": winwidth-630,
"position": "fixed",
"top": 0,
"left": 0,
"z-index": "1002"
});
// Add a hidden form variable, but only if it doesn't exist
// If it does exist, change the value to '1'
if (!$('#post-fullscreen').length) {
$('#search-form').append("");
} else { $('#post-fullscreen').val(1); }
checkDimensions();
}
// Go back to normal page layout
function unFS(){
isFullscreen = 0;
var winwidth = window.innerWidth;
$("#overlay").css("display","none");
$("#listings").css({
"height": "0px",
"margin-left": "0px",
});
$("#map-container").css({
"background": "transparent",
"position": "initial",
"z-index": "0"
});
$("#map").css({
"height": "660px",
"width": "662px"
});
$("#listings-container").css({
"height": "733px",
"margin": "6px 0 15px 0",
"padding-top": "0px",
"position": "relative",
"left": "0px",
"width": "300px",
"z-index": "0"
});
$('.re_search').css({
"position": "initial",
"clear": "none"
});
$("#listings-header").css("margin","0px");
$("#listings-footer").css("margin","0px");
$("#closeFS").css("display","none");
$("#FSHead").css("display","none");
$('.re_search div').css("clear","none");
$('#search-container').html($('#search-form'));
// Clear fullscreen form value
$('#post-fullscreen').val(0);
// Return form fields to normal
$('.re_search').css({
"margin-top": 17,
"margin-bottom": 5,
});
$('#course').css("width",244);
$('#location').css("width",156);
$('#par').css("width",123);
$('#holes').css("width",124);
var fs_params = {
course: $('#course').val(),
city: $('#location').val(),
par: $('#par').val(),
holes: $('#holes').val(),
};
// Re-center map if window is resized
var mcenter = map.getCenter();
var mzoom = map.getZoom();
initMap(mcenter,mzoom,fs_params);
}
// Reload map on full-screen window resize
var rtime;
var timeout = false;
var delta = 200;
$(window).resize(function() {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
});
// Do the reload stuff only after the window has finished being resized
function resizeend() {
if (new Date() - rtime < delta) {
setTimeout(resizeend, delta);
} else {
timeout = false;
if (isFullscreen==1) {
// Resize elements on page
fsYO();
//checkDimensions();
}
}
}
function checkDimensions() {
if ((window.innerWidth>=1600 && isFullscreen)) {
$('#fullscreen').css("display","block");
$('.re_search div').css("clear","none");
$('.re_search #submit').css("background","url(//classifieds.castanet.net/images/icons/search-mag20.png) no-repeat");
$('#header-search-container').css({
"background": "transparent",
"float": "right",
"clear": "none",
"margin-right": 16,
"padding": 0,
"width": 660
});
$('.re_search').css("margin-top",16);
$('#course').css("width",244);
$('#location').css("width",156);
$('#par').css("width",123);
$('#holes').css("width",124);
} else if (window.innerWidth<1600 && isFullscreen) {
$('.re_search div').css("clear","both");
$('#header-search-container').css({
"background": "rgba(0,0,0,0.6)",
"border-bottom-right-radius": 7,
"float": "left",
"clear": "both",
"padding": "0 5px 5px 10px",
"width": 171
});
$('.re_search').css("margin-top",0);
$('.re_search select').css("width", 166);
}
if (window.innerWidth<=1280 && isFullscreen) {
$('#listings-container').css({
"left": window.innerWidth-320,
"width": 310
});
$('#listings-header').css("margin-right","0px");
$('#listings-footer').css("margin-right","0px");
$('.re_search #submit').css("background","url(images/search-mag20-white.png) no-repeat");
$('#FSHead').css("width",window.innerWidth-320);
$('#map').css("width",window.innerWidth-320);
} else if (window.innerWidth>1280 && isFullscreen) {
}
var fs_params = {
course: $('#course').val(),
city: $('#location').val(),
par: $('#par').val(),
holes: $('#holes').val(),
};
var mcenter = map.getCenter();
//console.log(mcenter);
var mzoom = map.getZoom();
initMap(mcenter,mzoom,fs_params);
}
initMap();