var ss = sitespecific = {
	mapCallback: null,
	initMap: function(){
		eval(this.mapCallback + "()");	
	},
	loadGoogleMapApis: function(){
		// Import Google JS API
		var script = document.createElement("script");
		//script.src = "http://www.google.com/jsapi?key=ABQIAAAA72wRjaofavE8uGoaZ8REPhRDPD_5I7k9cNoxpd0Rh-kkC-cExRR5g30WGFu3eZ5BUbTRu3MmFs1UZA&callback=googleJSApiLoaded";
		script.src = "http://www.google.com/jsapi?key=ABQIAAAA72wRjaofavE8uGoaZ8REPhQfPCEWhqRXd72SX4o7gwhC4RUAYRRBgQZBrHJqofoVBGwXQ03LiDzLcA&callback=googleJSApiLoaded";
		script.type = "text/javascript";  
		document.getElementsByTagName("head")[0].appendChild(script);	
	},
	globalMap: {
		map: null,
		data: null,
		isInitalized: false,
		show: function(){
			ss.mapCallback = "ss.globalMap.load";
			if (!this.isInitalized) ss.loadGoogleMapApis();
		},
		load: function(){
			this.map = new google.maps.Map2(document.getElementById("map"));
			this.map.setCenter(new google.maps.LatLng(47.611320, -122.337437), 10);
			this.map.setUIToDefault();
			// Load GeoRSS feed
			//var geo = new google.maps.GeoXml(projectFeedUrl);
			//map.addOverlay(geo);
			for (var i=0;i<this.data.length;i++) {
				var point = new google.maps.LatLng(this.data[i].lat, this.data[i].lng);
				this.map.addOverlay(this.createMarker(point, this.data[i]));
			}
			this.isInitalized = true;
		},
		createMarker: function(point, venue){
			var icon = new google.maps.Icon(G_DEFAULT_ICON);
			icon.image = "/sites/all/themes/sitespecific/images/icons/map-marker.png";
			icon.iconSize = new GSize(32, 32);
			icon.iconAnchor = new GPoint(16, 16);
			icon.infoWindowAnchor = new GPoint(16, 16);
			var marker = new google.maps.Marker(point, {icon: icon});
			google.maps.Event.addListener(marker, 'click', function(){
				if (ss.globalMap.htmlCache[venue.id]) {
					ss.globalMap.map.openInfoWindow(point, ss.globalMap.htmlCache[venue.id]);		
				} else {
					$.get(basePath + 'node/' + venue.projects[0].id + '?ajax&template=map&venueid=' + venue.id, function(html){
						ss.globalMap.htmlCache[venue.id] = html;
						ss.globalMap.map.openInfoWindow(point, html);	
					});
				}
			});	
			return marker;
		},
		htmlCache: []		
	}
};

$(function(){
	$('#project .overview .upcomingEvents .more a').bind('click', function(){
		if ($(this).text() == 'More >') {
			$('#project .overview .upcomingEvents .moreEvents').slideDown();
			$(this).text('< Less')
		} else {
			$('#project .overview .upcomingEvents .moreEvents').slideUp();
			$(this).text('More >')		
		}
	});
	$('#project a.videoFile').bind('click', function(){
		$('#overlay').css({'height': $(document).height()});
		$('#overlay').show().css('opacity', 0).fadeTo(500, .75);
		$('#videoDialog').fadeIn(500);
	});
	$('#sidebar .eventsMap a').bind('click', function(){
		$('#overlay').css({'height': $(document).height()});
		$('#overlay').show().css('opacity', 0).fadeTo(500, .75);
		$('#mapDialog').fadeIn(500);
		ss.globalMap.show();
		return false;	
	});
	$('#overlay, div.dialog .close a').bind('click', function(){
		$('#overlay').fadeOut(250);
		$('div.dialog').fadeOut(250);
		return false;	
	});
});

/**
 * Executes after Google JS API script is loaded.
 */
function googleJSApiLoaded() {
	google.load("maps", "2.x", {"callback" : function(){
		ss.initMap();
	}});			
}


