///////////////////////////////////////////////////////////
// Class Locations
///////////////////////////////////////////////////////////

var Locations = Class.create({

	///////////////////////////////////////////////////////////
	// initialize
	///////////////////////////////////////////////////////////
	
	initialize:function(element){
		
		this.element = element;
	
		this.locations = [];
		this.locationsDict = []; 	// [27] = locations[index]
	},
	
	
	///////////////////////////////////////////////////
	// getJSONData
	///////////////////////////////////////////////////

	getJSONData:function(){
		
		// get the all data
		new Ajax.Request('/ajax/events/', {
			onComplete:function(transport){

				// get the json object
				var jsonLocations = transport.responseText.evalJSON().positions;
				
				$H(jsonLocations).each(function(arr){
					var obj = arr[1];
					this.locationsDict[obj.id] = this.locations.length;
					this.locations.push(obj);
				}.bind(this));
				
				// wait for the map to be ready, before controls work
				this.element.observe('map:ready', this.updateMap.bind(this));
				
				// make the map
				this.map = new GoogleMap(this, this.element);
				this.countryZoomControls = new CountryZoomControls(this, $('allCountries'));

			}.bind(this)
		});
	},
    
    
    ///////////////////////////////////////////////////
    // initMap
    ///////////////////////////////////////////////////

    initMap:function(e){
	    this.getJSONData();
    },
    
     
     ///////////////////////////////////////////////////
     // updateMap
     ///////////////////////////////////////////////////
 	
     updateMap:function(e){
         if(this.map){
             this.map.update();
         }else{
             this.initMap();
         }
     },
   
     
     ///////////////////////////////////////////////////
     // updateMap
     ///////////////////////////////////////////////////
 	
     zoomCountry:function(obj){
         this.map.zoomCountry(obj)
     }
});

///////////////////////////////////////////////////
// dom:loaded
///////////////////////////////////////////////////

var locations, tabs;
document.observe('dom:loaded', function(){
	if($('map_canvas')){
		locations = new Locations($('map_canvas'), $('id_location'));
	}
        
    tabs = new Tabs(locations, $('tabList'));
});
