// JavaScript Document

$(function() {
	$("#nav_num1").css({'background-image' : 'url(includes/images/circle.png)', 'background-repeat' : 'no-repeat'});
	totalPanels			= $(".scrollContainer").children().size();
		
	regWidth			= $(".panel").css("width");
	regImgWidth			= $(".panel img").css("width");
	regTitleSize		= $(".panel h2").css("font-size");
	regParSize			= $(".panel p").css("font-size");
	
	movingDistance	    = 133;
	
	curWidth			= 165;
	
	curImgWidth			= 155;    
	curTitleSize		= "12px"; 
	curParSize			= "11px"; 

	$panels				= $('#slider .scrollContainer > div');
	$container			= $('#slider .scrollContainer');

	$panels.css({'float' : 'left','position' : 'relative'});
    
	$("#slider").data("currentlyMoving", false);

	$container
		.css('width', ($panels[0].offsetWidth * $panels.length) + 50 )
		.css('left', "-10px"); /* for middle image */


	var scroll = $('#slider .scroll').css('overflow', 'hidden');

	function returnToNormal(element) {
		$(element)
			.animate({ marginTop: "20px", width: regWidth })
			.find("img")
			.animate({ width: regImgWidth })
		    .end()
			.find("h2")
			.animate({ fontSize: regTitleSize })
			.end()
			.find("p")
			.animate({ fontSize: regParSize });
	};
	
	function growBigger(element) {
		/* var temp=(parseInt($(element).css("height"))-100)*.3; */
		
		var moveUp=Math.ceil((100-$(element).find("img").height())*.5)+10;
		/* if image didn't load just set moveup to 0? */
		if(moveUp>45) { moveUp=0; }
		moveUp=moveUp+"px";
		
		$(element)
			
			.animate({ marginTop: moveUp, width: curWidth })
			.find("img")
			.animate({ width: curImgWidth })
			
		    .end()
			.find("h2")
			.animate({ fontSize: curTitleSize })
			.end()
			.find("p")
			.animate({ fontSize: curParSize });
		
	}
	
	//direction true = right, false = left
	function change(direction) {
	   
	    //if not at the first or last panel
		if((direction && !(curPanel < totalPanels)) || (!direction && (curPanel <= 1))) { return false; }	
        
		if(direction && (curPanel)%5==0)
		{
	  		$('.navinside').each(function() {
    			$(this).css({'background-image' : 'none'});
  			});
			var temp=Math.ceil((curPanel)/5)+1;
	  		$("#nav_num"+temp).css({'background-image' : 'url(includes/images/circle.png)', 'background-repeat' : 'no-repeat' });
		}
		else if(!direction && curPanel%5==1)
		{
	  		$('.navinside').each(function() {
    			$(this).css({'background-image' : "none"});
  			});
			var temp=Math.floor((curPanel)/5);
	  		$("#nav_num"+temp).css({'background-image' : 'url(includes/images/circle.png)', 'background-repeat' : 'no-repeat'});
		}
		
        //if not currently moving
        if (($("#slider").data("currentlyMoving") == false)) {
            
			$("#slider").data("currentlyMoving", true);
			
			var next         = direction ? curPanel + 1 : curPanel - 1;
			var leftValue    = $(".scrollContainer").css("left");
			var movement	 = direction ? parseFloat(leftValue, 10) - movingDistance : parseFloat(leftValue, 10) + movingDistance;
		
			$(".scrollContainer")
				.stop()
				.animate({
					"left": movement
				}, function() {
					$("#slider").data("currentlyMoving", false);
				});
			
			returnToNormal("#panel_"+curPanel);
			growBigger("#panel_"+next);
			
			curPanel = next;
			
			//remove all previous bound functions
			$("#panel_"+(curPanel+1)).unbind();	
			
			//go forward
			$("#panel_"+(curPanel+1)).click(function(){ change(true); });
			
            //remove all previous bound functions															
			$("#panel_"+(curPanel-1)).unbind();
			
			//go back
			$("#panel_"+(curPanel-1)).click(function(){ change(false); }); 
			
			//remove all previous bound functions
			$("#panel_"+curPanel).unbind();
		}
	}
	
	// Set up "Current" panel and next and prev
	growBigger("#panel_3");	
	curPanel = 3;
	
	$("#panel_"+(curPanel+1)).click(function(){ change(true); });
	$("#panel_"+(curPanel-1)).click(function(){ change(false); });
	
	//when the left/right arrows are clicked
	$(".right").click(function(){ change(true); return false; });	
	$(".left").click(function(){ change(false); return false; });
	



    


	$(window).keydown(function(event){
	  switch (event.keyCode) {
			case 13: //enter
				$(".right").click();
				break;
			case 32: //space
				$(".right").click();
				break;
	    case 37: //left arrow
				$(".left").click();
				break;
			case 39: //right arrow
				$(".right").click();
				break;
	  }
	  
	});
	
});

function go(num)
{
	  //if not currently moving
	  $('.navinside').each(function() {
    		$(this).css({'background-image' : "none"});
  		});

	  $("#nav_num"+num).css({'background-image' : 'url(includes/images/circle.png)', 'background-repeat' : 'no-repeat'});
	  
	  if (($("#slider").data("currentlyMoving") == false)) {
		  
		  $("#slider").data("currentlyMoving", true);
		  
		  var next         =  num*5-2;
		  var leftValue    = $(".scrollContainer").css("left");
		  var movement	 = -(num-1)*(133*5)-10;
	  
		  $(".scrollContainer")
			  .stop()
			  .animate({
				  "left": movement
			  }, function() {
				  $("#slider").data("currentlyMoving", false);
			  });
		  
		  function returnToNormal(element) {
		
		$(element)
			.animate({ marginTop: "20px",width: regWidth })
			.find("img")
			.animate({ width: regImgWidth })
		    .end()
			.find("h2")
			.animate({ fontSize: regTitleSize })
			.end()
			.find("p")
			.animate({ fontSize: regParSize });
		
	};
	
	function growBigger(element) {
		if($(element).css('margin-top')=='20px')
		{
		var moveUp=Math.ceil((100-$(element).find("img").height())*.5)+10;
		if(moveUp>45) { moveUp=0; }
		moveUp=moveUp+"px";
		
		$(element)
			
			.animate({ marginTop: moveUp, width: curWidth })
			.find("img")
			
			.animate({ width: curImgWidth })
		    .end()
			.find("h2")
			.animate({ fontSize: curTitleSize })
			.end()
			.find("p")
			.animate({ fontSize: curParSize });
		}
	}
 
	  }
	  if(curPanel != next)
	  {
	 returnToNormal("#panel_"+curPanel);
	 growBigger("#panel_"+next);
	  }
	  curPanel = next;
		  
		  //remove all previous bound functions
		  $("#panel_"+(curPanel+1)).unbind();	
		  
		  //go forward
		  $("#panel_"+(curPanel+1)).click(function(){ change(true); });
		  
		  //remove all previous bound functions															
		  $("#panel_"+(curPanel-1)).unbind();
		  
		  //go back
		  $("#panel_"+(curPanel-1)).click(function(){ change(false); }); 
		  
		  //remove all previous bound functions
		  $("#panel_"+curPanel).unbind();
		  return false;
}

<!-- stuff for 2nd slider -->
$(function() {
	
	totalPanels2			= $(".scrollContainer2").children().size();
		
	regWidth2			= $(".panel2").css("width");
	regImgWidth2			= $(".panel2 img").css("width");
	regTitleSize2		= $(".panel2 h2").css("font-size");
	regParSize2			= $(".panel2 p").css("font-size");
	
	movingDistance2	    = 133;
	
	curWidth2			= 165;
	
	curImgWidth2		= 155;    
	curTitleSize2		= "12px"; 
	curParSize2			= "11px"; 

	$panels2				= $('#slider2 .scrollContainer2 > div');
	$container2			= $('#slider2 .scrollContainer2');

	$panels2.css({'float' : 'left','position' : 'relative'});
    
	$("#slider2").data("currentlyMoving2", false);

	$container2
		.css('width', ($panels2[0].offsetWidth * $panels2.length) + 50 )
		.css('left', "-10px"); /* for middle image */


	var scroll = $('#slider2 .scroll2').css('overflow', 'hidden');

	function returnToNormal2(element) {
		$(element)
			.animate({ marginTop: "20px", width: regWidth2 })
			.find("img")
			.animate({ width: regImgWidth2 })
		    .end()
			.find("h2")
			.animate({ fontSize: regTitleSize2 })
			.end()
			.find("p")
			.animate({ fontSize: regParSize2 });
	};
	
	function growBigger2(element) {
		/* var temp=(parseInt($(element).css("height"))-100)*.3; */
		
		var moveUp2=Math.ceil((100-$(element).find("img").height())*.5)+10;
		/* if image didn't load just set moveup to 0? */
		if(moveUp2>45) { moveUp2=0; }
		moveUp2=moveUp2+"px";
		
		$(element)
			
			.animate({ marginTop: moveUp2, width: curWidth2 })
			.find("img")
			.animate({ width: curImgWidth2 })
			
		    .end()
			.find("h2")
			.animate({ fontSize: curTitleSize2 })
			.end()
			.find("p")
			.animate({ fontSize: curParSize2 });
		
	}
	
	//direction true = right, false = left
	function change2(direction2) {
	   
	    //if not at the first or last panel
		if((direction2 && !(curPanel2 < totalPanels2)) || (!direction2 && (curPanel2 <= 1))) { return false; }	
        
        //if not currently moving
        if (($("#slider2").data("currentlyMoving2") == false)) {
            
			$("#slider2").data("currentlyMoving2", true);
			
			var next2         = direction2 ? curPanel2 + 1 : curPanel2 - 1;
			var leftValue2    = $(".scrollContainer2").css("left");
			var movement2	 = direction2 ? parseFloat(leftValue2, 10) - movingDistance2 : parseFloat(leftValue2, 10) + movingDistance2;
		
			$(".scrollContainer2")
				.stop()
				.animate({
					"left": movement2
				}, function() {
					$("#slider2").data("currentlyMoving2", false);
				});
			
			returnToNormal2("#panel2_"+curPanel2);
			growBigger2("#panel2_"+next2);
			
			curPanel2 = next2;
			
			//remove all previous bound functions
			$("#panel2_"+(curPanel2+1)).unbind();	
			
			//go forward
			$("#panel2_"+(curPanel2+1)).click(function(){ change(true); });
			
            //remove all previous bound functions															
			$("#panel2_"+(curPanel2-1)).unbind();
			
			//go back
			$("#panel2_"+(curPanel2-1)).click(function(){ change2(false); }); 
			
			//remove all previous bound functions
			$("#panel2_"+curPanel2).unbind();
		}
	}
	
	// Set up "Current" panel and next and prev
	growBigger2("#panel2_3");	
	curPanel2 = 3;
	
	$("#panel2_"+(curPanel2+1)).click(function(){ change2(true); });
	$("#panel2_"+(curPanel2-1)).click(function(){ change2(false); });
	
	//when the left/right arrows are clicked
	$(".right2").click(function(){ change2(true); return false; });	
	$(".left2").click(function(){ change2(false); return false; });
	
	
});
