var animationTime = 10000;

function progressBarAnimate(valProgress) {
	switch (valProgress) {
		case 'play':
			$('#top_progress_bar').animate({
				'width' : '0px'
			}, animationTime, 'linear');
			$('#bottom_progress_bar').animate({
				'width' : '0px'
			}, animationTime, 'linear');
			break;
		case 'stop':
			$('#top_progress_bar').stop();
			$('#bottom_progress_bar').stop();
			$('#top_progress_bar').animate({
				'width' : '0px'
			}, 0);
			$('#bottom_progress_bar').animate({
				'width' : '0px'
			}, 0);
			break;
		case 'reset':
			$('#top_progress_bar').animate({
				'width' : '100px'
			}, 0);
			$('#bottom_progress_bar').animate({
				'width' : '100px'
			}, 0);
			break;
	}
}

function timer_fa(valTimer) {
	if (valTimer != false) {
		
		HideContent('top_play');
		HideContent('bottom_play');
		
		progressBarAnimate('reset');
		progressBarAnimate('play');
		
		$(document).everyTime(animationTime,function() {
			varCurrentSection++;
			if (varCurrentSection > 3) {
				varCurrentSection = 1;
			}
			progressBarAnimate('reset');
			progressBarAnimate('play');
			show_featuredAuthors(varCurrentSection);
		});
		
		timerActive = true;
		
	} else {
		$(document).stopTime();
		progressBarAnimate('stop');
	}
}

function hideEverything() {
	
	// reset opacity to 0
	document.getElementById('featured_author_bethanderson').style.opacity = '0';
	document.getElementById('featured_author_carrieandtheresa').style.opacity = '0';
	document.getElementById('featured_author_christopherdrummond').style.opacity = '0';
	document.getElementById('featured_author_curtisludlow').style.opacity = '0';
	document.getElementById('featured_author_dawnanddenise').style.opacity = '0';
	document.getElementById('featured_author_gabrielleandpaul').style.opacity = '0';
	document.getElementById('featured_author_jillsolomon').style.opacity = '0';
	document.getElementById('featured_author_karlmiller').style.opacity = '0';
	document.getElementById('featured_author_lorimcnally').style.opacity = '0';
	document.getElementById('featured_author_phuongle').style.opacity = '0';
	document.getElementById('featured_author_christieressel').style.opacity = '0';
	document.getElementById('featured_author_staceyvernon').style.opacity = '0';
	document.getElementById('featured_author_stephaniechurma').style.opacity = '0';
	document.getElementById('featured_author_austinanderson').style.opacity = '0';
	
	// featured author divs
	HideContent('featured_author_bethanderson');
	HideContent('featured_author_carrieandtheresa');
	HideContent('featured_author_christopherdrummond');
	HideContent('featured_author_curtisludlow');
	HideContent('featured_author_dawnanddenise');
	HideContent('featured_author_gabrielleandpaul');
	HideContent('featured_author_jillsolomon');
	HideContent('featured_author_karlmiller');
	HideContent('featured_author_lorimcnally');
	HideContent('featured_author_phuongle');
	HideContent('featured_author_christieressel');
	HideContent('featured_author_staceyvernon');
	HideContent('featured_author_stephaniechurma');
	HideContent('featured_author_austinanderson');
	
	// featured author navigation
	// top
	HideContent('fa_nav_previous_top');
	HideContent('fa_nav_next_top');
	HideContent('fa_nav_1_top');
	HideContent('fa_nav_2_top');
	HideContent('fa_nav_3_top');
	HideContent('fa_nav_1_off_top');
	HideContent('fa_nav_2_off_top');
	HideContent('fa_nav_3_off_top');
	// bottom
	HideContent('fa_nav_previous_bottom');
	HideContent('fa_nav_next_bottom');
	HideContent('fa_nav_1_bottom');
	HideContent('fa_nav_2_bottom');
	HideContent('fa_nav_3_bottom');
	HideContent('fa_nav_1_off_bottom');
	HideContent('fa_nav_2_off_bottom');
	HideContent('fa_nav_3_off_bottom');
}

function show_featuredAuthors(varSectionNum) {
	
	// reset by hiding everything
	hideEverything();
	
	switch (varSectionNum) {
		case 1:
			// set the current section
			varCurrentSection = 1;
			// featured authors
			ShowContent('featured_author_bethanderson');
			ShowContent('featured_author_carrieandtheresa');
			ShowContent('featured_author_christopherdrummond');
			ShowContent('featured_author_curtisludlow');
			ShowContent('featured_author_dawnanddenise');
			// navigation
			// top
			ShowContent('fa_nav_1_off_top');
			ShowContent('fa_nav_2_top');
			ShowContent('fa_nav_3_top');
			ShowContent('fa_nav_next_top');
			// bottom
			ShowContent('fa_nav_1_off_bottom');
			ShowContent('fa_nav_2_bottom');
			ShowContent('fa_nav_3_bottom');
			ShowContent('fa_nav_next_bottom');
			// animated fadeIn
			$("#featured_author_bethanderson").animateToClass("fadeIn", 1500); // 5
			$("#featured_author_carrieandtheresa").animateToClass("fadeIn", 500); // 1
			$("#featured_author_christopherdrummond").animateToClass("fadeIn", 1000); // 3
			$("#featured_author_curtisludlow").animateToClass("fadeIn", 1250); // 4
			$("#featured_author_dawnanddenise").animateToClass("fadeIn", 750); // 2
			return(false);
		case 2:
			// set the current section
			varCurrentSection = 2;
			// featured authors
			ShowContent('featured_author_gabrielleandpaul');
			ShowContent('featured_author_jillsolomon');
			ShowContent('featured_author_karlmiller');
			ShowContent('featured_author_lorimcnally');
			ShowContent('featured_author_phuongle');
			// navigation
			// top
			ShowContent('fa_nav_previous_top');
			ShowContent('fa_nav_1_top');
			ShowContent('fa_nav_2_off_top');
			ShowContent('fa_nav_3_top');
			ShowContent('fa_nav_next_top');
			// bottom
			ShowContent('fa_nav_previous_bottom');
			ShowContent('fa_nav_1_bottom');
			ShowContent('fa_nav_2_off_bottom');
			ShowContent('fa_nav_3_bottom');
			ShowContent('fa_nav_next_bottom');
			// animated fadeIn
			$("#featured_author_gabrielleandpaul").animateToClass("fadeIn", 500); // 1
			$("#featured_author_jillsolomon").animateToClass("fadeIn", 1000); // 3
			$("#featured_author_karlmiller").animateToClass("fadeIn", 750); // 2
			$("#featured_author_lorimcnally").animateToClass("fadeIn", 1250); // 4
			$("#featured_author_phuongle").animateToClass("fadeIn", 1500); // 5
			return(false);
		case 3:
			// set the current section
			varCurrentSection = 3;
			// featured authors
			ShowContent('featured_author_christieressel');
			ShowContent('featured_author_staceyvernon');
			ShowContent('featured_author_stephaniechurma');
			ShowContent('featured_author_austinanderson');
			// navigation
			// top
			ShowContent('fa_nav_previous_top');
			ShowContent('fa_nav_1_top');
			ShowContent('fa_nav_2_top');
			ShowContent('fa_nav_3_off_top');
			// bottom
			ShowContent('fa_nav_previous_bottom');
			ShowContent('fa_nav_1_bottom');
			ShowContent('fa_nav_2_bottom');
			ShowContent('fa_nav_3_off_bottom');
			// animated fadeIn
			$("#featured_author_christieressel").animateToClass("fadeIn", 750); // 2
			$("#featured_author_staceyvernon").animateToClass("fadeIn", 1000); // 3
			$("#featured_author_stephaniechurma").animateToClass("fadeIn", 500); // 1
			$("#featured_author_austinanderson").animateToClass("fadeIn", 1250); // 1
			return(false);
		case 'next':
			nav_next(varCurrentSection);
			return(false);
		case 'previous':
			nav_previous(varCurrentSection);
			return(false);
		/*default:
			alert('ERROR!!! show_featuredAuthors = ' + varSectionNum);
			return(false);*/
			
	}
}

function nav_next(varNext) {
	varNext++;
	varCurrentSection = varNext;
	show_featuredAuthors(varNext);
}
function nav_previous(varPrevious) {
	varPrevious--;
	varCurrentSection = varPrevious;
	show_featuredAuthors(varPrevious);
}


$(document).ready(function(){
	
	//jQuery.easing.def = "linear";
	$.localScroll();
	
	if (document.getElementById('email_subscribed')) {
		$('#email_subscribed').fadeIn('slow').fadeOut('slow').remove();
	}
	
	/* - HOME PAGE ONLY - */
	
	if (document.title == 'Chic Galleria') {
		
		// post fade animation to show all authors
		varCurrentSection = 2; // start at the next featured authors section, because the page loads with the first
		timer_fa(true);
		
		// shows default first 5 featured authors
		show_featuredAuthors(1);
		
		$("#fa_nav_1_top a, #fa_nav_1_bottom a, #fa_nav_2_top a, #fa_nav_2_bottom a, #fa_nav_3_top a, #fa_nav_3_bottom a, #fa_nav_previous_top a, #fa_nav_previous_bottom a, #fa_nav_next_top a, #fa_nav_next_bottom a").click(function() {
			if (timerActive == true) {
				// stop the progress bar
				HideContent('top_stop');
				HideContent('bottom_stop');
				ShowContent('top_play');
				ShowContent('bottom_play');
				timer_fa(false);
				timerActive = false;
				// alert('wtf');
			}
			switch (this.innerHTML) {
				case '1':
					varCurrentSection = 1;
					show_featuredAuthors(varCurrentSection);
					$(document).stopTime();
					return(false);
				case '2':
					varCurrentSection = 2;
					show_featuredAuthors(varCurrentSection);
					document.location = '#featured_authors';
					$(document).stopTime();
					return(false);
				case '3':
					varCurrentSection = 3;
					show_featuredAuthors(varCurrentSection);
					document.location = '#featured_authors';
					$(document).stopTime();
					return(false);
				case 'next':
					getCurrentSection = this.innerHTML;
					show_featuredAuthors(getCurrentSection);
					document.location = '#featured_authors';
					$(document).stopTime();
					return(false);
				case 'previous':
					getCurrentSection = this.innerHTML;
					show_featuredAuthors(getCurrentSection);
					document.location = '#featured_authors';
					$(document).stopTime();
					return(false);
			}
		});
		
		$('#top_stop a, #bottom_stop a').click(function() {
			ReverseContent('top_stop');
			ReverseContent('bottom_stop');
			ReverseContent('top_play');
			ReverseContent('bottom_play');
			timer_fa(false);
		});
		$('#top_play a, #bottom_play a').click(function() {
			ReverseContent('top_stop');
			ReverseContent('bottom_stop');
			ReverseContent('top_play');
			ReverseContent('bottom_play');
			timer_fa(true);
		});
		
	}
	
});
