function loadMap(lat, lon) {
  if (GBrowserIsCompatible() && $('gmap')) {
    var map = new GMap2(document.getElementById("gmap"));
    var point = new GLatLng(lat, lon);
    map.setCenter(point, 15);
    map.addControl(new GSmallMapControl());
    map.setMapType(G_HYBRID_MAP);
    var marker = new GMarker(point);
    map.addOverlay(marker);
    Event.observe(window, 'unload', GUnload);
  }
}

var ContactForm = {
  contactOpen: false,
  openForm: function() {
    new Effect.BlindDown('form', {duration: 0.8});
    this.contactOpen = true;
  },
  closeForm: function() {
    new Effect.BlindUp('form', {duration: 0.5});
    this.contactOpen = false;
  },
  toggle: function(link) {
    if (this.contactOpen) {
      Element.removeClassName(link, 'active');
      this.closeForm();
    } else {
      Element.addClassName(link, 'active');  
      this.openForm();
    }
  }
}

var Properties = {
  activeLink: null,
  swapIntro: function(to) {
    var from = this.activeLink;
    if (to != from) {
      new Effect.Parallel([
        new Effect.Fade(from.id + '-intro'),
        new Effect.Appear(to.id + '-intro')
      ], { duration: 0.5 } );
      from.removeClassName('active');
      to.addClassName('active');
      $('main').removeClassName(from.id);
      $('main').addClassName(to.id);    
      this.activeLink = to;
    }
  }
}

function init() {
  // Home page
  if ($('properties')) {
    Properties.activeLink = $$('#properties li a.active').first();
    $('main').addClassName(Properties.activeLink.id);
    var property_links = $$('#properties li a');
    property_links.each(function(link) {
      link.onmouseover = function() {
        Properties.swapIntro(this);
        return false;
      };
    });
  }
  
  // Properties page
  var contact_link = $$('ul#sidebar li a.contact').first();
  if (contact_link) {
    contact_link.onclick = function() {
      ContactForm.toggle(this);
      return false;
    }
    var contact_cancel = $$('ul#sidebar li a.contact-cancel').first();
    contact_cancel.onclick = function() {
      ContactForm.toggle(contact_link);
      return false;
    }
    var inputs = $$('ul#sidebar li div#form input');
    inputs.each(function(input) {
      input.onfocus = function() {
        if (!this.originalValue) this.originalValue = this.value;
        if (this.value == this.originalValue) {
          this.value = '';
          Element.addClassName(this, 'active');
        }
      }
      input.onblur = function() {
        if (this.value == '') {
          this.value = this.originalValue;
          Element.removeClassName(this, 'active');
        }
      }
    })
  }
}

Event.observe(window, 'load', init);