
$(function() {	
	googleMaps.init();
	$("#auMapLink").click(function(){window.open(this.href); return false;});
});


//google Maps (quick n dirrrty)
var googleMaps = {
	
	init: function () {

		function trMarker(point, r_address, map) {
			var iconTr = new GIcon();
			iconTr.image = "/public/images/icn_map-tr.png";
			iconTr.iconSize = new GSize(48, 48);
			iconTr.iconAnchor = new GPoint(0, 48);
			iconTr.infoWindowAnchor = new GPoint(0, 48); 
			var marker =  new GMarker(point,iconTr);
			return marker;
		}
		
		function brMarker(point, r_address, map) {
			var iconBr = new GIcon();
			iconBr.image = "/public/images/icn_map-br.png";
			iconBr.iconSize = new GSize(48, 48);
			iconBr.iconAnchor = new GPoint(0, 0);
			iconBr.infoWindowAnchor = new GPoint(0, 0); 
			var marker =  new GMarker(point,iconBr);
			return marker;
		}
				
		
		if (GBrowserIsCompatible()) {
			
			var mapLondon = new GMap2(document.getElementById("map"));
			mapLondon.addControl(new GSmallMapControl()); 
			mapLondon.enableDoubleClickZoom();
			var pointLondon = new GLatLng(51.52390, -0.07651);
			mapLondon.setCenter(pointLondon,15);
			mapLondon.addOverlay(trMarker(pointLondon, 'This is BD'), mapLondon);
			
			//get directions onclick
			$('#directions').submit(function(e) {
				/*
				
				$('#map-control:not(.open)').animate(
					{'left' : '360px'}
					,500
					,function()
					{	$(this).addClass('open');
						addCloseEvent();
						
					}
				);
				$('#directions-panel:not(.open)').animate(
					{'left' : '0'}
					,500
					,function()
					{	$(this).addClass('open');
					}
				);
				function addCloseEvent() {
					
					$('#map-control a').toggle(
						function(){ 
							$(this).parent().animate(
								{'left' : '0'}
								,500
								
							);
							$('#directions-panel').animate(
								{'left' : '-360px'}
								,500
							)
							return false;
						},
						function(){ ;
							$(this).parent().animate(
								{'left' : '360px'}
								,500
								
							);
							$('#directions-panel').animate(
								{'left' : '0'}
								,500
							)
							return false;
						}
					);
					
				}*/
				function addOpenEvent() {
					alert('');
					$('#map-control.closed a').click(
						
					);
				}
				
				directionsPanel = document.getElementById("directions-panel");
				directions = new GDirections(mapLondon, directionsPanel);			
		
				directions.load("from: " + $('#in_postcode').val() + " to: E1 6PQ");
				
				e.preventDefault();
	
			});
			
				
				

		}		
	
		
	}
	
}





