// TechKnow Slider v1.0

$(function() 
		   {
			   //we want to set up the slider to auto rotate
			   headline_interval = setInterval(rotateImages,5000); //time in milliseconds
   			   
			   //if we hover over one of the slides, we want to pause the animation
			   $('#TechKnow_Slider #slides')
			   .hover(function() 
						{
							clearInterval(headline_interval);
  						}, 
					function() 
						{
							headline_interval = setInterval(rotateImages,5000); //time in milliseconds
						});

		   		//if one of the mini-slides is clicked on, we want to go to the corresponding slide
				$("#TechKnow_Slider #controls ul li")
				.click(function()
						{
							var NextSlide = $("#TechKnow_Slider #controls ul li").index(this);
							goToSlide(NextSlide, 500);
						});
				
				//if we hover over one of the mini-slides, we want to show the pointer
				$("#TechKnow_Slider #controls ul li")
				.hover(function()
						{
							$("#TechKnow_Slider #controls ul li").css("cursor","pointer");
						},   
						function()
						{
							$("#TechKnow_Slider #controls ul li").css("cursor","auto");
						});
	
				//if we hover over the prev button, lets make it change so the user knows its clickable
				$("#TechKnow_Slider #controls div.prev")
				.hover(function()
						{
							$("#TechKnow_Slider #controls div.prev")
							.html('<img src="../images/slider_toolbar_prev_on.gif" width="18" height="25" />')
							.css("cursor","pointer");
						},   
						function()
						{
							$("#TechKnow_Slider #controls div.prev")
							.html('<img src="../images/slider_toolbar_prev.gif" width="18" height="25" />')
							.css("cursor","auto");
						});
	
				//if we hover over the next button, lets make it change so the user knows its clickable
				$("#TechKnow_Slider #controls div.next")
				.hover(function()
						{
							$("#TechKnow_Slider #controls div.next")
							.html('<img src="../images/slider_toolbar_next_on.gif" width="18" height="25" />')
							.css("cursor","pointer");
						},   
						function()
						{
							$("#TechKnow_Slider #controls div.next")
							.html('<img src="../images/slider_toolbar_next.gif" width="18" height="25" />')
							.css("cursor","auto");
						});
	
				//if prev is clicked on
				$("#TechKnow_Slider #controls div.prev")
				.click(function(){goToSlide("Prev", 500);});
				
				//if next is clicked on
				$("#TechKnow_Slider #controls div.next")
				.click(function(){goToSlide("Next", 500);});
		   
		   });


//this function changes to the next image in the set
function rotateImages()
{
	var oCurPhoto = $("#TechKnow_Slider #slides div.current");
	var oNextPhoto = oCurPhoto.next();
	var oCurSlide = $("#TechKnow_Slider #controls ul li.current");
	var oNextSlide = oCurSlide.next();
	
	if (oNextPhoto.length == 0)
	{
		oNextPhoto = $("#TechKnow_Slider #slides div:first");
	}
	
	if (oNextSlide.length == 0)
	{
		oNextSlide = $("#TechKnow_Slider #controls ul li:first");
	}
		
	oCurPhoto.removeClass('current').addClass('previous');
	oCurSlide.removeClass('current');
	
	oNextPhoto.css({opacity:0.0})
	.addClass('current')
	.animate({opacity:1.0}, 500, function() {oCurPhoto.removeClass('previous'); oNextSlide.addClass('current'); });
}

//This function responds to the controls 
function goToSlide(oNxtSlide, oAnimInterval)
{
	if (oNxtSlide == "Next")
	{
		var oCurPhoto = $("#TechKnow_Slider #slides div.current");
		var oNextPhoto = oCurPhoto.next();
		var oCurSlide = $("#TechKnow_Slider #controls ul li.current");
		var oNextSlide = oCurSlide.next();
		
		if (oNextPhoto.length == 0)
		{
			oNextPhoto = $("#TechKnow_Slider #slides div:first");
		}
		
		if (oNextSlide.length == 0)
		{
			oNextSlide = $("#TechKnow_Slider #controls ul li:first");
		}
	}
	else 
	{
		if (oNxtSlide == "Prev")
		{
			var oCurPhoto = $("#TechKnow_Slider #slides div.current");
			var oNextPhoto = oCurPhoto.prev();
			var oCurSlide = $("#TechKnow_Slider #controls ul li.current");
			var oNextSlide = oCurSlide.prev();
				
			if (oNextPhoto.length == 0)
			{
				oNextPhoto = $("#TechKnow_Slider #slides div:last");
			}
			
			if (oNextSlide.length == 0)
			{
				oNextSlide = $("#TechKnow_Slider #controls ul li:last");
			}
		}
			
		else
		{
			//get the next slide based on the index
			var oNextPhoto = $("#TechKnow_Slider #slides div").eq(oNxtSlide);
		
			//get the current slide
			var oCurPhoto = $("#TechKnow_Slider #slides div.current");
				
			//get the next slide based on the index
			var oNextSlide = $("#TechKnow_Slider #controls ul li").eq(oNxtSlide);
				
			//get the current slide
			var oCurSlide = $("#TechKnow_Slider #controls ul li.current");
		}
	}
		
	//remove the current class and change it to previous
	oCurPhoto.removeClass('current').addClass('previous');
	oCurSlide.removeClass('current');
	oNextSlide.addClass('current');
		
	//animate the next slide to become the current one and then remove previous class from the old photo
	oNextPhoto.css({opacity:0.0})
	.addClass('current')
	.animate({opacity:1.0}, oAnimInterval, function() {oCurPhoto.removeClass('previous');});
}