////////////////////////////////////////////////////////////////////////////
// Button-Fade Plugin
////////////////////////////////////////////////////////////////////////////
(function($) {
	$.fn.btn = function(options) {
// Configuration
		settings = jQuery.extend({
			effect: 'fade',
			attack: 200,
			decay: 200
		}, options);

// Events
		if (settings.effect == 'fade') {
			$(this).hover(function() {
				$(this).children(':first').stop(true).fadeTo(settings.attack, 0);
			}, function() {
				$(this).children(':first').stop(true).fadeTo(settings.decay, 1);
				if (!$.support.opacity) { this.style.removeAttribute("filter", false); };
			});
		} else if (settings.effect == 'slide') {
			$(this).hover(function() {
				$(this).children(':last').stop(true).slideUp(settings.attack);
			}, function() {
				$(this).children(':last').stop(true).slideDown(settings.decay);
			});
		}

// Initialization
		$(this).each(function() {
			var bgHeight = $(this).innerHeight();
			var bgWidth = $(this).width();
			//var bgImage = $(this).css('background-image').replace(/"(.*)"/, "$1");
			var bgColor = $(this).css('background-color');
			var bgRepeat = $(this).css('background-repeat');

			$(this).css({
				'position': 'relative',
				'overflow': 'hidden'
			}).children(':first').css({
				'position': 'relative'
			}).clone().css({
				'height': bgHeight+'px',
				'width': bgWidth+'px',
				'padding': '0',
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-repeat': bgRepeat,
				//'background-image': bgImage,
				'background-color': bgColor
			}).not('img').text('').end().prependTo(this).next().css({
				'background-image': 'none',
				'background-color': 'transparent'
			});
		});
	}
})(jQuery);


////////////////////////////////////////////////////////////////////////////
// Page-Ready Stuff
////////////////////////////////////////////////////////////////////////////
$(function() {
	// Call the button-fade plugin
	$('#homepageAffinitiButton, #homepageNextactionButton').btn();

	pageName = $('h1').text();
	if (pageName=='Executive Team' || pageName=='Board of Directors') {
		$('#mainContent > div').not('#optouts').hide();
		$('#mainContent > a').wrap('<p></p>');
		$('div.subexpanding').hide();
		$('#mainContent > p, div.expanding > p').mousedown(function() {
			$(this).next().toggle();
		}).mouseup(function() {
			$(this).parent().parent().blur();
		}).click(function() {
			return false;
		});

		$('#OptOutForm,#contactForm').hide();
		$('#NAoptout,#hideContact,.gotoform').mousedown(function() {
			$('#OptOutForm,#contactForm').toggle();
		}).mouseup(function() {
			$(this).blur();
		}).click(function() {
			return false;
		});
	};

	if (pageName=='Privacy') {
		$('#OptOutForm').show().parent().hide();
		$('#NAoptout').mousedown(function() {
			$('#OptOutForm').parent().toggle();
		}).mouseup(function() {
			$(this).parent().parent().blur();
		}).click(function() {
			return false;
		});
		$('.subexpanding').hide();
		$('.expanding, .subexpanding').prev().mousedown(function() {
			$(this).next().toggle();
		}).mouseup(function() {
			$(this).parent().parent().blur();
		}).click(function() {
			return false;
		});
	}

	if (pageName=="Contact") {
		if ($('#error').text()=='') {
			$('#mainContent > #hideContact').next().hide();
	}
		$('#mainContent > #hideContact').mousedown(function() {
			$(this).next().toggle();
		}).mouseup(function() {
			$(this).parent().parent().blur();
		}).click(function() {
			return false;
		});
	};
	
	$('#awards .newsHeading').click(function() {
			$(this).next().toggle();
			return false;
		}).next().hide();
	$('#news_releases .newsHeading,#press_coverage .newsHeading').click(function() {
			$(this).next().toggle();
			return false;
		}).next().show();
		
	
});
