// Weather Widget functions
var current_weather_zip;
function set_current_weather_zip(zip) {
	current_weather_zip = zip;
}

function show_weather_form() {
	$('#weather > .current').fadeOut('fast');
	$('#weather > .form').fadeIn('fast');
	weather_form_to_default();
}

function hide_weather_form() {
	$('#weather > .form').fadeOut('fast');
	$('#weather > .current').fadeIn('fast');
}

function weather_form_to_default() {
	var weather_zip = $('#weather #weather_zip').val();
	var default_weather_zip = 'Zip Code';
	if(weather_zip==current_weather_zip) {
		$('#weather #weather_zip').addClass('default');
	} else if(weather_zip=='' || weather_zip==default_weather_zip) {
		$('#weather #weather_zip').val(default_weather_zip).addClass('default');
	}
}

function weather_form_focus() {
	$('#weather #weather_zip').val('').removeClass('default');
}

$(document).ready(function() {
	//Drop Down Menu
	$('#head .menu li:has(.sub)').hover(function() {
		$('a:first', this).addClass('active');
		$('.sub', this).show();
	}, function() {
		$('a:first', this).removeClass('active');
		$('.sub', this).hide();
	});

	// Weather Widget
	$('#weather #change_zip').click(function() {
		show_weather_form();
	});

	$('#weather #cancel_zip').click(function() {
		hide_weather_form();
	});

	$('#weather #weather_zip').focus(function() {
		weather_form_focus();
	}).blur(function() {
		weather_form_to_default();
	});
	if(jQuery().datepicker) {
		$('.datepicker').datepicker({ dateFormat:'yy-mm-dd' });
	}
	
	//News Widget - autoscroll
	var latest_height = $('.newsitems').height();
	if(latest_height>180) {
		$('.articles').scrollable({ vertical:true, circular:true, easing:'linear' }).autoscroll({ autoplay:true, interval:4500 });
	}
	$('.more').click(function() {
		var id = $(this).attr('id').substring(5);
		$('#short-' + id).hide();
		$('#long-' + id).show();
	});
	$('.less').click(function() {
		var id = $(this).attr('id').substring(5);
		$('#short-' + id).show();
		$('#long-' + id).hide();
	});
	$('.viewer').click(function() {
		var jquery_this = $(this);
		var id = jquery_this.attr('id');
		$('.viewer').removeClass('active');
		if (id == 'all') {
			$('.newsitem:hidden', ".content").show();
		} else {
			$('.newsitem', ".content").hide().filter('.' + id).show();
		}
		jquery_this.addClass('active');
	});
});
