

var oldPflegestelle = null;
var gmapready = false;

$(document).ready(function(){
	initLightbox();
	
	correctHeight();
});


function correctHeight(){
	if(parseInt($('.content').height()) > 400){	
		$('#innersidebar').css('min-height',parseInt($('.content').height()) - 90);
	}
	
}

function initLightbox(){
	$("a[rel='lightbox']").colorbox({
		current : "",
		previous : "",
		next : "",
		close : "X",
		rel : 'nofollow'
	});	
}



function addMarker(ID, lat, lng, name) {
	if (!gmapready) {
		initializeGoogleMap();
	}
	
	var icon = new GIcon();
	icon.image = "/images/marker.png";		

	icon.iconSize = new GSize(12, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	var point = new GPoint(lat, lng);
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
		showPflegestelle(ID);
	});
	map.addOverlay(marker);
}

function showPflegestelle(iID) {
	if(oldPflegestelle != null){
		oldPflegestelle.removeClass('active');
	}
	$('#pflegestelleliste').scrollTo($('#pflegestelle-' + iID), 400, {
		onAfter : function() {
			$('#pflegestelle-' + iID).addClass('active');
			oldPflegestelle = $('#pflegestelle-' + iID); 
		}

	});
}

function setMapCenter(lat,lng,zoom){
	if (!gmapready) {
		initializeGoogleMap();
	}	
	map.setCenter(new GLatLng(lat, lng), zoom);
}

function initializeGoogleMap() {
	gmapready = true;
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.setMapType(G_NORMAL_MAP);
		map.setCenter(new GLatLng(50.736455137010665, 10.01953125), 6);
		var pos1 = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10, 10));
		map.addControl(new GSmallMapControl(), pos1);
	}
}

