if (!RS) {
	var RS = {};
}
RS.pw = {
	init: function() {
		YAHOO.util.Dom.addClass(document.body, "dynamic"); 
		if (document.getElementById("venueJumpMenu")) {
			var venueJumpMenu = document.getElementById("venueJumpMenu");
			venueJumpMenu.onchange = RS.pw.jump;
		}	
		if (RS.Gmaps && RS.Gmaps.length > 0) {
			for (var i=0; i < RS.Gmaps.length; i++) {
				var map = document.getElementById(RS.Gmaps[i].id);
				if (map) {
					RS.pw.maps(map,RS.Gmaps[i]);
					map.style.display = 'block';
				}
			};
			window.onunload = function() {GUnload();};
		}
	},
	maps: function(element,mapinfo) {
		if (GBrowserIsCompatible()) {
			this.map = new GMap2(element);
			this.map.addControl(new GSmallMapControl());
			if (mapinfo.center == null) {
				this.map.setCenter(new GLatLng(55.950254,-3.187606),11);
			} else {
				this.map.setCenter(new GLatLng(mapinfo.center.latitude,mapinfo.center.longitude));
			}

			var icon = new GIcon();
			icon.image = "/img/map-pin-small.png";
			icon.shadow = "/img/map-pin-small-shadow.png";
			icon.iconSize = new GSize(30, 30);
			icon.shadowSize = new GSize(48, 30);
			icon.iconAnchor = new GPoint(15, 35);
			icon.infoWindowAnchor = new GPoint(15, 8);			
			
			var bounds = new GLatLngBounds();			
			bounds.extend(this.map.getCenter());
			for (var i=0; i < mapinfo.markers.length; i++) {
				var markerinfo = mapinfo.markers[i];
				if (markerinfo.latitude != 0 && markerinfo.longitude != 0) {
					var point = new GLatLng(markerinfo.latitude,markerinfo.longitude);
					bounds.extend(point);
					var marker = new GMarker(point,{title: markerinfo.title, icon: icon});
					marker.markerinfo = markerinfo;
					this.map.addOverlay(marker);
					if (markerinfo.url) {
						GEvent.addListener(marker,'click',function(){window.location = this.markerinfo.url})					
					}					
				}
			};
			this.map.setCenter(bounds.getCenter());
			var zoomLevel = this.map.getBoundsZoomLevel(bounds);
			if (zoomLevel > 15) {
				zoomLevel = 15;
			}
			this.map.setZoom(zoomLevel);
		}
	},
	jump: function() {
		window.location = "/matclasses/"+this.options[this.selectedIndex].value+"/";
	}
};
YAHOO.util.Event.onDOMReady(RS.pw.init);
