var onNum = '1';
var rotateInterval = 10000;
var rotateFadeOut = 400;
var rotateFadeIn = 1850;
var rotate = window.setInterval(clickNextClass,rotateInterval);

function fadeAboutIt(event) {
		if($(event.target).is('.1') && onNum != '1'){
			$('.box img').fadeOut(rotateFadeOut);
			$('#img1,#img2,#img3').fadeIn(rotateFadeIn);
			onNum = '1';
			}
		if($(event.target).is('.2') && onNum != '2'){
			$('.box img').fadeOut(rotateFadeOut);
			$('#img4,#img5,#img6').fadeIn(rotateFadeIn);
			onNum = '2';
			}
		if($(event.target).is('.3') && onNum != '3'){
			$('.box img').fadeOut(rotateFadeOut);
			$('#img7,#img8,#img9').fadeIn(rotateFadeIn);
			onNum = '3';
			}
		$('.circlenav span').children().removeClass('active');
		$(event.target).addClass('active');
	}

function resumeRotate(){
		rotate = window.setInterval(clickNextClass,rotateInterval);
		}

function clickNextClass(){
	$('.1').parent().parent().parent().hover(
			function(){
				window.clearInterval(rotate);}
		,
			resumeRotate
		);
		if(onNum == '1'){
			$('.2').click();
			}
		else if(onNum == '2'){
			$('.3').click();
			}
		else if(onNum == '3'){
			$('.1').click();
			}
	}
$(document).ready(function() {
	$('.circlenav span a.1').addClass('active');
	$('.circlenav span a').click(fadeAboutIt);
});

var validate_send = false;
$(document).ready(
	function(){
		$('.hide').hide();
		$('.show').show();
		$('#wl_user_options .wl_option').hide();
		$('#wl_user_options ul li').click(
			function(){
				$('#wl_user_options ul li').removeClass('wl_selected');
				var current_class = $(this).attr('class');
					$('.wl_option').hide();
					$('#' + current_class).show();
				$(this).addClass('wl_selected');
				}
			);
		$('.wl_email_user').click();
		$('.wl_print_list').click(
			function(event){
				event.preventDefault();
				window.open(
						'../wp-content/plugins/wishlist/print.php'
						,
						'welcome'
						,
						'width=800,height=600,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes'
					);
				}
			);
		$('input[name = wl_email_admin]').click(
			function(event){
				var current_target = event.target;
				if( validate_send ){ validate_send = false; }
				else{
					event.preventDefault(); 
					$.post(
						'http://' + location.host + '/wp-content/plugins/wishlist/wl_validate.php'
						,
						$('#wl_email_admin_form').serialize()
						,
						function(data){
							$('.wl_user_alert').remove();
							$('.hide').hide();
							if( data == 'invalid' ){
								$('#wl_email_admin').append('<span class="wl_user_alert">Please enter a name and valid email address.</span>');
								}
							if( data == 'valid' ){
								validate_send = true;
								$('input[name = wl_email_admin]').click();
								}
							return false;
							}
						);
					}
				}
			);
		}
	);