var centerLatitude = 52.4786;
var centerLongitude = 13.3538;
var startZoom = 8;
var map;
var thermelogo = new GIcon();
thermelogo.image = 'http://www.therme-sauna-freizeitbad.de/logotherme.png';
thermelogo.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo.iconSize = new GSize(26, 25);
thermelogo.shadowSize = new GSize(50, 22);
thermelogo.iconAnchor = new GPoint(13, 25);
thermelogo.infoWindowAnchor = new GPoint(13, 1);
thermelogo.infoShadowAnchor = new GPoint(26, 13);


var thermelogo90001 = new GIcon();
thermelogo90001.image = 'http://www.therme-sauna-freizeitbad.de/icon/90001.png';
thermelogo90001.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90001.iconSize = new GSize(26, 25);
thermelogo90001.shadowSize = new GSize(50, 22);
thermelogo90001.iconAnchor = new GPoint(13, 25);
thermelogo90001.infoWindowAnchor = new GPoint(13, 1);
thermelogo90001.infoShadowAnchor = new GPoint(26, 13);

var thermelogo90010 = new GIcon();
thermelogo90010.image = 'http://www.therme-sauna-freizeitbad.de/icon/90010.png';
thermelogo90010.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90010.iconSize = new GSize(26, 25);
thermelogo90010.shadowSize = new GSize(50, 22);
thermelogo90010.iconAnchor = new GPoint(13, 25);
thermelogo90010.infoWindowAnchor = new GPoint(13, 1);
thermelogo90010.infoShadowAnchor = new GPoint(26, 13);

var thermelogo90011 = new GIcon();
thermelogo90011.image = 'http://www.therme-sauna-freizeitbad.de/icon/90011.png';
thermelogo90011.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90011.iconSize = new GSize(26, 25);
thermelogo90011.shadowSize = new GSize(50, 22);
thermelogo90011.iconAnchor = new GPoint(13, 25);
thermelogo90011.infoWindowAnchor = new GPoint(13, 1);
thermelogo90011.infoShadowAnchor = new GPoint(26, 13);

var thermelogo90100 = new GIcon();
thermelogo90100.image = 'http://www.therme-sauna-freizeitbad.de/icon/90100.png';
thermelogo90100.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90100.iconSize = new GSize(26, 25);
thermelogo90100.shadowSize = new GSize(50, 22);
thermelogo90100.iconAnchor = new GPoint(13, 25);
thermelogo90100.infoWindowAnchor = new GPoint(13, 1);
thermelogo90100.infoShadowAnchor = new GPoint(26, 13);

var thermelogo90101 = new GIcon();
thermelogo90101.image = 'http://www.therme-sauna-freizeitbad.de/icon/90101.png';
thermelogo90101.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90101.iconSize = new GSize(26, 25);
thermelogo90101.shadowSize = new GSize(50, 22);
thermelogo90101.iconAnchor = new GPoint(13, 25);
thermelogo90101.infoWindowAnchor = new GPoint(13, 1);
thermelogo90101.infoShadowAnchor = new GPoint(26, 13);

var thermelogo90110 = new GIcon();
thermelogo90110.image = 'http://www.therme-sauna-freizeitbad.de/icon/90110.png';
thermelogo90110.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90110.iconSize = new GSize(26, 25);
thermelogo90110.shadowSize = new GSize(50, 22);
thermelogo90110.iconAnchor = new GPoint(13, 25);
thermelogo90110.infoWindowAnchor = new GPoint(13, 1);
thermelogo90110.infoShadowAnchor = new GPoint(26, 13);

var thermelogo90111 = new GIcon();
thermelogo90111.image = 'http://www.therme-sauna-freizeitbad.de/icon/90111.png';
thermelogo90111.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo90111.iconSize = new GSize(26, 25);
thermelogo90111.shadowSize = new GSize(50, 22);
thermelogo90111.iconAnchor = new GPoint(13, 25);
thermelogo90111.infoWindowAnchor = new GPoint(13, 1);
thermelogo90111.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91000 = new GIcon();
thermelogo91000.image = 'http://www.therme-sauna-freizeitbad.de/icon/91000.png';
thermelogo91000.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91000.iconSize = new GSize(26, 25);
thermelogo91000.shadowSize = new GSize(50, 22);
thermelogo91000.iconAnchor = new GPoint(13, 25);
thermelogo91000.infoWindowAnchor = new GPoint(13, 1);
thermelogo91000.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91001 = new GIcon();
thermelogo91001.image = 'http://www.therme-sauna-freizeitbad.de/icon/91001.png';
thermelogo91001.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91001.iconSize = new GSize(26, 25);
thermelogo91001.shadowSize = new GSize(50, 22);
thermelogo91001.iconAnchor = new GPoint(13, 25);
thermelogo91001.infoWindowAnchor = new GPoint(13, 1);
thermelogo91001.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91010 = new GIcon();
thermelogo91010.image = 'http://www.therme-sauna-freizeitbad.de/icon/91010.png';
thermelogo91010.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91010.iconSize = new GSize(26, 25);
thermelogo91010.shadowSize = new GSize(50, 22);
thermelogo91010.iconAnchor = new GPoint(13, 25);
thermelogo91010.infoWindowAnchor = new GPoint(13, 1);
thermelogo91010.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91011 = new GIcon();
thermelogo91011.image = 'http://www.therme-sauna-freizeitbad.de/icon/91011.png';
thermelogo91011.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91011.iconSize = new GSize(26, 25);
thermelogo91011.shadowSize = new GSize(50, 22);
thermelogo91011.iconAnchor = new GPoint(13, 25);
thermelogo91011.infoWindowAnchor = new GPoint(13, 1);
thermelogo91011.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91100 = new GIcon();
thermelogo91100.image = 'http://www.therme-sauna-freizeitbad.de/icon/91100.png';
thermelogo91100.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91100.iconSize = new GSize(26, 25);
thermelogo91100.shadowSize = new GSize(50, 22);
thermelogo91100.iconAnchor = new GPoint(13, 25);
thermelogo91100.infoWindowAnchor = new GPoint(13, 1);
thermelogo91100.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91101 = new GIcon();
thermelogo91101.image = 'http://www.therme-sauna-freizeitbad.de/icon/91101.png';
thermelogo91101.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91101.iconSize = new GSize(26, 25);
thermelogo91101.shadowSize = new GSize(50, 22);
thermelogo91101.iconAnchor = new GPoint(13, 25);
thermelogo91101.infoWindowAnchor = new GPoint(13, 1);
thermelogo91101.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91110 = new GIcon();
thermelogo91110.image = 'http://www.therme-sauna-freizeitbad.de/icon/91110.png';
thermelogo91110.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91110.iconSize = new GSize(26, 25);
thermelogo91110.shadowSize = new GSize(50, 22);
thermelogo91110.iconAnchor = new GPoint(13, 25);
thermelogo91110.infoWindowAnchor = new GPoint(13, 1);
thermelogo91110.infoShadowAnchor = new GPoint(26, 13);

var thermelogo91111 = new GIcon();
thermelogo91111.image = 'http://www.therme-sauna-freizeitbad.de/icon/91111.png';
thermelogo91111.shadow = 'http://www.therme-sauna-freizeitbad.de/logothermeschadow.png';
thermelogo91111.iconSize = new GSize(26, 25);
thermelogo91111.shadowSize = new GSize(50, 22);
thermelogo91111.iconAnchor = new GPoint(13, 25);
thermelogo91111.infoWindowAnchor = new GPoint(13, 1);
thermelogo91111.infoShadowAnchor = new GPoint(26, 13);


var deselectCurrent = function() {};


var PromoControl = function(url) {
	this.url_ = 'http://www.therme-sauna-freizeitbad.de/therme-sauna-freizeitbad-berlin-brandenburg.php';
};

PromoControl.prototype = new GControl(true);

PromoControl.prototype.initialize = function(map) {
	var container = document.createElement("div");
	container.innerHTML =
	
		
		

		
		
		'<a href="http://www1.belboon.de/adtracking/0284b307da7a0065ae000648.html" target="_blank">'
		+ '<img src="http://www1.belboon.de/adtracking/0284b307da7a0065ae000648.img" border="0" width="120" '
		+ ' height="90" alt="" /></a>';
		



	
	
		
	container.style.width='120px';
	container.style.height='90px';
	
	url = this.url_;
	
	GEvent.addDomListener(container, "click", function() {
		document.location = url;
	});
	
	map.getContainer().appendChild(container);
	
	return container;
};

PromoControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(
		G_ANCHOR_TOP_LEFT, new GSize(70, 10));
};



function initializePoint(pointData) {
	var point = new GLatLng(pointData.latitude,
		pointData.longitude);
		

var testvar = pointData.badicon;

if(testvar == 90001){
	testicon = 	thermelogo90001; 
}else if(testvar == 90010){
	testicon = 	thermelogo90010; 
}else if(testvar == 90011){
	testicon = 	thermelogo90011; 
}else if(testvar == 90100){
	testicon = 	thermelogo90100; 	
}else if(testvar == 90101){
	testicon = 	thermelogo90101; 	
}else if(testvar == 90110){
	testicon = 	thermelogo90110; 	
}else if(testvar == 90111){
	testicon = 	thermelogo90111; 	
}else if(testvar == 91000){
	testicon = 	thermelogo91000; 
}else if(testvar == 91001){
	testicon = 	thermelogo91001; 
}else if(testvar == 91010){
	testicon = 	thermelogo91010; 	
}else if(testvar == 91011){
	testicon = 	thermelogo91011; 	
}else if(testvar == 91100){
	testicon = 	thermelogo91100; 	
}else if(testvar == 91101){
	testicon = 	thermelogo91101; 	
}else if(testvar == 91110){
	testicon = 	thermelogo91110; 
}else if(testvar == 91111){
	testicon = 	thermelogo91111; 	
} else {
	testicon = 	thermelogo;
}
		
		
	var marker = new GMarker(point, {title:pointData.state, icon:testicon});
	var listItem = document.createElement('li');
	var listItemLink =
		listItem.appendChild(document.createElement('a'));
	var visible = false;

	listItemLink.href = "#";
	listItemLink.innerHTML = '<strong>' + pointData.city
		+ ' </strong><span>' 
		+ pointData.state + '</span>';
	
	var focusPoint = function() {
		deselectCurrent();
		// Abschnitt current muss in der CSS-Datei
		// entsprechend ergänzt werden
		listItem.className = 'current';
		deselectCurrent = function() {
			listItem.className = ''; }
		//marker.openInfoWindowHtml(pointData.address);
		var infoTabs = [	new GInfoWindowTab("Bad", pointData.address) ];
		marker.openInfoWindowTabsHtml(infoTabs);
		
		map.panTo(point);
		return false;
	}

	GEvent.addListener(marker, 'click', focusPoint);	
	listItemLink.onclick = focusPoint;

	pointData.show = function() {
		if (!visible) {
			document.getElementById(
				'sidebarmap-list').appendChild(listItem);
			map.addOverlay(marker);
			visible = true;
		}
	}
	pointData.hide = function() {
		if (visible) {
			document.getElementById(
				'sidebarmap-list').removeChild(listItem);
			map.removeOverlay(marker);
			visible = false;
		}
	}

	pointData.show();
}

function initializeSortTab(type) {
	var listItem = document.createElement('li');
	var listItemLink = listItem.appendChild(
		document.createElement('a'));

	listItemLink.href = "#";
	listItemLink.innerHTML = type;
	listItemLink.onclick = function() {
		changeBodyClass('standby', 'loading');

		for(id in markers) {
			if (markers[id].type == type || 'Alle' == type)
				markers[id].show();
			else
				markers[id].hide();	
		}

		changeBodyClass('loading', 'standby');

		return false;
	}

	document.getElementById('filters').appendChild(listItem);
}

function windowHeight() {
	// Standardbrowser (Mozilla, Safari usw.)
	if (self.innerHeight)
		return self.innerHeight;
	// IE 6
	if (document.documentElement
		&& document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	// IE 5
	if (document.body)
		return document.body.clientHeight;
	// Nur für den Fall...
	return 0;
}

function handleResize() {
	var height = windowHeight()
		- document.getElementById('toolbar').offsetHeight - 30;
		
		
	document.getElementById('map').style.height
		= 500 + 'px';
	document.getElementById('sidebarmap').style.height
		= 500 + 'px';
}

function changeBodyClass(from, to) {
	document.body.className =
		document.body.className.replace(from, to);
	return false;
}


function init() {
	var type;
	var allTypes = { 'Alle':[] };
	
	document.getElementById('button-sidebarmap-hide').onclick =
		function() {
			return changeBodyClass('sidebarmap-right', 'nosidebarmap');
		};
	document.getElementById('button-sidebarmap-show').onclick =
		function() {
			return changeBodyClass('nosidebarmap', 'sidebarmap-right');
		};
	handleResize();
	
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	
	
	
	map.setCenter(new GLatLng(centerLatitude,
		      centerLongitude), startZoom);

	for(id in markers) {
		initializePoint(markers[id]);
		allTypes[markers[id].type] = true;
	}

	for(type in allTypes) {
		initializeSortTab(type);
	}

	changeBodyClass('loading', 'standby');
}

window.onresize = handleResize;
window.onload = init;
window.onunload = GUnload;
