$(document).ready(function(){



	var options = {

		target:     '.details',

		url:        '/assets/snippets/email/email.php',

		success:    function() {

			$('#newsSignup fieldset').hide();

		}

	};

	$("#newsSignup").validate({

            submitHandler: function(form) {

                $(form).ajaxSubmit(options);

            },

			errorLabelContainer:'#error'

	});



	imageCarousel();

	inputClear('eNewsEmail', 'Type in your email address');

	//$('#semList').accordion();

});



function imageCarousel() {

	var currentAd = 0;

	

	function fadeBanner() {

		if (currentAd < $('#bannerNav a').length - 1) {

			currentAd++;

		} else {

			currentAd = 0;

		}

		goToBanner(currentAd);

	}

	

	function goToBanner(bannerNum) {

		$currentBanner = $('#banner div:visible').not('.bannerLeft div,.bannerRight div');

		$currentBanner.css('z-index', '1');

		

		$('#banner div').eq(bannerNum).css('z-index', '2').fadeIn('slow', function () {

			$currentBanner.fadeOut('fast');

		});

		$('#bannerNav li').removeClass('active').eq(bannerNum).addClass('active');

	}

	function animating(element) {

		if ( element.parent('li').hasClass('active') || $('#banner div:animated').length > 0 )

			return true;

		else

			return false

	}

	

	$('div.hide').removeClass('hide').hide();

	timeOut = setInterval(fadeBanner, 12000);

	

	$('#bannerNav a').click(function(event) {

		if ( !animating( $(this) ) ) {	

			clearTimeout(timeOut);

			currentAd = $('#bannerNav a').index($(this));

			goToBanner(currentAd);

			timeOut = setInterval(fadeBanner, 8000);

		}

		event.preventDefault();

	});

	

	$('#banner .bannerLeft').click(function(event) {

		if ( !animating( $(this) ) ) {	

			clearTimeout(timeOut);

			if ((currentAd-1) < 0) {

				currentAd = $('#bannerNav a').length - 1;

			} else {

				currentAd--;

			}

			goToBanner(currentAd);

			timeOut = setInterval(fadeBanner, 5000);

		}

		event.preventDefault();

	});

	$('#banner .bannerRight').click(function(event) {

		if ( !animating( $(this) ) ) {

			clearTimeout(timeOut);

			fadeBanner();

			timeOut = setInterval(fadeBanner, 5000);

		}

		event.preventDefault();

	});

}






