$(document).ready(function(){
	
	function vertAlign() {
		var img_height = $('a.sponsor_logo img').height();
		var frame_height = 240 - img_height;
		var margin = Math.round(frame_height / 2);
		$('a.sponsor_logo img').css('margin-top', margin);
	}
	vertAlign();
	
	function mainNav() {
		$('ul.main_nav_left li:not(ul.main_nav_left li ul li)').mouseover(function(){
			$(this).children("div.nav_menu").show();
			$('ul.main_nav_left li:not(ul.main_nav_left li ul li)').mouseleave(function(){
				$('div.nav_menu').hide();
			});
		});
	}
	mainNav();
	
	$('div.rotational').cycle({
		fx: 'fade'
	});

	$('div.sponsor_slides').cycle({
		fx: 'fade'
	});
	
    $('#newsletter-form input').labelify({
        text: 'label',
        labelledClass: 'labelled'
    });
    $('#newsletter-form label').hide();
	
	function animateClouds() {
		var vp_width = $(window).width();
		$('.clouds_1').css('background-position', '-509px 120px');
		$('.clouds_2').css('background-position', vp_width + 'px 170px');
		$('.clouds_3').css('background-position', '-709px 30px');
		$('div.clouds_1').animate({backgroundPosition: vp_width + 'px 120px'},40000, 'linear');
		$('div.clouds_2').animate({backgroundPosition: '-553px 170px'},50000, 'linear');
		$('div.clouds_3').animate({backgroundPosition: vp_width + 'px 30px'},60000, 'linear', function(){ animateClouds(); });
	}
	if (!$.browser.msie || ($.browser.msie && $.browser.version.substr(0,1)>7)) {
	  animateClouds();
	}
	
	$('#increase').click(function(evt){
		if ($('body').hasClass('font_decrease')) {
			$('body').removeClass('font_decrease');
		} else {
			$('body').addClass('font_increase');
		}
		evt.preventDefault();
	});
	$('#decrease').click(function(evt){
		if ($('body').hasClass('font_increase')) {
			$('body').removeClass('font_increase');
		} else {
			$('body').addClass('font_decrease');
		}
		evt.preventDefault();
	});
	
	// Volunteer forms
	$('a.toggle_terms_box').click(function(evt){
		$('div.terms_release').toggle();
		evt.preventDefault();
	});
	$('a.terms_close').click(function(evt){
		$('div.terms_release').hide();
		evt.preventDefault();
	});
	$('input#minor_yes').click(function(){
		$('div.terms_minor').show();
	});
	$('input#minor_no').click(function(){
		$('div.terms_minor').hide();
	});
	$('input#vol_submit').click(function(evt){
		if ($('input#terms_agree').attr('checked')) {
			if ($('input#minor_yes').attr('checked') || $('input#minor_no').attr('checked')) {
				if ($('input#minor_no').attr('checked')) {
					// Process form
				} else {
					if ($('input#guardian_yes').attr('checked') || $('input#guardian_no').attr('checked')) {
						if ($('input#guardian_yes').attr('checked')) {
							if ($('input#guardian_name').val() == '') {
								alert('You must specify a name for the parent or legal guardian of the minor.');
								evt.preventDefault();
							} else {
								// Process form
							}
						} else {
							alert('You must confirm that you are the parent or legal guardian of the minor to complete the application.');
							evt.preventDefault();
						}
					} else {
						alert('Please confirm that you are the parent or legal guardian of the minor.');
						evt.preventDefault();
					}
				}
			} else {
				alert('Please specify whether the Volunteer is a minor (under age 18) or not.');
				evt.preventDefault();
			}
		}  else {
			alert('Please indicate that you understand and agree to the Release and Consent terms.');
			evt.preventDefault();
		}
	});

});

$(window).load(function(){
	function vertAlign() {
		var old_display = $(this).parent().css('display');
        $(this).parent().css('display', 'block');
		var img_height = $(this).height();
        $(this).parent().css('display', old_display);
		var frame_height = 240 - img_height;
		var margin = Math.round(frame_height / 2);
		$(this).css('margin-top', margin);
	}
    $('a.sponsor_logo img').each(vertAlign);
});

