
$(document).ready(function() {

	/*-------- global vars --------*/

	/*-------- global functions --------*/
	function setWxUnits(type) {
		$.cookie('wxunits', type);
	}
	function getWxUnits() {
		return $.cookie('wxunits');
	}
	function swapWxUnits() {
		var units = getWxUnits();
		if (units == 'met') {
			setWxUnits('eng');
		}
		else {
			setWxUnits('met');
		}
		showWxUnits();
	}
	function showWxUnits() {
		var units = getWxUnits();
		if (units == 'met') {
			$('.u-eng').hide();
			$('.u-met').show();
			$('.u-switcher span').text('Switch to english units');
		}
		else {
			$('.u-eng').show();
			$('.u-met').hide();
			$('.u-switcher span').text('Switch to metric units');
		}
	}
	

	/*-------- global processes --------*/
	// banner click handling
	$('#top .banner').css({cursor:'pointer'});
	$('#top .banner').click(function(){
		document.location = SITE_ROOT;
	});
	
	// top loc search
	$('#nav-locsearch :text').focus(function(e){
		$(this).val('');
	});
	
	// handle user units
	$('.u-eng').hide();
	$('.u-met').hide();
	$('.u-switcher').click(function(){
		swapWxUnits();
	});
	showWxUnits();
	
	// page title data switchers
	if ($('h1 span.data-switcher')) {
		$('h1 span.data-switcher > a').click(function(e){
			if ($(this).attr('id').match(/data-(\w+)-switcher/) ) {
				var ref = $(this).attr('id').replace(/data-(\w+)-switcher/, "$1");

				$('#content div.switchable-data-wrapper').hide();				
				$('#data-' + ref).show();

	 		 	$('h1 span.data-switcher > a').removeClass('sel');
				$(this).addClass('sel');
			}

	 		return false;
		});
	}
	
	// flowplayer support
	if ($("a.simonvid").is('*')) flowplayer("a.simonvid", "/includes/flowplayer/flowplayer.commercial-3.1.0.swf", { clip: { autoPlay: false }, key: FPKEY });
	

});