$(document).ready(function() {
    
	$("#evt_cal_box tr:even").not(".day_names").addClass("zebra");
	
	if(!$("#AnnualContrib").is(":checked")) {
		$("#AnnualContrib_Amount").hide();
	}
	$("#AnnualContrib").change(function() {
		if($(this).attr("checked")) {
			$("#AnnualContrib_Amount").show();
			$("#AnnualContrib").attr("checked", true);
		} else {
			$("#Annual_Contribution").val("");
			$("#AnnualContrib_Amount").hide();
			$("#AnnualContrib").attr("checked", false);
		}
	});
	
	$('table.utilities').hide();
	$('p.utilities a').toggle(function(){
		$('table.utilities').slideDown('slow');
		$(this).text('Hide Utilities List');
	}, function() {
		$('table.utilities').slideUp();
		$(this).text('See Utilities List');
	});
	$('div.incentives').hide();
	$('p.incentives a').toggle(function(){
		$('div.incentives').slideDown('slow');
		$(this).text('Hide Incentives List');
	}, function() {
		$('div.incentives').slideUp();
		$(this).text('See Incentives List');
	});
	
	$('#res_subnav').hide();
	$('#res').mouseenter( function(){
		$('#res_subnav').show();
	}, function() { });
	$('#res_subnav').mouseleave( function(){
		$('#res_subnav').hide();
	}, function() { });


	$("#search_tab").mouseenter(
			function() {
				$(this).parent().addClass("tert_search");
				$('#search_box').css('visibility', 'visible');
				$('#contact_info').hide();
			}, function() { } );
	$("#header .tertiary").mouseleave(
		function() {
			if( $(this).hasClass("tert_search") ) {
				$(this).removeClass("tert_search");
				$('#search_box').css('visibility', 'hidden');
				$('#contact_info').show();
			}
			$('#header .tertiary').focus();
		}
	);
	
	var clearMePrevious = "";
	$('.clearMeFocus').focus(function() { // clear input on focus
		if($(this).val()==$(this).attr('title')) {
			clearMePrevious = $(this).val();
			$(this).val("");
		}
	});
	$('.clearMeFocus').blur(function() { if($(this).val()=="") { $(this).val(clearMePrevious); } });
	
	theRotator();
	var intervalImg = setInterval('rotate()', 9000);
	var intervalTxt = setInterval('rotate_txt()', 9000);
	
	$('form#contact_form ul li div').hide();
	$('#contact_form ul li label span').click( function() {
		$(this).parent().next().slideToggle();
		$(this).text(($(this).text() == '(show details)') ? '(hide details)' : '(show details)');
	});
	
	$('#contact_form .error').hide();
	
	$('#rotating_ctrl').toggle(function() {
		clearInterval(intervalImg);
		clearInterval(intervalTxt);
		$(this).attr('src','/images/button_play.png');
	}, function() {
		intervalImg = setInterval('rotate()', 9000);
		intervalTxt = setInterval('rotate_txt()', 9000);
		rotate();
		rotate_txt();
		$(this).attr('src','/images/button_pause.png');
	});


	
});

function theRotator() {
	
	$('div#rotator ul li').css({opacity: 0.0}); //Set the opacity of all images to 0
	$('div#rotating_txt ul li').css({opacity: 0.0});
	$('div#rotator ul li:first').css({opacity: 1.0}); //Get the first image and display it
	$('div#rotating_txt ul li:first').css({opacity: 1.0});
	
}

function rotate() {	
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first')); //Get the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	//Get next image, when it reaches the end, rotate it back to the first image
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');
	
};
function rotate_txt() {	
	var current = ($('div#rotating_txt ul li.show')?  $('div#rotating_txt ul li.show') : $('div#rotating_txt ul li:first')); //Get the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotating_txt ul li:first') :current.next()) : $('div#rotating_txt ul li:first'));	//Get next image, when it reaches the end, rotate it back to the first image
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');
	
};
