/* Author: RIESTER

*/

$(document).ready(function() { 

	//navigation flyouts
	$("ul.menu").superfish();

	if($('#featureSlider').length) {
		featureSlider();
	}// end if

	if($('#bottomSlider').length) {
		bottomSlider();
	}// end if

	//Home page Tabs
	if($('#tabInfo').length) {
		//hide all but first tab info section
		$('#tabInfo ul li:first').siblings().hide();

		//click tab and you get the corresponding info
		$('#tabs li').bind('click', function(){
			var index = $(this).index();

			$('#tabInfo ul li').hide();
			$('#tabs li').removeClass('active');

			$('#tabInfo ul li').eq(index).show();
			$('#tabs li').eq(index).addClass('active');

			return false;
		}); // end tabs bind
	} //end if
	
	// FAQ expander
	if ($('#faqList').length) {
		$('#faqList div.answer').hide();
		
		$('#faqList a.question').live('click', function() {
			if ($(this).next('div.answer').hasClass('shown')) {
				return;
			} else {	
				$('#faqList div.answer.shown').removeClass('shown').slideToggle();
				$(this).next('div.answer').addClass('shown').slideToggle();
			}
			
			return false;
		}); // end listener
	}// end if


	$('input#s').focus(function() {
		if(this.value == 'Search Hearst Castle...') { 
			this.value = '';
		}
	});
	
	$('input#s').blur(function() {
		if(this.value == '') { 
			this.value = 'Search Hearst Castle...';
		}
	});



}); //end doc ready

function featureSlider() {

	//vars
	var slideTime = 6000,
	index = 0,
	speed = 500,
	features = $('ul#featureImages').find('li'),
	pause = false,
	totalSlides = features.length;


	function rotate() {
		
		// Stop, if user has interacted. 
		if (pause) {
			return;
		}
		
		//check to see if it is at the end
		if (index === totalSlides) { 
			index = 0;
		}
		features.eq(index).fadeIn(speed);

		//action for slider
		function pauseCheck() {
			if (pause) {
				return;
			} else {
				features.eq(index++).fadeOut(speed, rotate);
			} //end if
		} // end sliderAction

		setTimeout(pauseCheck, slideTime);
	}// end rotate

	// Add click listeners for controls. 
	$('#sliderControls a').click(function() {

		// Show target, hide other <li>. 
		$($(this).attr('href')).show().siblings('li').hide();

		// Add class="current" and remove from all others. 
		$(this).addClass('current').parent('li').siblings('li').find('a').removeClass('current');

		// Pause animation. 
		pause = true;

		// Nofollow. 
		return false;
	});
	
	// Add click listeners for controls. 
	$('#featureImages a').click(function() {
		if ($('body').is('.home')) {
			// Nofollow. 
			return false;
		}; //if
	});

		rotate();

}// end featureSlider


function bottomSlider() { 

	var totalSize = $('#bottomSlider').width,
	counter = 0 ;
	
	$('.arrowLeft').addClass('arrowLeftDone');
	
	$('.arrowRight').bind('click', function() {
		if (counter !== $('#rotator').children().length - 4) {
			$('#rotator').children().stop(true, true).animate({
				left: '-=210px'
				}, 500, function(){
			});
			$('.arrowLeft').removeClass('arrowLeftDone');
			$(this).removeClass('arrowRightDone');
		} else {
			$(this).addClass('arrowRightDone');
			return false;
		}
		counter++;
		return false;
	});
	
	$('.arrowLeft').click(function() {
		if (counter !== 0) {
			$('#rotator').children().animate({left: '+=210px'}, 500, function(){});
			$('.arrowRight').removeClass('arrowRightDone');
			$(this).removeClass('arrowLeftDone');
		} else { 
			$(this).addClass('arrowLeftDone');
			return false;
		}
		
		counter--;
		return false;
	});
	
} // end bottomSlider

      







