
$(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 --------*/

	// top loc search
	$('#header :text').focus(function(e){
		$(this).val('');
	});
	$('a#locsearch-submit').click(function(e){
		$('form#locsearch').submit();

		return false;
	});

    // nav search box
    $('#vnav :text').focus(function(e){
		$(this).val('');
	});

	// handle user units

	$('.u-eng').hide();
	$('.u-met').hide();
	$('.u-switcher').click(function(){
		swapWxUnits();
	});
	showWxUnits();



	// add local forecast clicks
	$('ul.gennav > li > a').click(function(e){
		var ref = $(this).attr('id').replace(/(\w+)-link/, "$1");


		if ($(this).attr('id').match(/(\w+)-link/) ) {
			var ref = $(this).attr('id').replace(/(\w+)-link/, "$1");
			var refType = $(this).attr('id').replace(/^(\w+)-.+$/, "$1");

			$('.gen-' + refType).hide();
			$('#' + ref + '-img').show();
			$('#' + ref).show(500);


 		 	$('ul.gennav > li > a').removeClass('sel');
			$(this).addClass('sel');

		}


 		return false;
 	});





});