Event.observe(window, 'load', function() {
	$$('a[href="#"]').each(function (element) {
		if (element.up().hasClassName('expander') || element.rel.length > 0)
			return;
		element.addClassName('notimplemented');
		element.observe('click', function(event) {
			alert('This functionality has not been implemented in the prototype. It will be part of the actual Central Version.');
			event.stop();
		});
	});
	
	$$('form:not([action])').each(function (form) {
		form.observe('submit', function(event) {
			alert('This functionality has not been implemented in the prototype. It will be part of the actual Central Version.');
			event.stop();
		});
	});
	
	$$('.expander a').each(function (element) {
		element.observe('click', function(event) {
			var expander = event.element().up();
			if (expander.hasClassName('collapsed')) {
				new Effect.BlindDown(expander.next(), {duration: 0.5});
				expander.removeClassName('collapsed');
			} else {
				new Effect.BlindUp(expander.next(), {duration: 0.5});
				expander.addClassName('collapsed');
			}
			
			event.stop();
		});
	});
	
	$$('a[rel="facebox"]').each(function (element) {
		Facebox.facebox(element);
	});

	if (Prototype.Browser.IE) {
		// Workaround for IE6 not supporting :hover on anything other than <a>
		var menuitems = $$('#main-nav > li:not([class~=search])');
		menuitems.each(function (element) {
			element.observe('mouseover', function(event) {
				menuitems.invoke('removeClassName', 'hover');
				element.addClassName('hover');
			});
			element.observe('mouseout', function(event) {
				element.removeClassName('hover');
			});
		});
	}
});

FocusObserver = Class.create({
	initialize: function(element, defaultValue) {
		this.element = $(element);
		this.defaultValue = defaultValue;
		
		Event.observe(this.element, 'blur', this.onBlurEvent.bind(this));
		Event.observe(this.element, 'focus', this.onFocusEvent.bind(this));
	},

	onBlurEvent: function() {
		if (this.element.getValue() == '')
			this.element.value = this.defaultValue;
	},

	onFocusEvent: function() {
		if (this.element.getValue() == this.defaultValue)
			this.element.clear();
		else
			this.element.activate();
	}
});

var Map = {
	initializeMap: function() {
		this.map = new GMap2($('map'));
		this.map.setCenter(new GLatLng(0,0));
		this.map.addControl(new GSmallMapControl());
		this.map.addControl(new GMapTypeControl());
		this.map.enableScrollWheelZoom();
		Event.observe($('map'), 'DOMMouseScroll', function(event) {
			event.stop();
		});
		
		this.baseIcon = new GIcon();
		this.baseIcon.image = "http://www.google.com/mapfiles/gadget/markerSmall80.png";
		this.baseIcon.shadow = "http://www.google.com/mapfiles/gadget/shadow50Small80.png";
		this.baseIcon.iconSize = new GSize(16, 27);
	  this.baseIcon.shadowSize = new GSize(30, 28);
	  this.baseIcon.iconAnchor = new GPoint(8, 27);
	  this.baseIcon.infoWindowAnchor = new GPoint(5, 1);

		this.letteredIcons = new Array();
	  for (var i = 0; i < 20; i++) {
	    var icon = new GIcon(this.baseIcon);
	    var iconImageKey =
	    icon.image = "http://www.google.com/mapfiles/gadget/letters/marker" +
	                      String.fromCharCode(65+i) + ".png";
	    this.letteredIcons[i] = icon;
	  }

		this.locations = new Array();
		this.bounds = new GLatLngBounds();
	},
	
	addLocation: function(loc) {
		loc= $H(loc);

		var marker = new GMarker(new GLatLng(loc.get('lat'), loc.get('lng')), {
			icon: this.letteredIcons[this.locations.size()],
			title: loc.get('title')
		});
		var job_id = 'job_' + this.locations.size();
		
		this.locations.push(marker);
		
		GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindow($('result_1'), {maxWidth: '400'});
			marker.originalImage = marker.getIcon().image;
			marker.setImage('/images/marker-highlight.png');
			$('job_1').addClassName('highlight');
		});
		GEvent.addListener(marker, 'mouseover', function() {
			marker.originalImage = marker.getIcon().image;
			marker.setImage('/images/marker-highlight.png');
		});
		GEvent.addListener(marker, 'mouseout', function() {
			marker.setImage(marker.originalImage);
		});
		
		// Update map
		this.map.addOverlay(marker);
		this.bounds.extend(marker.getPoint());
		this.map.setZoom(Math.min(10, this.map.getBoundsZoomLevel(this.bounds)));
		this.map.setCenter(this.bounds.getCenter());
	}
};