document.observe('dom:loaded', function () {
	if (typeof Vx === 'undefined') {
		var portraits = $$('div.office'),
			profiles = $$('div.address');
		
		profiles.invoke('hide');
		
		profiles.each(function (profile, i) {
			profile.setStyle({
				position: 'absolute',
				top: '160px',
				left: '130px'
			});
			
			if (i === 0) {
				profile.show();
			}
		});
		
		portraits.each(function (portrait, i) {
			var profile = profiles[i];
			portrait.insert({
				after: profile
			});
			portrait.observe('click', function (event) {
				profiles.invoke('hide');
				if (profiles.map(Element.visible).include(true)) {
					return event;
				} else {
					if (typeof profile !== 'undefined') { profile.show(); }
				}
			});
		});
	}
});

function highlightLinks(obj) {
   var linkList = document.getElementById("contact_offices").getElementsByTagName("a");
   for (i = 0; i < linkList.length; i++) {
      linkList[i].className = "";
   }
   obj.className = "selected";
};

(function () {
	var resetInput = function () {
		var element = (typeof $(this).hasClassName === 'function') ? $(this) : $(arguments[0]);
		if (!element.hasClassName('prefilled') && element.getValue() === element.defaultValue) {
			element.setValue('');
		}
		return element;
	};
	var clearForms = function () {
		var form_elements = $$('input[type=text]', 'textarea');
		form_elements.invoke('observe', 'focus', resetInput);
		form_elements.invoke('observe', 'blur', function () {
			if ($F(this).blank()) {
				this.setValue(this.defaultValue);
			}
		});
		$$('form').invoke('observe', 'submit', function () {
			this.select('input[type=text]', 'textarea').map(resetInput);
		});
	};

	document.observe('dom:loaded', clearForms);
})();

Element.addMethods({
	redraw: function (element) {
		element = $(element);
		element.down().setStyle({ marginTop: '1px' });
		
		return element;
	},
	
	hasScrollbar: function (element, direction) {
		element = $(element);
		var has_scrollbar = false;
		
		switch (direction) {
			case 'vertical':
				has_scrollbar = (element.clientWidth < element.offsetWidth);
				break;
			case 'horizontal':
				has_scrollbar = (element.clientHeight < element.offsetHeight);
				break;
			default:
				has_scrollbar = ((element.clientWidth < element.offsetWidth) || (element.clientHeight < element.offsetHeight));	
		}
		
		return has_scrollbar;
	}
});

document.observe('dom:loaded', function () {
	if ($('breadcrumb') && $('breadcrumb').down('ul')) {
		var breadcrumb = $('breadcrumb').down('ul');
		var document_title = (document.title).split(' | ').slice(1).join(' | ');
		var final_element = new Element('li', { className: 'last' }).update(document_title);
		
		breadcrumb.insert(final_element);
	}
	
	try {
		var location_sub = /([^\/]+?)\/([^\/]+?)\.asp$/;
		var folder_name, file_name, window_location;
		window.location.href.gsub(location_sub, function (match) {
			window_location = match[0];
			folder_name = match[1];
			file_name = match[2];
		});
	
	
		$$('#navigation a').each(function (element) {
			$(element).readAttribute('href').gsub(location_sub, function (match) {
				if (match[2] !== 'home') {
					if (match[0] === window_location) {
						element.addClassName('selected');
					}
			
					if (match[2] === folder_name) {
						element.addClassName('selected');
					}
				}
			});
		});
	
		$$('.submenu a').each(function (element) {
			$(element).readAttribute('href').gsub(location_sub, function (match) {
				if (match[0] === window_location) {
					element.addClassName('selected');
				}
			});
		});
	} catch (err) {}
	
	$$('.right_column').each(function (column) {
		// work out if the element currently has scrollbars
		var first_element = column.down();
		
		if ( column.hasScrollbar('vertical') ) {
			// if the element has scrollbars then replace them with javascript arrows
			column.setStyle('overflow:hidden'); // hide the overflow to remove the scrollbar
			
			// create the arrows and work out how far we can scroll in any direction
			var up_arrow = new Element('a', { href: '#up', id: 'up_arrow', className: 'scroll_arrow' }),
				down_arrow = new Element('a', { href: '#down', id: 'down_arrow', className: 'scroll_arrow' }),
				column_height = column.scrollHeight,
				max_height = column.offsetHeight,
				allowable_height = max_height - column_height,
				offset = parseInt(first_element.getStyle('margin-top'), 10) || 0;
			
			// insert the fader to make it look better (it’s a transparent PNG)
			column.insert('<div class="content_fader fader_bottom">');
			
			// observe the arrow keys and work out which direction we are scrolling
			$(up_arrow, down_arrow).each(function (arrow) {
				// insert the arrows into the page. they are already styles in the CSS
				column.insert({ after: arrow });
				
				arrow.observe('click', function (event) { event.stop(); });
				arrow.observe('mousedown', function (event) {
					var direction = -2;
					
					if (arrow.id === 'up_arrow') { direction = 2; }
					new PeriodicalExecuter(function (pe) {
						$w('mouseup mouseout').each(function (ev) {
							arrow.observe(ev, function () { pe.stop(); arrow.stopObserving(ev); });
						});
						
						// work out the new offset for the column scroll
						offset += direction;
						
						// if we are at a limit, stop scrolling
						if ((offset >= 0 && direction > 0) || (offset < allowable_height-22 && direction < 0)) {
							pe.stop(); arrow.stopObserving('mouseup'); arrow.stopObserving('mouseout');
							return;
						}
						
						// now style the first descendent of the column to move it up or down
						first_element.setStyle({ marginTop: (offset) + 'px' });
					}, 0.01);
				});
			});
			
			column.redraw(); // force a redraw of the column (especially for Safari)
			
			// fix the content fader for IE6 (it’s a transparent PNG)
			try { DD_belatedPNG.fix('.content_fader'); } catch (not_ie6) {}
		}
	});
	
	$$('.left_column').each(function (column) {
		// work out if the element currently has scrollbars
		var first_element = column.down();
		
		if ( column.hasScrollbar('vertical') ) {
			// if the element has scrollbars then replace them with javascript arrows
			column.setStyle('overflow:hidden'); // hide the overflow to remove the scrollbar
			
			// create the arrows and work out how far we can scroll in any direction
			var up_arrow = new Element('a', { href: '#up', id: 'up_arrow_left', className: 'scroll_arrow_left' }),
				down_arrow = new Element('a', { href: '#down', id: 'down_arrow_left', className: 'scroll_arrow_left' }),
				column_height = column.scrollHeight,
				max_height = column.offsetHeight,
				allowable_height = max_height - column_height,
				offset = parseInt(first_element.getStyle('margin-top'), 10) || 0;
			
			// insert the fader to make it look better (it’s a transparent PNG)
			column.insert('<div class="content_fader fader_bottom">');
			
			// observe the arrow keys and work out which direction we are scrolling
			$(up_arrow, down_arrow).each(function (arrow) {
				// insert the arrows into the page. they are already styles in the CSS
				column.insert({ after: arrow });
				
				arrow.observe('click', function (event) { event.stop(); });
				arrow.observe('mousedown', function (event) {
					var direction = -2;
					
					if (arrow.id === 'up_arrow_left') { direction = 2; }
					new PeriodicalExecuter(function (pe) {
						$w('mouseup mouseout').each(function (ev) {
							arrow.observe(ev, function () { pe.stop(); arrow.stopObserving(ev); });
						});
						
						// work out the new offset for the column scroll
						offset += direction;
						
						// if we are at a limit, stop scrolling
						if ((offset >= 0 && direction > 0) || (offset < allowable_height-22 && direction < 0)) {
							pe.stop(); arrow.stopObserving('mouseup'); arrow.stopObserving('mouseout');
							return;
						}
						
						// now style the first descendent of the column to move it up or down
						first_element.setStyle({ marginTop: (offset) + 'px' });
					}, 0.01);
				});
			});
			
			column.redraw(); // force a redraw of the column (especially for Safari)
			
			// fix the content fader for IE6 (it’s a transparent PNG)
			try { DD_belatedPNG.fix('.content_fader'); } catch (not_ie6) {}
		}
	});
	
	$$('.thumbnail_column').each(function (column) {
		// work out if the element currently has scrollbars
		if (typeof Vx === 'undefined' && column.hasScrollbar('horizontal')) {
			// remove the scrollbars
			column.setStyle('overflow:hidden');
			
			// create the back/next arrows
			var current_group = 0,
				next_arrow = new Element('a', { href: '#next', className: 'arrow next' }).update('Next'),
				back_arrow = new Element('a', { href: '#back', className: 'arrow back' }).update('Previous').hide();
			
			// split the content into groups of 4 elements
			var thumbnails = column.select('.person_thumbnail').eachSlice(4),
				wrappers = $A();
				
			thumbnails.each(function (group) {
				var wrapper = new Element('div', { className: 'thumbnail_wrapper' });
				column.insert(wrapper);
				group.each(function (el) {
					wrapper.insert(el);
				});
				
				wrappers.push(wrapper);
			});
			
			// sort the animation onclick
			$(next_arrow, back_arrow).invoke('observe', 'click', function (event) {
				event.stop();
				if (this === next_arrow) {
					current_group++;
				} else {
					current_group--;
				}
				next_arrow.show(); back_arrow.show();
				
				if (current_group === thumbnails.length - 1) { next_arrow.hide(); }
				if (current_group === 0) { back_arrow.hide(); }
				
				wrappers[0].morph({ marginLeft: (-current_group * 100) + '%' }, { duration: 0.6 });
			});
			
			// add the arrows and the nice faders to the element
			column.insert(next_arrow).insert(back_arrow).insert('<div class="fader left_fader"></div><div class="fader right_fader"></div>');
			
			// fix the content fader for IE6 (it’s a transparent PNG)
			try { DD_belatedPNG.fix('.thumbnail_column .fader'); } catch (not_ie6) {}
		}
	});
});

function popbc(URL) {
	var popup_width = 610
	var popup_height = 293
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'left=0,top=0,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+popup_width+',height='+popup_height+'');");
}