$(function(){
	// map controls
	$('#imagery .vcard .pseudo-href .street-address, #imagery .map .close').click(function(){
		$('#imagery .map').toggle();
		$('#imagery').toggleClass('map-opened');
	});
	
	var calendar_href = $('.calendar-href'),
		calendar_border = calendar_href.find('b'),
		calendar_overlay = calendar_href.find('.overlay').css('visibility', 'visible'),
		calendar_offset,
		is_msie = $.browser.msie;
	
	
	function rememberPos() {
		calendar_offset = calendar_href.offset();
	}
		
	function followMouse(pos_x) {
		var x = pos_x - calendar_offset.left,
			w = calendar_border[0].offsetWidth;
		
		x = Math.min(calendar_overlay[0].offsetWidth, Math.max(3, x));
			
		calendar_border.css('left', x);
		x = calendar_border[0].offsetLeft;
		
		var clip = ['auto', (x + w) + 'px', 'auto', x + 'px'];
		
		calendar_overlay.css('clip', 'rect(' + clip.join(is_msie ? ' ' : ',') + ')');
	}
	
	calendar_href
		.mousemove(function(/* Event */ evt) {
			followMouse(evt.pageX);
		})
		.hover(rememberPos, function(){});
	
	if (calendar_href.length) {
		rememberPos();
		followMouse(50);
	}
});