var size_timer;
Event.observe(document, 'dom:loaded', function() {

	size_timer = setInterval('check_sizes()', 1);

	// event bar pop ups
	$$('#events-bar .event').each(function(x) {
		if (x.down('.info')) {
			x.onmouseover = function() { $(this).down('.info').show(); }
			x.onmouseout = function() { $(this).down('.info').hide(); }
		}
	});
	
	// dropdown navigation
	$$('ul#nav li').each(function(li) {
		li.onmouseover = function() { $(this).addClassName('selected'); }
		li.onmouseout = function() { $(this).removeClassName('selected'); }
	});
	
	// search field focus/blur
	$('search_text').onfocus = function() { if (this.value == 'search') this.value = ''; }
	$('search_text').onblur = function() { if (this.value == '') this.value = 'search'; }
	
	// email address field focus/blur
	$('email_address').onfocus = function() { if (this.value == 'your email address') this.value = ''; }
	$('email_address').onblur = function() { if (this.value == '') this.value = 'your email address'; }
	
	// check for elements that should display tooltips
	$$('.tooltip').each(function(x) {
		x.onmouseover = function() {
			tooltip_title = x.readAttribute('title');
			x.writeAttribute('title', '')
			$('tooltip-box').update(tooltip_title).show();
		}
		x.onmouseout = function() {
			$('tooltip-box').update('').hide();
			x.writeAttribute('title', tooltip_title);
			tooltip_title = '';
		}
	});
});

var tooltip_title = '';
Event.observe(document, 'mousemove', function(event) {
	if ($('tooltip-box').visible()) {		
		$('tooltip-box').setStyle({
			'top': Event.pointerY(event) - $('tooltip-box').getHeight() - 10 + 'px',
			'left': Event.pointerX(event) + 10 + 'px'
		}).show();
	}
});

function check_sizes() {
	if ($('full-bg')) {
		// determine the bigger gap between vertical/horizontal
		var vwidth = document.viewport.getWidth();
		var vheight = $('main').getHeight();
		
		var img_width = $('full-bg').getWidth();
		var img_height = $('full-bg').getHeight();
					
		var horizontal = vwidth - img_width;
		var vertical = vheight - img_height;
					
		if (horizontal >= vertical) {
			// resize horizontally
			//new_width = vwidth;
			//new_height = img_height * new_width / img_width;
			$('full-bg').setStyle({
				width: '100%',
				height: 'auto'
			}).show();
		} else {
			// resize vertically
			//new_height = vheight;
			//new_width = img_width * new_height / img_height;
			$('full-bg').setStyle({
				width: 'auto',
				height: '100%'
			}).show();
		}
		
		/*$('full-bg').setStyle({
			width: new_width + 'px',
			height: new_height + 'px'
		}).show();*/
	}
}
