$(function(){
	labels();
	text_replace();
	scroll_to();
	formalize();
	if ($("a[rel='colorbox']").length>0) $("a[rel='colorbox']").colorbox();
	$(window).load(function(){
		//initialize();
	});
});
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    map.setUIToDefault();
  }
}
function scroll_to() {
	
	$('#tm-contact a').click(function(){
		$(window).scrollTo($('#footer-main'), 800 );
		return false;
	});
}
function text_replace() {
	Cufon.replace($('h1,h2,h3,h4'));

}
function labels() {
	$('.label-input-pair:not([class~="legal"]) label').labelOver('over');	
}
function formalize() {
	$('#contact-form').submit(function(){
		$.post($(this).attr('action'),$(this).serialize(),function(data){
			if (data.complete==false) {
				$('#msg').removeClass('complete').html(data.msg).css('display','none').fadeIn('slow');
			} else {
				$('#msg').addClass('complete').html(data.msg).css('display','none').fadeIn('slow');
				$('#contact-form input[type="text"]').val('');
				$('#contact-form textarea').val('');
				$('#contact-form input[type="checkbox"]').each(function(){
					this.checked = 0;
				});
				$('#contact-form input[type="text"]').each(function(){
					this.focus();
					this.blur();
				});
				$('#contact-form textarea').each(function(){
					this.focus();
					this.blur();
				});
				$('#contact-form select').each(function(){
					this.selectedIndex = 0;
				});
			}
		},'json');
		return false;
	});
}

