// JavaScript Document

	$(document).ready(function(){
	
	$switchTime = 2750;
	$moveTime = 400;
	
	$distance = 160; // distance to move image AS WELL AS singular image width
	$hoverDistance = $distance; // keeps original distance when hover
	
	$imageLength = parseInt($('#moveItem').css('width')); // length of all the images together
	$direction ="-=";
	$position = 0;
	$secondLap = false;
	$containerViewWidth = 480;
	$end = $containerViewWidth - $imageLength;
	
	$visited = false;
	$left = 0;


		// TIMER FUNCTION THAT MAKES THE IMAGES MOVE
		$('#moveItem').everyTime($switchTime,function()
		{	
			
			$position = parseInt($('#moveItem').css('left'));	
			if($position <= ($end ))
			{
				$direction = "+=";
				$secondLap = true;
			}
			
			if($secondLap == true && $position == 0)
			{
				$direction = "-=";
			}
			
			$('#moveItem').animate({ left: $direction  + $distance + "px"}, $moveTime );
	
		});
		
		// SET MOVE DISTANCE TO ZERO WHEN HOVERING OVER IMAGES
		$('#moveItem').hover(
			function () 
			{
			  	$distance = 0;
			}, 
			function () {
			  	$distance = $hoverDistance;
			}
		  );
		
		
		// SHOW ALT TEXT AS IMAGE TITLE WHEN HOVERED OVERSS
		$('#moveItem img').hover(
			//ON HOVER OVER IMAGE
			function () 
			{ 
				// REMOVE ALL TITLES
				$('#moveItem').find("span#hoverTXT").remove();
				
				// ADD IN TITLE FOR HOVERED IMAGE
				$visited = false;
				$description = $(this).attr('alt');
				
				if ($(this).attr('class') == 'blue') {
					$classvar = 'class="blue"';
				} else {
					$classvar = '';
				}
				
				
				$pos = $(this).position();		
				
				$(this).after('<span id="hoverTXT" style="left:' + $pos.left + 'px"' + $classvar + '>' + $description + '</span>');
			}
		);	
		
		// WHEN LEAVING SCROLLER
		$('#moveItem').hover(
			function () {},
			function ()
			{
				// HIDE ALL TITLES
				$('#moveItem').find("span#hoverTXT").remove();
			}
		);	
		
		
	});
