$(document).ready(function() { resizeLayout(); var today = new Date(); window.timelineMin = 1212303600; window.timelineMax = Math.round(today.getTime() / 1000); window.timeline1Position = window.timelineMin; window.timeline2Position = window.timelineMax; updateDates(); /* map initialization */ if (GBrowserIsCompatible()) { window.map = new GMap2(document.getElementById('map')); window.map.setCenter(new GLatLng(38.27, -95.75), 5); window.map.setMapType(G_HYBRID_MAP); window.map.addControl(new GLargeMapControl()); updateMap(); GEvent.addListener(window.map, 'moveend', function() { initializeUpdate(); }); GEvent.addListener(window.map, 'zoom', function() { initializeUpdate(); }); } /* timeline initialization */ $('#timeline').slider({ min: window.timelineMin, max: window.timelineMax, range: true, handles: [{ start: window.timeline1Position, min: window.timelineMin, max: window.timelineMax, id: 'timelineSlider1' }, { start: window.timeline2Position, min: window.timelineMin, max: window.timelineMax, id: 'timelineSlider2' }], slide: function(e, ui) { if (ui.handle.attr('id') == 'timelineSlider1') { window.timeline1Position = ui.value; } else { window.timeline2Position = ui.value; } updateDates(); }, stop: function(e, ui) { initializeUpdate(); } }); /* event handling */ $('#preview').click(function() { $(this).hide(); }); $('.helpLaunch').click(function() { $('#detail').animate({ width: 'hide', }, 'fast'); $('#panelLink').html('Show panel'); $('#help').show(); $('#help > div').load('/pages/help'); $('#helpContainer').hide(); $('#backContainer').show(); }); $('#backContainer').click(function() { $('#backContainer').hide(); $('#helpContainer').show(); $('#help').hide(); }); $('#permalinkLink').click(function() { if (window.map.getCurrentMapType().getName() == 'Map') { var mapType = 'road'; } else { var mapType = 'satellite'; } var newLocation = '/?ll=' + window.map.getCenter().lat() + ',' + window.map.getCenter().lng() + '&zoom=' + window.map.getZoom() + '&type=' + mapType; if ($('#mediaType').val()) { newLocation += '&media=' + $('#mediaType').val(); } if ($('#search').val()) { newLocation += '&q=' + encodeURIComponent($('#search').val()) .replace(/%20/g, '+') } if (window.timeline1Position != window.timelineMin) { var date = new Date(); date.setTime(window.timeline1Position * 1000); var urlMonth = date.getMonth() + 1; if (urlMonth < 10) { urlMonth = '0' + urlMonth; } var urlDate = date.getDate() + 1; if (urlDate < 10) { urlDate = '0' + urlDate; } newLocation += '&start=' + date.getFullYear() + '-' + urlMonth + '-' + urlDate; } if (window.timeline2Position != window.timelineMax) { var date = new Date(); date.setTime(window.timeline2Position * 1000); var urlMonth = date.getMonth() + 1; if (urlMonth < 10) { urlMonth = '0' + urlMonth; } var urlDate = date.getDate() + 1; if (urlDate < 10) { urlDate = '0' + urlDate; } newLocation += '&end=' + date.getFullYear() + '-' + urlMonth + '-' + urlDate; } window.location = newLocation; }); $('#mapTypeLink').click(function() { if (window.map.getCurrentMapType().getName() == 'Map') { window.map.setMapType(G_HYBRID_MAP); $('#mapTypeLink').html('Switch to road view'); } else { window.map.setMapType(G_NORMAL_MAP); $('#mapTypeLink').html('Switch to satellite view'); } }); $('#panelLink').click(function() { if ($('#detail').css('display') == 'block') { $('#detail').animate({ width: 'hide', }, 'fast'); $('#panelLink').html('Show panel'); } else { $('#detail').animate({ width: 'show', }, 'fast'); $('#panelLink').html('Hide panel'); } }); $('#mediaType').change(function() { initializeUpdate(); }); $('#searchForm').submit(function() { initializeUpdate(); return false; }); $('.emailSignupInput').keypress(function(e) { if (e.which == 13) { $.post('/addresses/add', {address: $(this).val()}); $('.emailSignup').html('Thanks for signing up!'); } }); $('.emailSignupSubmit').click(function() { $.post('/addresses/add', {address: $(this).prev().val()}); $('.emailSignup').html('Thanks for signing up!'); }); }); $(document).unload(function() { GUnload(); }); $(window).resize(function() { resizeLayout(); }); function initializeUpdate() { if (window.mapTimeout) { clearTimeout(window.mapTimeout); } window.mapTimeout = setTimeout(updateMap, 3000); if ($('#noThings').css('display') == 'block') { $('#noThings').fadeOut(); } if ($('#incomplete').css('display') == 'block') { $('#incomplete').fadeOut(); } $('#mapLoader').fadeIn(); } function resizeLayout() { $('#map').height(window.innerHeight - 100); $('#mapLoader').css('top', (window.innerHeight - 100) / 2 - 15); $('#detail').height(window.innerHeight - 140); $('#help').width(window.innerWidth - 20); $('#help').height(window.innerHeight - 120); $('#help div').height(window.innerHeight - 120); $('#spacerContainer').width(window.innerWidth - 435); $('#timeline').width(window.innerWidth - 475); $('#timelineSlider2').css('left', window.innerWidth - 475 - 9); } function updateDates() { var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; var startDate = new Date(); startDate.setTime(window.timeline1Position * 1000); var startDateString = months[startDate.getMonth()] + ' ' + startDate.getDate() + ', ' + startDate.getFullYear(); var endDate = new Date(); endDate.setTime(window.timeline2Position * 1000); var endDateString = months[endDate.getMonth()] + ' ' + endDate.getDate() + ', ' + endDate.getFullYear(); if (window.timeline1Position == window.timelineMin) { if (window.timeline2Position == window.timelineMax) { $('#startDate').html(''); $('#dateSpan').html('all dates'); $('#endDate').html(''); } else { $('#startDate').html(''); $('#dateSpan').html('before'); $('#endDate').html(endDateString); } } else if (window.timeline2Position == window.timelineMax) { $('#startDate').html(''); $('#dateSpan').html('after'); $('#endDate').html(startDateString); } else { $('#startDate').html(startDateString); $('#dateSpan').html('to'); $('#endDate').html(endDateString); } } function updateMap() { window.map.clearOverlays(); var bounds = window.map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var dataFields = { lat1: northEast.lat(), lat2: southWest.lat(), lng1: northEast.lng(), lng2: southWest.lng(), media: $('#mediaType').val(), q: $('#search').val() }; var date = new Date(); if (window.timeline1Position != window.timelineMin) { date.setTime(window.timeline1Position * 1000); dataFields.start = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate(); } if (window.timeline2Position != window.timelineMax) { date.setTime(window.timeline2Position * 1000); dataFields.end = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate(); } if ($('#noThings').css('display') == 'block') { $('#noThings').fadeOut(); } if ($('#incomplete').css('display') == 'block') { $('#incomplete').fadeOut(); } $('#mapLoader').fadeIn(); $.getJSON('/things/retrieve', dataFields, function(json) { $('#mapLoader').fadeOut(); if (json.status == 'none') { if ($('#noThings').css('display') == 'none') { $('#noThings').fadeIn(); } } else { $.each(json.things, function(i, thing) { var typeIcon = new GIcon(); typeIcon.iconSize = new GSize(24, 24); typeIcon.iconAnchor = new GPoint(12, 12); typeIcon.image = '/img/type-' + thing.type + '.png'; typeIcon.shadow = '/img/shadow-' + thing.type + '.png'; typeIcon.shadowSize = GSize(32, 24); markerOptions = { icon: typeIcon }; var point = new GLatLng(thing.lat, thing.lng); var icon = new GIcon(G_DEFAULT_ICON); var marker = new GMarker(point, markerOptions); GEvent.addListener(marker, 'click', function() { $('#detail').html(''); $('#detail').animate({ width: 'show', }, 'slow'); $('#panelLink').html('Hide panel'); $('#detail').load('/things/detail/' + thing.id); }); if (thing.url) { GEvent.addListener(marker, 'mouseover', function() { $().mousemove(function(e) { $('#preview img').attr('src', thing.url); $('#preview').css({ top: e.pageY - 25, left: e.pageX + 5 }); $('#preview img').load(function() { $('#preview').show(); }); }); }); GEvent.addListener(marker, 'mouseout', function() { $().unbind('mousemove'); $('#preview').hide(); }); } window.map.addOverlay(marker); }); if (json.status == 'incomplete') { $('#totalThings').html(json.formattedCount); if ($('#incomplete').css('display') == 'none') { $('#incomplete').fadeIn(); } } } }); }