var map = null
var status = false;
var elh = 400;
var la = 0;
var lo = 0;
var what = "venue";

$(document).ready(function(){
	 $('div.v_detail').each(function(){
	 	var temp = $(this).attr('geo');
	 	var temp = temp.split(',');
	 	la = temp[0];
	 	lo = temp[1];
	 });
	 if($('div.rc').find('a').length > 0) {
	 	what = "event";
	 }
	if (GBrowserIsCompatible()) {
	$('div.view_map').prepend('<a href="#" id="maplink">View this '+what+' on a map</a>');
	if ($('div.view_map').height() != null || $('div.view_map').height() < 10) {
		$('div.view_map').css('height','475px');
	} else {
		$('div.view_map').css('height',$('div.view_map').height()+'px');
	}
	$('div.view_map').css('overflow','hidden');
	$('div.view_map').find('img').each(function(){
		$(this).wrap('<div id="map_image"></div>');
		if ($(this).height() != null && $(this).height() > 10) {
			elh = $(this).height();
		}
		//alert(elh);
	});
	$('#maplink').click(function(me){
		me.preventDefault();
		
		
		
		
		if (status) {
			$('div#map_panel').html('&nbsp;')
			map.hide();
			var t = setTimeout("cleanUp();",800);
			$('#map_image').slideDown();
			$('#maplink').html('View this '+what+' on a map');
			status = false;
		} else {

			$('#maplink').html('Hide map');
			cleanUp();
			$('div#map_panel').css('height',elh+'px');
			$('#map_image').before('<div id="map_panel" style="height:'+elh+'px;width:280px;"></div>');
			$('div#map_panel').wrap('<div id="map_holder" style="height:'+(elh-10)+'px;width:280px;background:#333333;margin:10px 0 10px 10px;"></div>');
			map = $($('div#map_holder'));
			map.hide();
			$('#map_image').slideUp();
			map.slideDown(function(){
				
					 var gmap = new GMap2(document.getElementById("map_panel"));
					 gmap.addControl(new GSmallMapControl());
     				 gmap.addControl(new GMapTypeControl());
					 
					 gmap.setCenter(new GLatLng(la,lo), 15);
					 var point = new GLatLng(la,lo);
					 var marker = new GMarker(point);
      				 gmap.addOverlay(marker);
					 
			
			
			});
			status = true;
		
		}
		
		return false;
	});
	}

});

function cleanUp() {
	if (map != null) {
		map.remove();
		map = null;
	}	
}