
var _map = null;
var _timeout = null;
var _crosshair = null;
var _markerlist = [];
var _places = [];
var _previous_hash = '';
var _processing = false;
var _block_transparency = false;
var _block_slider = false;
var _block_slider_collapse = false;
var _untransTimeout = null;
var _transTimeout = null;
var _place_results_visible = false;
var _performing_drag = false;
function transparent_all() {
if(!_block_transparency)
for(var i = 0; i < _markerlist.length; i++)
_markerlist[i].transparent();
}
function untransparent_all() {
for(var i = 0; i < _markerlist.length; i++)
_markerlist[i].untransparent();
}
function worldview() {
var bounds = new GLatLngBounds(new GLatLng(-80, -180), new GLatLng(80, 180));
var zoom = _map.getBoundsZoomLevel(bounds);
_map.setCenter(new GLatLng(0, 0), zoom);
close_places();
}
function show_suggestion_box() {
display('find_place_none', 'none');
display('find_place_loading', 'none');
display('find_place_results', 'none');
display('find_place_suggestions', '');
}
function load() {
parse_hash();
if(GBrowserIsCompatible()) {
_crosshair = new Crosshair();
var center = new GLatLng(_lat, _lng);
_map = new GMap2(document.getElementById("map"));
if(typeof _bbox != 'undefined') {
var bounds = new GLatLngBounds(new GLatLng(_bbox.sw_lat, _bbox.sw_lng), new GLatLng(_bbox.ne_lat, _bbox.ne_lng));
_zoom = _map.getBoundsZoomLevel(bounds);
center = bounds.getCenter();
window.location.href = '/map/#lat=' + center.lat().toFixed(6) + '&lng=' + center.lng().toFixed(6) + '&z=' + _zoom;
return;
}
_map.setCenter(center, _zoom);
_map.enableRotation();
_map.addMapType(G_PHYSICAL_MAP);
_map.addControl(new GOverviewMapControl());
_map.addControl(new GLargeMapControl3D(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(15, 15)));
_map.addControl(new GMenuMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(100, 15)));
_map.addControl(new GScaleControl());
_map.enableDoubleClickZoom();
_map.enableContinuousZoom();
_map.enableScrollWheelZoom();
switch(_maptype) {
case 'n':
_map.setMapType(G_NORMAL_MAP);
break;
case 's':
_map.setMapType(G_SATELLITE_MAP);
break;
case 'p':
_map.setMapType(G_PHYSICAL_MAP);
break;
default:
_map.setMapType(G_HYBRID_MAP);
}
GEvent.addListener(_map, 'move', function() {
_crosshair.update();
});
GEvent.addListener(_map, 'moveend', function() {
clearTimeout(_timeout);
_timeout = setTimeout(load_webcams, 1000);
save_hash();
});
GEvent.addListener(_map, 'dragstart', function() {
transparent_all();
_performing_drag = true;
});
GEvent.addListener(_map, 'dragend', function() {
untransparent_all();
_performing_drag = false;
});
_map.addControl(_crosshair);
_timeout = setTimeout(load_webcams, 1000);
setInterval(check_hash, 1000);
$('find_place').onkeydown = function(e) {
if(!e)
e = window.event;
var key = null;
if(e.which)
key = e.which;
else
key = e.keyCode;
if(key == 10 || key == 13)
find_place();
return;
}
// Google Ads.............................
var publisher_id = 'pub-0219134797937958';
var adsManagerOptions = {
  maxAdsOnMap : 2,
  style: 'adunit',
  // The channel field is optional - replace this field with a channel number 
  // for Google AdSense tracking
  channel: '3612822701',
  position: new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(14, 110))
};
adsManager = new GAdsManager(_map, publisher_id, adsManagerOptions);
adsManager.enable();
// Google Ads............................./
}
}
function unload() {
GUnload();
}
function resize() {
_map.checkResize();
load_webcams();
}
function load_webcams() {
var bounds = _map.getBounds();
var sw_lat = bounds.getSouthWest().lat();
var sw_lng = bounds.getSouthWest().lng();
var ne_lat = bounds.getNorthEast().lat();
var ne_lng = bounds.getNorthEast().lng();
var zoom = _map.getZoom();
var a = new AJAX('/ajax/webcams.php', function(response, data) {
if(response == null)
return;
if(response.status != 200)
return;
display_webcams(response.webcams);
return;
}, null, false);
a.ontransferstart = function(){display('loadingwebcams', '');}
a.ontransferend = function(){display('loadingwebcams', 'none');}
a.setParameter('a', 'fullscreen');
a.setParameter('sw_lat', sw_lat);
a.setParameter('sw_lng', sw_lng);
a.setParameter('ne_lat', ne_lat);
a.setParameter('ne_lng', ne_lng);
a.setParameter('zoom', zoom);
a.send();
}
function display_webcams(webcams) {
var marker = null;
var newmarker = [];
var markerlist = [];
var webcamids = [];
var webcamidmap = {};
// Welche webcamids haben wir zur Zeit auf der Karte?
for(var i = 0; i < _markerlist.length; i++) {
webcamids.push(_markerlist[i].wt_webcam.webcamid);
webcamidmap[_markerlist[i].wt_webcam.webcamid] = i;
}
// Die neuen webcamids durchgehen
for(var i = 0; i < webcams.length; i++) {
// Ist diese Webcam schon auf der Karte?
var index = webcamids.indexOf(webcams[i].webcamid);
if(index == -1) {// Nein, neuen Marker erstellen und in die Liste mit den neuen Marker hinzufuegen
marker = new ThumbMarker(32, 32, webcams[i], new GLatLng(webcams[i].lat, webcams[i].lng));
marker.wt_webcam = webcams[i];
GEvent.addListener(marker, 'click', function() {
this.select();
});
GEvent.addListener(marker, 'mouseout', function() {
this.unselect();
});
newmarker.push(marker);
}
else {// Ja, diese Webcam aus der webcamid-Liste nehmen und den Marker in die Liste mit den bestehenden Marker hinzufuegen
webcamids[index] = '';
markerlist.push(_markerlist[index]);
}
}
// Die nicht mehr sichtbaren Marker von der Karte nehmen
for(var i = 0; i < webcamids.length; i++) {
if(webcamids[i].length == 0)
continue;
marker = _markerlist[webcamidmap[webcamids[i]]];
_map.removeOverlay(marker);
}
$('nowebcams').style.display = 'none';
// Die neuen Marker zur Karte hinzufugen
for(var i = 0; i < newmarker.length; i++) {
_map.addOverlay(newmarker[i]);
if(_performing_drag)
newmarker[i].transparent();
markerlist.push(newmarker[i]);
}
_markerlist = markerlist;
update_slider();
}
function update_slider() {
clear('slider_thumblist');
var width = 145 * _markerlist.length;
$('slider_thumblist').style.width = width + 'px';
var a = null;
var img = null;
for(var i = 0; i < _markerlist.length; i++) {
img = $Img('http://images.webcams.travel/thumbnail/' + _markerlist[i].wt_webcam.webcamid + '.jpg', null, 128, 96);
a = $Link('/webcam/' + _markerlist[i].wt_webcam.webcamid, img, '_blank', 'thumb');
a.setAttribute('title', _markerlist[i].wt_webcam.title);
a.setAttribute('index', i);
a.onmouseover = function() {
var index = this.getAttribute('index');
_markerlist[index].highlight();
};
a.onmouseout = function() {
var index = this.getAttribute('index');
_markerlist[index].unhighlight();
};
a.appendChild($Element('br'));
a.appendChild($Text(do_dots(_markerlist[i].wt_webcam.city, 'thumb')));
$('slider_thumblist').appendChild(a);
}
if(_markerlist.length == 0)
$('nowebcams').style.display = '';
}
function find_place() {
var n = $('find_place');
var place = n.value;
if(place.length == 0)
return;
display('find_place_res', '');
display('find_place_none', 'none');
display('find_place_results', 'none');
display('find_place_close', 'none');
display('find_place_loading', '');
display('find_place_suggestions', 'none');
var a = new AJAX('/ajax/findplace.php', function(response, data) {
display('find_place_loading', 'none');
display_places(response);
return;
}, null, false);
a.setParameter('p', place);
a.send();
}
function center_place(p) {
close_places();
var place = _places[p];
var zoom = 13;
if(place.fcl == 'A')
zoom = 6;
_map.setCenter(new GLatLng(place.lat, place.lng), zoom);
}
function display_places(places) {
var n = $('find_place_results');
_place_results_visible = true;
display('find_place_suggestions', 'none');
if(places == null) {
display('find_place_close', '');
display('find_place_none', '');
return;
}
if(places.totalResultsCount == 0) {
display('find_place_close', '');
display('find_place_none', '');
return;
}
clear(n);
display('find_place_close', '');
display(n, '');
_places = new Array();
var text = '';
var subtext = '';
var link = null;
var place = null;
for(var i = 0; i < places.geonames.length; i++) {
place = places.geonames[i];
if(place.fcl == 'A') {
text = place.name;
subtext = place.countryCode;
}
else {
text = place.name;
subtext = '';
if(place.adminName1)
subtext += place.adminName1 + ', ';
subtext += place.countryName;
}
var u = $Element('u');
u.appendChild($Text(text));
link = $Link('javascript: center_place(' + _places.length + ')', u);
// SubText
var small = $Element('small');
small.appendChild($Text(subtext));
link.appendChild(small);
n.appendChild(link);
_places.push(place);
}
if(_places.length == 1)
center_place(0);
}
function close_places() {
display('find_place_res', 'none');
}
function check_hash() {
var hash = window.location.hash.substring(1);
if(hash != _previous_hash) {
parse_hash();
_previous_hash = hash;
_map.setCenter(new GLatLng(_lat, _lng), _zoom);
switch(_maptype) {
case 'n':
_map.setMapType(G_NORMAL_MAP);
break;
case 's':
_map.setMapType(G_SATELLITE_MAP);
break;
case 'p':
_map.setMapType(G_PHYSICAL_MAP);
break;
default:
_map.setMapType(G_HYBRID_MAP);
}
}
}
function parse_hash() {
var hash = window.location.hash.substring(1);
if(hash.length == 0) {
hash = get_cookie('map');
if(hash == null)
return;
}
var p = hash.split('&');
var v = new Array();
for(var i = 0; i < p.length; i++) {
v = p[i].split('=');
switch(v[0]) {
case 'lat':
_lat = parseFloat(v[1]);
break;
case 'lng':
_lng = parseFloat(v[1]);
break;
case 'z':
_zoom = parseInt(v[1]);
break;
case 't':
_maptype = v[1];
break;
default:
break;
}
}
}
function save_hash() {
var point = _map.getCenter();
_lat = point.lat().toFixed(6);
_lng = point.lng().toFixed(6);
_zoom = _map.getZoom();
var m = _map.getCurrentMapType();
if(m == G_NORMAL_MAP)
_maptype = 'n';
else if(m == G_HYBRID_MAP)
_maptype = 'h';
else if(m == G_PHYSICAL_MAP)
_maptype = 'p';
else
_maptype = 's';
var hash = 'lat=' + _lat + '&lng=' + _lng + '&z=' + _zoom + '&t=' + _maptype;
_previous_hash = hash;
location.hash = hash;
set_cookie('map', hash)
}
function toggleFooter() {
var map = $('map');
var mapfooter = $('mapfooter');
var position = mapfooter.getAttribute('wctposition');
if(position == 'closed') {
mapfooter.style.height = '160px';
map.style.bottom = '160px';
display('slider_thumblist', '');
display('mapfooter_show', 'none');
display('mapfooter_hide', '');
mapfooter.setAttribute('wctposition', 'open');
}
else {
mapfooter.style.height = '27px';
map.style.bottom = '27px';
display('slider_thumblist', 'none');
display('mapfooter_hide', 'none');
display('mapfooter_show', '');
mapfooter.setAttribute('wctposition', 'closed');
}
resize();
}
