
var j = jQuery.noConflict();
j(document).ready(function($){
	
	// Clickable Logo
    $().clickableLogo('National Association of Corporate Directors','http://www.nacdnj.org');

    // Rotating Header Banner
    $('#slideshow')
		.addClass('imageRotation')
		.after('<div id="slideshow-caption"></div>')
		.cycle({
			fx: 'fade',
			random: 0,
			timeout: 6000,
			before: function(){
				$('#slideshow-caption').fadeTo(250, 0.01);
			},
			after: function(){
				if ($('img', this).attr('alt') != ''){
					$('#slideshow-caption').html($('img', this).attr('alt')).fadeTo(100,1);
				}
			}
		});
	
	
	// Board of Directors Page
	if ($('#board').length){
		$('#board div').hide();	
		$('#board a').click(function(){
			if ($('span', this).html() == '+'){
				$('span', this).html('-');
			} else {
				$('span', this).html('+');
			}
			$(this).parent().next('div').slideToggle();
			return false;
		});
	}
	
	
	// Email Address Input Field
	$('#email_form input[type=text]').addClass('email')
	var emailText = $('.email').val();
	$('.email').live('focus', function(){
		if ($(this).val() == emailText){
			$(this).attr('value','');
		}
	}).live('blur', function(){
		if ($(this).val() == ''){
			$(this).attr('value',emailText);
		}
	});
	
	
	// Ajax Email Form Submission
	$('#email_form input[type=submit]').click(function(){
		
		// Form Validation
		$('.error').hide();
		var email = $('#email_form input[type=text]').val();
		var sendto = $('#email_form input[type=hidden]').val();
		if (email == '' || email.indexOf('@') < 1) {
			$('.error').fadeIn();
			return false;
		}
	
		// Submit Form
		var dataString = 'email=' + email + '&sendto=' + sendto;
		$.ajax({  
			type: 'POST',  
			url: $('#email_form form').attr('action'),  
			data: dataString,  
			success: function(data) {
				$('#email_form form').hide();
				$('.success').html(data).fadeIn();
			},
			error: function(data) {
				$('.error').html('There was a problem saving your email address. Please try again later.').fadeIn();
			}  
		});  
	
		return false;
		
	});
   
});

