var gmapStuff = {
		
		map: null,
		
		currentLocation: null,
		
		markerManager: null,
		
		locationMarker:null,
		
		markerClusterer: null,
		
		directions:null,

		createMyLocationMarker: function(){
			if(gmapStuff.map != null && gmapStuff.currentLocation != null){
				var point = new google.maps.LatLng(gmapStuff.currentLocation.split("|")[0].split(",")[0], gmapStuff.currentLocation.split("|")[0].split(",")[1]);
				var myIcon = new google.maps.Icon(G_DEFAULT_ICON);
  		      	myIcon.image = "/img/your_location.png";
		      	myIcon.iconSize = new google.maps.Size(60, 60);
		      	myIcon.shadow = "";
					gmapStuff.locationMarker = new google.maps.Marker(new google.maps.LatLng(gmapStuff.currentLocation.split("|")[0].split(",")[0], gmapStuff.currentLocation.split("|")[0].split(",")[1]), {icon:myIcon});
					gmapStuff.map.addOverlay(gmapStuff.locationMarker);
					gmapStuff.locationMarker.hide();
			}
		},
		
		markerClick: function(e){
			gmapStuff.directions.clear();
			this.openExtInfoWindow(gmapStuff.map, 'info_window', '', {beakOffset:8, ajaxUrl:'/events/eventInfo/' + this.getTitle()});
			GEvent.addListener(gmapStuff.map, 'extinfowindowupdate', gmapStuff.resizeInfoWindow);
			$('#directions').removeClass('alpha omega box_4');
		},
		
		clusterClick: function(e){
			var markers = e.getMarkers();
			var ids = '';
			for (var i=0; i < markers.length; i++) {
				ids += markers[i].marker.getTitle() + ',';
			};
		markers[0].marker.openExtInfoWindow(gmapStuff.map, 'info_window', '', {beakOffset:8, ajaxUrl:'/events/eventList/' + ids});
		},
		
		resizeInfoWindow: function(e){
			gmapStuff.map.getExtInfoWindow().resize();
			GEvent.removeListener(gmapStuff.map, 'extinfowindowupdate', gmapStuff.resizeInfoWindow);
		},
		
		mouseOverTour: function(e){
			console.log(this);
			console.log(this.polylineoptions);
		},

		loadDirections: function(e){
			gmapStuff.directions.load('from:'+ e.from_here.value + ' to:' + e.to_here.value); // "from: Seattle to: San Francisco" or "from: Toronto to: Ottawa to: New York"
		},
		
		revealDirections: function(e){
			$('#directions').addClass('alpha omega box_4');
		},
		
		openWindow: function(marker, eventID){
			if(!marker.openExtInfoWindow){
				setTimeout(openWindow, 1000);
			} else {
				marker.openExtInfoWindow(gmapStuff.map, 'info_window', '', {beakOffset:8, ajaxUrl:'/events/eventInfo/' + eventID});
			}
			
		},
		
		openWindow2: function(coords){
			if(gmapStuff.map){
					var point = new google.maps.LatLng(coords.split("|")[0].split(",")[0], coords.split("|")[0].split(",")[1]);
					var zoom = coords.split("|")[1];
					var id = coords.split("|")[2];
					if(gmapStuff.markerManager){
						var lat = point.lat();
						var lon = point.lng();
						var marker = gmapStuff.markerManager.getMarker(lat, lon, parseInt(zoom)); 
						marker.openExtInfoWindow(gmapStuff.map, 'info_window', '', {beakOffset:8, ajaxUrl:'/events/eventInfo/' + id});
					}
					return false;
				}
		},
				
		init: function(){
			$(".continent").click(function(){
				if(gmapStuff.map){
					if($(this).hasClass("currentLocation") && gmapStuff.currentLocation != null){
						var point = new google.maps.LatLng(gmapStuff.currentLocation.split("|")[0].split(",")[0], gmapStuff.currentLocation.split("|")[0].split(",")[1]);
						gmapStuff.map.setZoom(7);
						gmapStuff.map.panTo(point);
						gmapStuff.locationMarker.show();
						return false;
					} else {
						gmapStuff.locationMarker.hide();
						var point = new google.maps.LatLng($(this).attr("rel").split("|")[0].split(",")[0], $(this).attr("rel").split("|")[0].split(",")[1]);
						gmapStuff.map.setZoom(parseInt($(this).attr("rel").split("|")[1]));
						gmapStuff.map.panTo(point);
						return false;
					}
				}
			});
			
			$(".directions").click(function(){
				if(gmapStuff.map){			
					var rel = $(this).attr("rel");
					var point = new google.maps.LatLng(rel.split("|")[0].split(",")[0], rel.split("|")[0].split(",")[1]);
					
					if(gmapStuff.markerManager){
						var lat = parseFloat(rel.split("|")[0].split(",")[0]);
						var lon = parseFloat(rel.split("|")[0].split(",")[1]);
						var zoom = parseInt(rel.split("|")[1]);
						var marker = gmapStuff.markerManager.getMarker(lat, lon, zoom); 
						marker.openExtInfoWindow(gmapStuff.map, 'info_window', '', {beakOffset:8, ajaxUrl:'/events/eventInfo/' + rel.split("|")[2]});
					}
					gmapStuff.map.setZoom(parseInt($(this).attr("rel").split("|")[1]));
					gmapStuff.map.panTo(point);
					$("html, body").animate({scrollTop:0}, 'slow');
					return false;
				}
			});
		}
		
	}
	
	

