$(document).ready(function() {		
		/* Using custom settings */
		
		$("a#vidTakeATour").fancybox({
			'hideOnContentClick': false,
			'scrolling': 'no',
			'width': 575,
			'height': 360,
			'overlayOpacity': 0.7,
			'overlayColor': '#000000',
			'titleShow': false
		});
		
		$('#slideContainer .pane').biggerlink();
		
		runSlideShow();
		
		function runSlideShow() {
		
			// ---  Slide carousel  ---
			
			// Get the width of the outermost container div.
			var getWidth = $('#slideContainer').width();
			// Get the total number of slides
			var ct = $('#shifter').children().size();
			// Get slide thumbnail that is clicked
			// Set a slide "listener" variable
			var slideShowing = 1;
			// Gets the thumb that was clicked
			var imgClicked = $('#slideNav li');
			
			//Makes the first slide thumbnail class="active"
			$("#slideNav li:first-child").addClass("active");
			
			// Set a global variable to keep track of how far
			// the "shifter" should be moved.
			var setWidth = 0;
			
			//Timer active / not active
			var active = true;
			
			
			// Subtract the pane width from the amount by which
			// the "shifter" has already been moved.
			// Don't forget to give back the changed setWidth variable!
			$('#slideNav .slideArrowNext').click(function(){
				$(this).blur();												//Fixes firefox bug when user hits enter to zoom
				var activeDot = $("#slideNav li.active");				//locates <li.active> in the slide navigator and assigns it to variable
				slideShowing = $('#slideNav li').index(activeDot) + 1;	//This gets the <li.active> index and adds '1' to it. This will restore the slide # when exiting from zoom
				getWidth = $('#slideContainer').width();
				setWidth = - (slideShowing - 1) * getWidth;
				if (slideShowing < ct) {
					var activeDot = $("#slideNav li.active");
					setWidth = setWidth - getWidth; 
					slideShowing = slideShowing + 1;
					$("#slideNav li").removeClass("active"); // removes "active" class from thumb <li>
					$("#slideNav ul").find(":nth-child(" + slideShowing + ")").addClass("active");// adds "active" class to thumb <li>
					$('#shifter').animate({left: setWidth}, 500);
					//alert(setWidth);
					return false;
				}
				// Goes to the first slide if the first slide is selected and "Next" button is clicked
				else if (slideShowing >= ct) {
					setWidth = 0;
					slideShowing = 1;
					$("#slideNav li").removeClass("active"); // removes "active" class from thumb <li>
					$("#slideNav ul").find(":nth-child(" + slideShowing + ")").addClass("active");// adds "active" class to thumb <li>
					$('#shifter').animate({left: setWidth}, 500);
					return false;
				}
		
			});
				
				$('.slideArrowNextHidden').click(function(){
					$(this).blur();												//Fixes firefox bug when user hits enter to zoom
					var activeDot = $("#slideNav li.active");				//locates <li.active> in the slide navigator and assigns it to variable
					slideShowing = $('#slideNav li').index(activeDot) + 1;	//This gets the <li.active> index and adds '1' to it. This will restore the slide # when exiting from zoom
					getWidth = $('#slideContainer').width();
					setWidth = - (slideShowing - 1) * getWidth;
					if (slideShowing < ct) {
						var activeDot = $("#slideNav li.active");
						setWidth = setWidth - getWidth; 
						slideShowing = slideShowing + 1;
						$("#slideNav li").removeClass("active"); // removes "active" class from thumb <li>
						$("#slideNav ul").find(":nth-child(" + slideShowing + ")").addClass("active");// adds "active" class to thumb <li>
						$('#shifter').animate({left: setWidth}, 1000);
						//alert(setWidth);
						return false;
					}
					// Goes to the first slide if the first slide is selected and "Next" button is clicked
					else if (slideShowing >= ct) {
						setWidth = 0;
						slideShowing = 1;
						$("#slideNav li").removeClass("active"); // removes "active" class from thumb <li>
						$("#slideNav ul").find(":nth-child(" + slideShowing + ")").addClass("active");// adds "active" class to thumb <li>
						$('#shifter').animate({left: setWidth}, 1000);
						return false;
					}
			
				});
							
			// Same thing in reverse.
			$('.slideArrowPrev').click(function(){
				var activeDot = $("#slideNav li.active");				//locates <li.active> in the slide navigator and assigns it to variable
				slideShowing = $('#slideNav li').index(activeDot) + 1;	//This gets the <li.active> index and adds '1' to it. This will restore the slide # when exiting from zoom
				getWidth = $('#slideContainer').width();
				setWidth = - (slideShowing - 1) * getWidth;
				if (slideShowing > 1) {
					setWidth = setWidth + getWidth;
					slideShowing = slideShowing - 1;
					$("#slideNav li").removeClass("active"); // removes "active" class from thumb <li>
					$("#slideNav ul").find(":nth-child(" + slideShowing + ")").addClass("active");// adds "active" class to thumb <li>
					$('#shifter').animate({left: setWidth}, 500);
					return false;
				}
				// Goes to the last slide if the first slide is selected and "previous" button is clicked
				else if (slideShowing <= 1) {
					setWidth = getWidth * -1 * ct + getWidth;
					slideShowing = ct;
					$("#slideNav li").removeClass("active"); // removes "active" class from thumb <li>
					$("#slideNav ul").find(":nth-child(" + slideShowing + ")").addClass("active");// adds "active" class to thumb <li>
					$('#shifter').animate({left: setWidth}, 500);
					return false;
				}
			});

			// Gets the list item (dot) that was clicked and shifts the slides to the exact spot	
			$('#slideNav li').click(function(){
				$(this).siblings("li").removeClass("active");
				$(this).addClass("active");
				slideClicked = imgClicked.index(this);
				slideShowing = slideClicked + 1
				setWidth = 0 - slideClicked * getWidth;
				$('#shifter').animate({left: setWidth}, 500);	
			});
			
			// Timer Functions
			$('#slideContainer .slideArrowNext').click(function(){
				active = false;
				$(document).stopTime();
			});
			$('#slideContainer .slideArrowPrev').click(function(){
				active = false;
				$(document).stopTime();
			});
			$('#slideContainer #slideNav li').click(function(){
				active = false;
				$(document).stopTime();
			});
			$('#slideContainer').click(function(){
				active = false;
				$(document).stopTime();
			});
						
			$(document).everyTime(7000, 'controlled', function() {
				if (active === true) {	
					$('#slideNav .slideArrowNextHidden').click();
				}
			});
						
		}	
	
	});
