/**
* @file: slider.js
* @author: Justin Foley
* @dateModified: 10/27/2010
* -------------------------------
* This is the javascript file that holds all the code
* that makes the front-page slideshow work
*/
		
		$slideImage = 1; // Setting the default image (we're using index of 1 instead of 0)
		$top = 50; // Setting default top position for the slide-arrow
		$left = 515;
		var topArray = new Array(0,-250,176,251,326,401,476,142); // Setting our array for the different top positions for the arrow. If another image is added to the slide, add 75 to the second-to-last value in the array and stick it right before the last value
		var leftArray = new Array(0,515,515,515,515,515,515,120);		
		/**
		* This function simply starts the slideshow
		*/
		function SetSlideShow($action)
		{
			$(".slide-arrow").hide();
			
			$('.slideshow').cycle({
				fx: 'scrollRight', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				speed: 1000, // Sets how long it takes for the transition to finish (in milliseconds)
				before: onBefore, // Setting up our function to execute as soon as the next slide starts transitioning in
				timeout: 5500, // How long the image shows before it transitions to the next image
				pause: $action // Not a damn thing
			});
		}
		
		
		
		
		
		$(document).ready(function() { // When the page is loaded
			
			SetSlideShow(0); // Run the slideshow - if you pass it 1 instead of 0 then it will pause whenever the image is moused-over
			
			//Event handler for buttons - performs an image-swap for a hover-effect
			$("#btn-ac").mouseover(function()
			{				
				$(this).attr("src","images/buttons/btn_ac_over.jpg");	
				
			}).mouseout(function()
			{
				$(this).attr("src","images/buttons/btn_ac.jpg");				
			});
			
			$("#btn-structured").mouseover(function()
			{
				$(this).attr("src","images/buttons/btn_structured_over.jpg");	
			}).mouseout(function()
			{
				$(this).attr("src","images/buttons/btn_structured.jpg");
			});
			
			$("#btn-ip").mouseover(function()
			{
				$(this).attr("src","images/buttons/btn_ip_over.jpg");
			}).mouseout(function()
			{
				$(this).attr("src","images/buttons/btn_ip.jpg");
			});
			
			$("#btn-nicet").mouseover(function()
			{
				$(this).attr("src","images/buttons/btn_nicet_over.jpg");
			}).mouseout(function()
			{
				$(this).attr("src","images/buttons/btn_nicet.jpg");
			});
			
			$("#btn-osha").mouseover(function()
			{
				$(this).attr("src","images/buttons/btn_osha_over.jpg");	
			}).mouseout(function()
			{
				$(this).attr("src","images/buttons/btn_osha.jpg");
			});
			
			//---------------------------------------------------------
			
			/*
			* Setting up our image-swapping for the nav-item mouse-overs
			* and handling which page to show whenever an item is moused-over
			*/
			
			$(".slide-nav").find("li").each(function()
			{
				$(this).mouseover(function()
				{
					$(this).find("img").each(function()
					{
						$(this).attr("src","images/slide-unselected");
					});
					$(this).find("img").each(function()
					{
						$(this).attr("src","images/slide-selected.png");
					});
				}).mouseout(function()
				{
					$(this).find("img").each(function()
					{
						$(this).attr("src","images/slide-unselected.png");
					});
					var curSlide = $(".slide-nav").find("img")[$slideImage-2];
					$(curSlide).attr("src","images/slide-selected.png");
				});
			});
		});
		
		
		function SwapArrow($left)
		{
			if($left)
				$image = "images/arrow-left.png";
			else
				$image = "images/arrow.png";
			
			$(".slide-arrow").find("img").each(function()
			{
				$(this).attr("src", $image);
			});
		}
		
		/*
		* This function executes as soon as the slideshow begins transitioning
		* It handles the arrow position and picks the correct nav-item to select
		*/
		
		function onBefore()
		{
			switch($slideImage) // Determine which image it's on (index of 1)
			{
				// Assigning the '$top' variable to the corresponding topArray value
				// to determine where the arrow should be located
				case 1:
					$top = topArray[1];
					$left = leftArray[1];
					SwapArrow(false);
					break;
				case 2:
					$top = topArray[2];
					$left = leftArray[2];
					SwapArrow(false);
					$(".slide-arrow").show();
					break;
				case 3:
					$top = topArray[3];
					$left = leftArray[3];
					SwapArrow(false);
					$(".slide-arrow").show();
					break;
				case 4:
					$top = topArray[4];
					$left = leftArray[4];
					SwapArrow(false);
					$(".slide-arrow").show();
					break;
				case 5:
					$top = topArray[5];
					$left = leftArray[5];
					$(".slide-arrow").show();
					break;
				case 6:
					$top = topArray[6];
					$left = leftArray[6];
					SwapArrow(false);
					$(".slide-arrow").show();
					break;
				case 7:
					SwapArrow(true);
					$(".slide-arrow").show();
					$top = topArray[7];
					$left = leftArray[7];
					break;
				default:
					$top = topArray[1];
					$left = leftArray[1];
					$slideImage = 1;
					break;					
			}
				$counter = 1; // The counter for our .each() loop (index of 1)
				$(".slide-nav").find("li").each(function()
				{
					if($counter == $slideImage)
					{
						$(this).find("img").each(function()
						{
							$(this).attr("src","images/slide-selected.png");
						});
						
						// Begin image-swapping for slideshow navigator
						
						if($slideImage > 1)
						{
							var curLi = $(".slide-nav").find("li")[$slideImage-2];
							
							$(curLi).find("img").each(function()
							{
								$(this).attr("src","images/slide-unselected.png");		
							});
						}
						else
						{
							var curLi = $(".slide-nav").find("li")[6];
							
							$(curLi).find("img").each(function()
							{
								$(this).attr("src","images/slide-unselected.png");
							});
						}
					}
					$counter++
				});
			
				$slideImage++;
				
			$(".slide-arrow").animate(
			{
				"top" : $top,
				"left" : $left
			},1000);
		}
		
		/**
		* This function is called by the 'onmouseover' event handler for
		* the slide-nav list items (navigation for the slideshow)
		*/
		
		function SlideMouseOver($val)
		{			
			$(".slideshow").cycle('pause');
			if($val == 7)
				SwapArrow(true);
			else
				SwapArrow(false);
			$(".slide-arrow").show();
			$(".slideshow").find("img").each(function()
			{
				$(this).css({"display" : "none"});
			});
			
			var curSlideImage = $(".slideshow").find("img")[$val-1];
			$(curSlideImage).css({"display" : "block", "left" : "0px"});
			$(".slide-arrow").animate(
			{
				"top" : topArray[$val],
				"left" : leftArray[$val]
			},0);
		}
		
		function SlideMouseOut($val)
		{
			$(".slideshow").cycle('resume');	
		}
