OpenLayers.Control.OLAnglingIdentify = OpenLayers.Class(OpenLayers.Control, {'infourl':'lib/AnglingTech/php/getinfo.php?',defaultHandlerOptions:{'single':true,'double':false,'stopSingle':false,'stopDouble':false,'delay':100,'pixelTolerance':null,'stopMove':false},

	initialize: function(options) {
		this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions);
		OpenLayers.Control.prototype.initialize.apply(this, arguments);
		//this.handler = new OpenLayers.Handler.Hover(this,{'click':this.onClick,'move':this.onMove},this.handlerOptions	);
		this.handler = new OpenLayers.Handler.Click(this,{'click': this.trigger},this.handlerOptions);
	},

/*	onPause: function(e) {
		var tolerance = new OpenLayers.Pixel(10, 10);
		var min_px = new OpenLayers.Pixel(e.xy.x - tolerance.x, e.xy.y + tolerance.y);
		var max_px = new OpenLayers.Pixel(e.xy.x + tolerance.x, e.xy.y - tolerance.y);
		var min_ll = map.getLonLatFromPixel(min_px);
		var max_ll = map.getLonLatFromPixel(max_px);
		pt = min_ll.clone();

		//var point = OpenLayers.Projection.transform(new OpenLayers.Geometry.Point(min_ll.lon,min_ll.lat), new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
		//var mapbounds= map.getExtent().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")).toBBOX();
		pt.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
		max_ll.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
		mapbounds = pt.lon + ',' + pt.lat + ',' + max_ll.lon + ',' + max_ll.lat;
		var mapresolution = map.getResolution();
		url = this.infourl + 'mapres=' + mapresolution +'&bbox=' + mapbounds + '&pt='+ pt.lon + ',' + pt.lat;

		OpenLayers.loadURL(url, '', map, function(response) {
				if (popup) {
						popup.destroy();
						popup = null;
				}
				popup = new OpenLayers.Popup.AnchoredBubble("identify", new OpenLayers.LonLat(min_ll.lon, min_ll.lat), new OpenLayers.Size(210, 210),response.responseText, null, true);
				//popup.imageSrc = "/images/cloud_popup_relative_black.png";
				map.addPopup(popup);
				popup.setBackgroundColor('black');
			}
		);
	 },*/

	 trigger: function(e) {
		 if (!this.active){
			 return false;
		 }
		var tolerance = new OpenLayers.Pixel(10, 10);
		var min_px = new OpenLayers.Pixel(e.xy.x - tolerance.x, e.xy.y + tolerance.y);
		var max_px = new OpenLayers.Pixel(e.xy.x + tolerance.x, e.xy.y - tolerance.y);
		var min_ll = map.getLonLatFromPixel(min_px);
		var max_ll = map.getLonLatFromPixel(max_px);
		pt = min_ll.clone();

		//var point = OpenLayers.Projection.transform(new OpenLayers.Geometry.Point(min_ll.lon,min_ll.lat), new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
		//var mapbounds= map.getExtent().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")).toBBOX();
		pt.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
		max_ll.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
		mapbounds = pt.lon + ',' + pt.lat + ',' + max_ll.lon + ',' + max_ll.lat;
		var mapresolution = map.getResolution();
		url = this.infourl + 'mapres=' + mapresolution +'&bbox=' + mapbounds + '&pt='+ pt.lon + ',' + pt.lat;

		if(popup){
			popup.destroy();
			popup = null;
		}	
		
		popup =  new OpenLayers.Control.ATPopupControl({'bottom':60,'left':60,'width':200,'url':url});
		map.addControl(popup);	
		popup.maximizeControl();				

/*
		OpenLayers.loadURL(url, '', map, function(response) {
				if (popup) {
						popup.destroy();
						popup = null;
				}
				popup = new OpenLayers.Popup.AnchoredBubble("identify", new OpenLayers.LonLat(min_ll.lon, min_ll.lat), new OpenLayers.Size(210, 100),response.responseText, null, true);
				//popup.imageSrc = "/images/cloud_popup_relative_black.png";
				map.addPopup(popup);
				popup.setBackgroundColor('black');
			}
		);

*/				

						
		
	 },

	onMove: function(evt) {
		// if this control sent an Ajax request (e.g. GetFeatureInfo) when
		// the mouse pauses the onMove callback could be used to abort that
		// request.
	},

	CLASS_NAME: "OpenLayers.Control.OLAnglingIdentify"
});

