/*
 * Author: Genhan Chen
 * Email: genhan.chen@azgs.az.gov
 */

var map, searchControl, filterControl;
function init(){
	map = new L.Map("map");
	
	// Cloudmade / OpenStreetMap tiled layer
	var cmUrl = 'http://{s}.tile.cloudmade.com/f7d28795be6846849741b30c3e4db9a9/997/256/{z}/{x}/{y}.png',
		cmAttribution = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery � <a href="http://cloudmade.com">CloudMade</a>',
		cmOptions = { maxZoom: 18, attribution: cmAttribution };
	var cloudmade = new L.TileLayer(cmUrl, cmOptions);

	/* WMS layer */
	var wmsUrl = "http://opengis.azexperience.org/geoserver/wms";
		wmsLayer = new L.TileLayer.WMS(wmsUrl, {
			maxZoom: 10, 
			layers: "vae:usa", 
			format: "image/png", 
			transparent: true 
		}); 
	
	/* WFS GeoJSON layer */
	var wfsLayer = map.wfsLayer = new L.GeoJSON.WFS("http://opengis.azexperience.org/geoserver/wfs", "vae:ACERT", {
		pointToLayer: function(latlng) { 
			return new L.Marker(latlng, { 
				icon: new L.Icon({ 
					iconUrl: "style/images/logos/?Agency?png", /// ? + property name used as the image name + ? + image type
					iconHighlightUrl: "style/images/logos/highlight/?Agency?png",
					iconSize: new L.Point(16, 16) 
				}) 
			});
		},
		popupObj: new JadeContent("templates/wfsIdentify.jade"),
		popupOptions: { maxWidth: 1000, centered: true },
		hoverFld: "Name"
	}); 
	
	var center = new L.LatLng(34.1618, -111.53332);
	
	map.setView(center, 7).addLayer(cloudmade).addLayer(wmsLayer);
	
	map.addLayer(wfsLayer);
	
	searchControl = new L.Control.Search({
		highlightSymbolUrl: "style/images/logos/highlight/?Agency?png"
	});
	map.addControl(searchControl);
	
	filterControl = new L.Control.Filter([{"category" : "Agency", "items" : agencyItems}, 
	                                          {"category" : "Access", "items" : accessItems}, 
	                                          {"category" : "Information", "items" : infoItems}, 
	                                          {"category" : "Camping", "items" : campingItems}, 
	                                          {"category" : "Facilities", "items" : facilitiesItems}, 
	                                          {"category" : "Trails", "items" : trailsItems}, 
	                                          {"category" : "Natural History", "items" : naturalHistoryItems}, 
	                                          {"category" : "Water Sports", "items" : waterSportsItems}]);
	map.addControl(filterControl);
	
	/// Add map events
	map.on("layeradd", function(e){
		searchControl.setAutocompleteItems(this.wfsLayer, "Name");
	});
	
	map.on("popupopen", function(e){
		searchControl.hidePopup();
		filterControl.hidePopup();
		
		this._reopen = false;
		
		/***this._resetPopup = jQuery.extend({}, e.popup);****/
		var linkInPopup = document.getElementById("title-link");
		
		L.DomEvent.addListener(linkInPopup, 'click', function(evt) {
			var url = evt.target.getAttribute("url");
			
			/***********************************************************
			var goBack = L.DomUtil.create("span", "popup-link-back");
			L.DomEvent.addListener(goBack, 'click', function(evt){
				this._reopen = true;
				this.closePopup();				
			}, this)
			
			
			this._popup._container.appendChild(goBack);
			***********************************************************/
			
			var linkPage = L.DomUtil.create("iframe", "acert-link-frame");
			linkPage.style.width = "600px";
			linkPage.style.height = "500px";
			linkPage.style.marginTop = "15px";
			linkPage.src = url;
			
			this._popup.setContent(linkPage);
			
		}, this);
		
	});
	
}

@@ -3484,17 +3484,17 @@
 idth = %22
-6
+8
 00px%22;%0A%09
@@ -3521,17 +3521,17 @@
 ght = %225
-0
+2
 0px%22;%0A%09%09

Change the size of click link popup