var GMapsSearchShopEvent = new Class({
	Extends: swellCoreshopGMaps,
        options: {
        },
		initialize: function(options){
			
			this.parent(options);
			this.displayMap(null);
        },
		findAllLocsToMap: function() {
			var foundShopLocs = [];
			
			var tmpShopLats = $$('.coreshopSearchLocInp_Lat'); //get Lat hidden inputs for ALL LOCS
			tmpShopLats.each(function(item) {
				var shopLocsArIndxs = ['Lat', 'Lng', 'Loc_id', 'LocType', 'LocHoverId', 'LocLink'];
				var shopLocsArVals = [];
				var tmpItmIdParts = item.id.split('_');
				

				
				shopLocsArVals[0] = parseFloat(item.value);
				shopLocsArVals[1] = parseFloat($('currLocLong_'+tmpItmIdParts[1]).value);
				shopLocsArVals[2] =  parseInt(tmpItmIdParts[1]);
				shopLocsArVals[3] = $('currLocType_'+shopLocsArVals[2]).value;
				shopLocsArVals[4] = $('currLocHoverId_'+shopLocsArVals[2]).value;
				shopLocsArVals[5] = $('currLocLink_'+shopLocsArVals[2]).value;
				
				var tmpCurrArr = shopLocsArVals.associate(shopLocsArIndxs);
				foundShopLocs.include(tmpCurrArr);
				//alert(shopLocsArVals[0]+'  '+shopLocsArVals[1]);
			});
			this.locations = foundShopLocs;
		},
		displayMap: function(data) {
			if (GBrowserIsCompatible()) {
				this.parent(data);
				
				this.createAllMarkers();//load marker points onto google maps here

				//map.centerAndZoomOnBounds(map.getBoundsLatLng());
				this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds));
				this.map.setCenter(this.bounds.getCenter());
			}
		},
		createAllMarkers: function() {
			this.findAllLocsToMap();
			this.locations.each(this.initMarker.bind(this));
		},
		initMarker: function (item) {
			/* Code for each map point plotted */
				var latlng = new GLatLng(item['Lat'], item['Lng']);
			
				//alert(item['LocLink']);
				var tmpMarker = this.createMarker(latlng, item['Loc_id'], item['LocHoverId'], item['LocLink'], item['LocType']);
				this.map.addOverlay(tmpMarker);
				this.bounds.extend(tmpMarker.getPoint());
		},
		createMarker: function(point, loc_ID, hoverId, locLink, locType) {
			//alert(locLink);
			var iconToUse = $empty;
			if(locType == 'shop')
				iconToUse = this.mapIcons['inactiveShop'];
			else if(locType == 'event') 
				iconToUse = this.mapIcons['event'];
			// Set up our GMarkerOptions object
				markerOptions = { icon:iconToUse };
				this.markers[''+loc_ID] = new GMarker(point, markerOptions);

				GEvent.addListener(this.markers[''+loc_ID], "mouseover", function(point) {
					var targetEle = document.getElementById(hoverId);
					var newEleXloc = findPosX(document.getElementById('map_canvas'))+parseInt(myGoogleMapsObj.map.fromLatLngToContainerPixel(point).x);
					var newEleYloc = findPosY(document.getElementById('map_canvas'))+(parseInt(myGoogleMapsObj.map.fromLatLngToContainerPixel(point).y)-150);
					
					
					var myClientWindowScroll = getScrollXY();
					
					var wasMovedDown = false;
					
					if(myClientWindowScroll[1] > (newEleYloc)) {
						//alert(myClientWindowScroll[1]+"-----"+(newEleYloc));
						newEleYloc = newEleYloc+((myClientWindowScroll[1] - newEleYloc)+10)
						newEleXloc = newEleXloc + 16;
						wasMovedDown = true;
					}
					
					var myClientWindowSize = getClientSize();
					var tmpCurrWindowDiff = (newEleXloc+423) - myClientWindowSize[0];
					if(tmpCurrWindowDiff >= -10) {
						newEleXloc = newEleXloc - (tmpCurrWindowDiff+20);
						if(wasMovedDown == true) {
							newEleYloc = newEleYloc+270;
							
						}
					}

					targetEle.style.left = newEleXloc+'px';
					targetEle.style.top = newEleYloc+'px';
					targetEle.style.zIndex = '1';

					targetEle.style.display = 'block';
				});
			
				GEvent.addListener(this.markers[''+loc_ID], "mouseout", function() {
					var targetEle = document.getElementById(hoverId);
					targetEle.style.display = 'none';
				});
				
				GEvent.addListener(this.markers[''+loc_ID], "click", function() {
					location.href = locLink;
				});
				
				
				return this.markers[''+loc_ID];
		}
});
