// JavaScript Document
var gMapCms ;
var gMapCmsDb;
var gMapCmsDebug;
mapCmsUserOnLoad=window.onload; //store userdefeined onload function here
henworx.MapCms.Load={};
henworx.MapCms.Load.Events=new function(){
	this.beforeLoad= new Array(); //array of functions to be fired before mapcms is loaded
	this.afterLoad= new Array(); //array of functions to be fired after mapsms is loaded
	
}
window.onload=function(){
	
	gMapCms = new henworx.MapCms();
 	gMapCmsDb= new henworx.MapCms.DB();
 	gMapCmsDebug= new Debug();		
	gMapCmsDb.getRecent(500);
	//gMapCmsDb.getRecentXmlFile('recent.xml');
	
	if(mapCmsUserOnLoad){mapCmsUserOnLoad()}
	_events=henworx.MapCms.Load.Events;
		
	
	for(i=0;i<_events.beforeLoad.length;i++){
		_a= _events.beforeLoad[i];
		if(typeof(_a)=='function') {_a();}
	}
	
		switch (gCenterType){
			case "recent":
				_l=gMapCmsDb.recentLocations[0];
			break;
			case "recent_highlight":
				for(i=0;i<gMapCmsDb.recentLocations.length;i++){
					if(gMapCmsDb.recentLocations[i].getCustomField('highlight')){
						_l=gMapCmsDb.recentLocations[i]
						break;
					}
				}
				if(typeof(_1) == 'undefined'){
					_l=new henworx.MapCms.Address("Germany","53.5973774","6.7180445");
				}
			break;
			case "address":
				_l=new henworx.MapCms.Address(gCenterAddress);
			break
			case "latlng":
				_default_latlng = gCenterLatLng.split('|');
				if(_default_latlng[0] == ''){
					_default_latlng[0] = 53.5973774;
				}
				if(_default_latlng[1] == '' || typeof(_default_latlng[1]) == 'undefined'){
					_default_latlng[1] = 6.7180445;
				}
				_l=new henworx.MapCms.Address("Germany",_default_latlng[0],_default_latlng[1]);
				break;
			default:
			_l=new henworx.MapCms.Address("Germany","53.5973774","6.7180445");
		}
	gMapCms.centerAt=_l;	
	gMapCms.zoom=parseInt(gZoomLevel);
	gMapCms.initialize();
		gMapCms.allLocations=gMapCmsDb.recentLocations;
		gMapCms.addLocation(gMapCmsDb.recentLocations)
		
		if(typeof(objlinkrel) == 'object'){
			gMapCms.putAllMarker();
		}
		else{
			gMapCms.putAllMarker();
			gMapCms.map.clearOverlays();
		}
		
		
		
		//lastLoc=gMapCmsDb.recentLocations[gMapCmsDb.recentLocations.leghth-1];
		//gMapCmsDebug.append(lastLoc);
		//gMapCms.zoom=15;

		
   		

	for(i=0;i<_events.afterLoad.length;i++){
		_a=_events.afterLoad[i];
		if(typeof(_a)=='function') {_a();}
	}	

}
