/*

This javascript file will hold the scripts required for the Map on the home page

*/

atlas.mapHandler = {

	mapClickQueryRunning : false,

	drawMap : function()
	{
		MQA.EventUtil.observe(window, 'load', function()
			  	{
					window.map = new MQA.TileMap(       // Constructs an instance of MQA.TileMap
					  document.getElementById('map'),   //the id of the element on the page you want the map to be added into
					  1,                                //intial zoom level of the map
					  {lat:0.0, lng:0.0}, //the lat/lng of the map to center on
					  'map');
					  
			
			
					MQA.withModule('zoomcontrol4', 'geocoder', 'viewcontrol4', function()
					{
			
					  map.addControl(
						new MQA.LargeZoomControl4(),
						new MQA.MapCornerPlacement(MQA.CORNER_TOPRIGHT)
					  );
			
					  map.addControl(
					      new MQA.ViewControl4(),
					      new MQA.MapCornerPlacement(MQA.MapCorner.TOP_RIGHT)
					  );
			
					});
			  		
			  		map.setLogoPlacement(1,new MQA.MapCornerPlacement(2,new MQA.Size(6,5)));
					map.setLogoPlacement(0,new MQA.MapCornerPlacement(2,new MQA.Size(13,25)));
			
	
					MQA.EventManager.addListener(map, 'click', eventRaised); 
					MQA.EventManager.addListener(map, 'dragend', dragEventHandler); 

					function dragEventHandler(event)	{
						atlas.omniture.sendData("MQAtlasDragMap");
					}
					function eventRaised(evt)
					{
						if (atlas.mapHandler.mapClickQueryRunning == true)
							return;
							
						atlas.mapHandler.mapClickQueryRunning = true;	
						var e=document.createElement('div');
						e.innerHTML=evt.eventName;
						
						 var url = "/identify?lat=" + evt.ll.getLatitude() + "&lng=" + evt.ll.getLongitude();
						 atlas.mapHandler.showLoadingForHomePage(atlas.menu.clickPos);
						 $.ajax({
							url: url,
							success: atlas.helper.getGeoLocationFromOSM,
							context: document
						 });
						 
						
						
					}
				});
	},
	
	showLoadingForHomePage : function(pos) 
	{
		$('#loaderCntner').css('display','block');
		$('#loaderCntner').css('top',pos.y);
		$('#loaderCntner').css('left',pos.x);
	}

}
