var map, contactFormRequest;
function init() {
	var mapCenter = new google.maps.LatLng(38.9031444, -77.0321841);
	map = new google.maps.Map(document.getElementById('map'), {
		'zoom': 15,
		'center': mapCenter,
		'mapTypeId': google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
 		mapTypeControl: true,
  		scaleControl: true
	});
	
	var marker = new google.maps.Marker({
		map: map,
		position: new google.maps.LatLng(38.9031444, -77.0321841),
		draggable: false,
		title: ''
	});
}

window.addEvent('domready', function() {
	if ( document.id('contact_form_button') )
	{
		//login request
		contactFormRequest = new Request({
			url: '/contact/form',
			link: 'cancel',
			method:'post',
			onRequest: function()
			{
				document.id('shadow_content_inner').set('html', '<img src="/images/css/ajax_loader.gif" alt="" />');
				openShadow();
				
				//track form load
				if ( undefined !== window.pageTracker ) 
				{pageTracker._trackPageview('/contact/form');}
			},
			onSuccess: function(response)
			{
				//alert(loginRequest.data);
				document.id('shadow_content_inner').set('html', response);
				setupContactForm();
			},
			onFailure: function(xhr)
			{
				alert('An error occurred: ' + xhr);	
			}
		});
		
		//setup contact button
		document.id('contact_form_button').addEvent('click', function(e) {
			e.preventDefault();
			contactFormRequest.send();
		});
		
		if ( document.id('map') )
		{	
			google.maps.event.addDomListener(window, 'load', init);
		}
	}
});

//setup contact form
function setupContactForm()
{
	var contactForm = document.id('contact_form').getFirst('form');
	Cufon.refresh();
	contactForm.set('send', {
		onSuccess: function(response)
		{
			var json = JSON.decode(response);
			if (json.success)
			{
				//alert(json.reason);
				//closeShadow();
				window.location = '/contact/thanks';
			}
			else
			{alert(json.reason);}
		},
		onFailure: function(xhr)
		{
			alert('An error occurred: ' + xhr);	
		}
	});
	
	contactForm.addEvent('submit', function(e)
	{
		e.preventDefault();
		contactForm.send();
	});
}
