var projekteTeaser = new Class({
	
	initialize:function(){
		this.mapDiv=$('projekte_map');
		this.projekteDiv=$('projekte');
		
		
		
		this.parseProjects();
		
		this.initMap();
	},
	
	
	
	parseProjects:function(){

		var raw = this.projekteDiv.get('html');
		
		this.projects = JSON.decode(raw);

	},
	
	
	initMap:function(){
		
		if (GBrowserIsCompatible()) {
		    this.map = new GMap2(this.mapDiv, {
				mapTypes:[G_HYBRID_MAP]
			});
		
			this.geocoder = new GClientGeocoder();
		    
			this.geocoded = 0;
		
			this.bounds = new GLatLngBounds();
			
			
			this.geocodeProjects(function(){
				
				this.map.setCenter(this.bounds.getCenter(), this.map.getBoundsZoomLevel(this.bounds));
				this.addMarkersToMap();
				this.map.zoomOut();

				
			}.bind(this));
	    }
		
	},
	
	
	geocodeProjects:function(onReady){
		
		this.projects.each(function(project){
			

			
			this.geocoder.getLatLng(project.adresse, function(point){
				
				this.geocoded++;
				
				project.point = point;
				
				this.bounds.extend(point);
				
				// punkt auf karte hinzufügen
		  		// var marker = new GMarker(point);
				
				
				if(this.geocoded == this.projects.length){
					onReady();
				}
				
				
			}.bind(this));
			
		}.bind(this));
		
	},
	
	
	addMarkersToMap:function(){
		
		this.projects.each(function(project){
			this.map.addOverlay(new GMarker(project.point));
			

		}.bind(this));
		
	}
		

	
});


window.addEvent('domready',function(){
	
	var projects = new projekteTeaser();	
	
});

