var current_featured_event = 0;
$(function(){
	$('.box_bottom .carousel_container a').click(function(){
		if(current_featured_event == parseInt($(this).attr('rel'))) return false;
		current_featured_event = parseInt($(this).attr('rel'));
		$('.featured_events_holder .item').stop();
		$('.featured_events_holder .item:visible').fadeOut('slow');
		$('.featured_events_holder .item:eq('+$(this).attr('rel')+')').fadeIn('slow', function(){$(this).fadeTo(1,1);});
		$('.box_bottom .itemselected').removeClass('itemselected').addClass('item');
		$(this).removeClass('item').addClass('itemselected');
		return false;
	});
});
var marker_primary;
var map_primary;
var geocoder_primary;

function initialize_map(point1, point2, address, city, title) {
	// Change title
	$("#show-map-box").dialog("option", "title", title);
	// We don't have lat/long but we have an address
	if (point1 == "")
	{
		var myOptions = {
				address: address
		};
		geocoder_primary = new google.maps.Geocoder;
		geocoder_primary.geocode(myOptions,
				function(results, status) {
					if (status == google.maps.GeocoderStatus.OK)
					{
						set_map_center(results[0].geometry.location.lat(), results[0].geometry.location.lng());
					}
					else
					{
						alert('Lookup failed : '+status);
					}
				}
		);	
	}
	else
	{
		set_map_center(point1, point2);
	}
}

function set_map_center(point1, point2)
{
	// We have a lat/long pair :D
	var latlng = new google.maps.LatLng(point1, point2);
    var myOptions = {
		zoom: 14,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    // Init map
    map_primary = new google.maps.Map(document.getElementById("mmaapp_holder"), myOptions);
    // Create the pin point marker
    marker_primary = new google.maps.Marker({
    	position: latlng, 
    	map: map_primary
  	});
    marker_primary.setMap(map_primary);
}
