function reportReview(e){
	if(confirm('Somebody has been naughty and written something inappropriate? If so, click ok and we will look into it.'))
		$(e.target).parent().load($.WEBROOT + "reviews/report/" + $(e.target).attr('reviewId'));
}

function rateReview(e,which){
	$.post($.WEBROOT + "reviews/helpfull/" + $(e.target).parents('a:first').attr('reviewId') + "/" + which);
	$(e.target).parents('a:first').parent().html("Thanks for your feedback");
}

// DEFAULT TEXT
(function($){
	$.fn.defaultInputText = function(which,options){
		options = $.extend({
			cssClass:'gray',
			object:this.get(0)
		}, options || {});
		
		
		// register events
		$(this).focus(_onFocus).blur(_onBlur);
		
		// add clear to form
		$(this).parents('form:first').submit(_clearFromForm);
		
		if($(this).get(0).value.length == 0){
			$(this).addClass(options.cssClass).val(which);
		}
				
		function _onFocus(){
			if(this.value==which){
				$(this).removeClass(options.cssClass).val('');
			}
		};
		
		function _onBlur(){
			 if(this.value==which || this.value.length == 0){
				$(this).addClass(options.cssClass).val(which);
			}
		};
		
		function _clearFromForm(){
			if(options.object.value==which){
				options.object.value='';
			}
		}
		
	};
})(jQuery);

$.gmap = {
	showMap : function(){
		$('#map').show();
		$.gmap.drawMarkers();
	},

	hideMap : function(){
		$('#map').hide('slow');
	},

	initialize : function(){
		this.map = new GMap2('map');
		var customUI = this.map.getDefaultUI();
		customUI.maptypes.hybrid = false;
		customUI.maptypes.physical = false;
		this.map.setUI(customUI);
		this.geocoder = new GClientGeocoder();
	},
	
	initializeSmall : function(){
		if (GBrowserIsCompatible()) {
		    this.map = new GMap2(document.getElementById("smallMap"));
		    this.map.setUIToDefault();
		    this.geocoder = new GClientGeocoder();
		  }
	},
	
	
	showAddress : function (address) {
	  if (this.geocoder) {
	    $.gmap.geocoder.getLatLng(
	      address,
	      function(point) {
	        if (!point) {
	          alert(address + " not found");
	        } else {
	          $.gmap.map.setCenter(point, 14);
	          var marker = new GMarker(point);
	          $.gmap.map.addOverlay(marker);
	        }
	      }
	    );
	  }
	},
	
	drawMarkers : function(jsonString){
		$.gmap.map.clearOverlays();
		$results = $('#map').data('data');
		$.each($results,function(i){
			var location = this;
			if ($.gmap.geocoder) {
				$.gmap.geocoder.getLatLng(
		          this.Location.postcode,
		          function(point) {
		            if (!point) {
		              alert(" not found");
		            } else {
		              	var marker = new GMarker(point);
		              	$.gmap.map.addOverlay(marker);
		                GEvent.addListener(marker, "click", function(){
		                	$.gmap.displayPoint(marker,location);
						});
		                $('#'+location.Game.id).click(function(){
		                	$.gmap.displayPoint(marker,location);
		                });
		                if(0==i){
		                	$.gmap.map.setCenter(point, 12);
		                	$.gmap.displayPoint(marker,location);
		              	}
		            }
		          }
		        );
		      }
		});
	},

	displayPoint : function (marker,location){
		$.gmap.map.panTo(marker.getLatLng());
		var markerOffset = $.gmap.map.fromLatLngToDivPixel(marker.getLatLng());
		var html = $.gmap.generateInfoWindowHTML(location);
		marker.openInfoWindowHtml(html);
	},
	
	generateInfoWindowHTML : function (location){
		var html = "<div id='message'>";
		html = "<h3>" + location.Location.name + "</h3>";
		html += "<p>" + location.Location.postcode + "</p>";
		html += "<p>" + location.GameType.name + ", "+ location.Format.name +"</p>";
		html += "<p>" + location.Day.name + "</p>";
		html += "</div>";
		return html;
	}
}