﻿//This is the Javascript for the Slide Shows
	$(document).ready(function() {

		//******Masthead Slide Show**********??
		//Show the paging and activate its first link
		$(".paging").show();
		$(".paging a:first").addClass("active");
		
		//Get size of the image, how many images there are, then determin the size of the image reel.
		var imageWidth = $(".window").width();
		var imageSum = $(".image_reel div").size();
		var imageReelWidth = imageWidth * imageSum;
		
		//Adjust the image reel to its new size
		$(".image_reel").css({'width' : imageReelWidth});

		//Paging  and Slider Function
		rotate = function(){
		    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
		
		    $(".paging a").removeClass('active'); //Remove all active class
		    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		    //Slider Animation
		    //$(".image_reel").animate({
		    //    left: -image_reelPosition
		    //}, 500 );
			$('.image_reel').fadeOut(500);
			$('.image_reel').animate({ left: -image_reelPosition }, 0 );
			$('.image_reel').fadeIn(500);		
		}; 
		
		//Rotation  and Timing Event
		rotateSwitch = function(){
		    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
		        $active = $('.paging a.active').next(); //Move to the next paging
		        if ( $active.length === 0) { //If paging reaches the end...
		            $active = $('.paging a:first'); //go back to first
		        }
		        rotate(); //Trigger the paging and slider function
		    }, 7000); //Timer speed in milliseconds (7 seconds)
		};
		
		rotateSwitch(); //Run function on launch

		//On Hover
		$(".image_reel a").hover(function() {
		    clearInterval(play); //Stop the rotation
		}, function() {
		    rotateSwitch(); //Resume rotation timer
		});	
		
		//On Click
		$(".paging a").click(function() {
		    $active = $(this); //Activate the clicked paging
		    //Reset Timer
		    clearInterval(play); //Stop the rotation
		    rotate(); //Trigger rotation immediately
		    rotateSwitch(); // Resume rotation timer
		    return false; //Prevent browser jump to link anchor
		});


		//***********Slide Show 1***********//
		//Show the paging and activate its first link
		$(".paging_1").show();
		$(".paging_1 a:first").addClass("active_1");
		
		//Get size of the image, how many images there are, then determin the size of the image reel.
		var imageWidth_1 = $(".window_1").width();
		var imageSum_1 = $(".image_reel_1 img").size();
		var imageReelWidth_1 = imageWidth_1 * imageSum_1;
		
		//Adjust the image reel to its new size
		$(".image_reel_1").css({'width' : imageReelWidth_1});

		//Paging  and Slider Function
		rotate_1 = function(){
		    var triggerID_1 = $active_1.attr("rel") - 1; //Get number of times to slide
		    var image_reelPosition_1 = triggerID_1 * imageWidth_1; //Determines the distance the image reel needs to slide
		
		    $(".paging_1 a").removeClass('active_1'); //Remove all active class
		    $active_1.addClass('active_1'); //Add active class (the $active is declared in the rotateSwitch function)
		
		    //Slider Animation
		    //$(".image_reel").animate({
		    //    left: -image_reelPosition
		    //}, 500 );
			$('.image_reel_1').fadeOut(500);
			$('.image_reel_1').animate({ left: -image_reelPosition_1 }, 0 );
			$('.image_reel_1').fadeIn(500);		
		}; 
		
		//Rotation  and Timing Event
		rotateSwitch_1 = function(){
		    play_1 = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
		        $active_1 = $('.paging_1 a.active_1').next(); //Move to the next paging
		        if ( $active_1.length === 0) { //If paging reaches the end...
		            $active_1 = $('.paging_1 a:first'); //go back to first
		        }
		        rotate_1(); //Trigger the paging and slider function
		    }, 7000); //Timer speed in milliseconds (7 seconds)
		};
		
		rotateSwitch_1(); //Run function on launch

		//On Hover
		$(".image_reel_1 a").hover(function() {
		    clearInterval(play_1); //Stop the rotation
		}, function() {
		    rotateSwitch_1(); //Resume rotation timer
		});	
		
		//On Click
		$(".paging_1 a").click(function() {
		    $active_1 = $(this); //Activate the clicked paging
		    //Reset Timer
		    clearInterval(play_1); //Stop the rotation
		    rotate_1(); //Trigger rotation immediately
		    rotateSwitch_1(); // Resume rotation timer
		    return false; //Prevent browser jump to link anchor
		});

		//***********Slide Show 2***********//
		//Show the paging and activate its first link
		$(".paging_2").show();
		$(".paging_2 a:first").addClass("active_2");
		
		//Get size of the image, how many images there are, then determin the size of the image reel.
		var imageWidth_2 = $(".window_2").width();
		var imageSum_2 = $(".image_reel_2 img").size();
		var imageReelWidth_2 = imageWidth_2 * imageSum_2;
		
		//Adjust the image reel to its new size
		$(".image_reel_2").css({'width' : imageReelWidth_2});

		//Paging  and Slider Function
		rotate_2 = function(){
		    var triggerID_2 = $active_2.attr("rel") - 1; //Get number of times to slide
		    var image_reelPosition_2 = triggerID_2 * imageWidth_2; //Determines the distance the image reel needs to slide
		
		    $(".paging_2 a").removeClass('active_2'); //Remove all active class
		    $active_2.addClass('active_2'); //Add active class (the $active is declared in the rotateSwitch function)
		
		    //Slider Animation
		    //$(".image_reel").animate({
		    //    left: -image_reelPosition
		    //}, 500 );
			$('.image_reel_2').fadeOut(500);
			$('.image_reel_2').animate({ left: -image_reelPosition_2 }, 0 );
			$('.image_reel_2').fadeIn(500);		
		}; 
		
		//Rotation  and Timing Event
		rotateSwitch_2 = function(){
		    play_2 = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
		        $active_2 = $('.paging_2 a.active_2').next(); //Move to the next paging
		        if ( $active_2.length === 0) { //If paging reaches the end...
		            $active_2 = $('.paging_2 a:first'); //go back to first
		        }
		        rotate_2(); //Trigger the paging and slider function
		    }, 7000); //Timer speed in milliseconds (7 seconds)
		};
		
		rotateSwitch_2(); //Run function on launch

		//On Hover
		$(".image_reel_2 a").hover(function() {
		    clearInterval(play_2); //Stop the rotation
		}, function() {
		    rotateSwitch_2(); //Resume rotation timer
		});	
		
		//On Click
		$(".paging_2 a").click(function() {
		    $active_2 = $(this); //Activate the clicked paging
		    //Reset Timer
		    clearInterval(play_2); //Stop the rotation
		    rotate_2(); //Trigger rotation immediately
		    rotateSwitch_2(); // Resume rotation timer
		    return false; //Prevent browser jump to link anchor
		});


	});

