


 $(document).ready(function() {




	if(typeof GUnload == 'function') {
		updateMap(false, false);
	}


	$("#main ul li").prepend("<span></span>");

	

	$("span.email a").noSpamReplace();


	$("a.youtube").youtubeEmbed();



	$(".address").click  
	(  
		function()  
		{
			$('.address').removeClass('active');

			$(this).addClass('active');

			var txt = $(this).children("span.bubble_txt").text();
			var geo = $(this).children("span.geo").text();
			updateMap(geo, txt);

			return false;

		} 
	);  

});


$.fn.noSpamReplace = function() {
	$(this).each(function(){

		var email = $(this).html();
		email = email.replace("NOSPAM","");

		$(this).html(email);
		$(this).attr("href", "mailto:"+email);

	});

	return this;
};


$.fn.youtubeEmbed = function() {
	$(this).each(function(){

		var video = $(this).attr("href");

		video = video.split('=');



//console.log(video[1]);
http://www.youtube.com/watch?v=zH8K8mPtyXQ
//<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/zH8K8mPtyXQ&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/zH8K8mPtyXQ&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>

		var embed = '<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/zH8K8mPtyXQ&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+video[1]+'&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>';

//	console.log(embed);

	var player = jQuery(document.createElement('div'));
    player.attr('class', 'video_player');
    player.html(embed);
    $(player).insertAfter(this);
	$(this).remove();


	});

	return this;
};


$(window).unload( function () { 

	if(typeof GUnload == 'function') {
		GUnload();
	} 

});



function updateMap (geo, txt)
{

	if(!document.getElementById("map"))
		return false;


	if (GBrowserIsCompatible()) {

		var map = new GMap2(document.getElementById("map"));

		if(geo) {
			var tmp = geo.split(",");
			var map_lat = tmp[0];
			var map_long =  tmp[1];
		}
		else {
			var map_lat = 0;
			var map_long =  0;

			var first = $(".address:first").children("span.geo").text();
			$(".address:first").addClass('active');
			var txt = $(".address:first").children("span.bubble_txt").text();
			var tmp = first.split(",");
			var map_lat = tmp[0];
			var map_long =  tmp[1];


			//find first address
			//pull out geo


		}

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(map_lat, map_long), 14);

		// Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);

		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		var point = new GLatLng(map_lat,map_long);
		map.addOverlay(new GMarker(point, icon));

		if(txt) {
			map.openInfoWindow(map.getCenter(),
			document.createTextNode(txt));
		}

	}

}
