$(document).ready(function(){
	
	var ParentDiv3;
	var childDiv3;
	var childDiv3Height;
	var scrollTop3;
	var isScrolling = false;
	
	if($('body').attr('id') == 'bios'){
		childDiv3 = $("#team-member-bio-1 .scroll-content");
		childDiv3Height = $("#about-box-3 .scroll-content").height();
	}
	else{
		childDiv3 = $("#project-list-desc-1 .scroll-content");
		childDiv3Height = $("#project-list-box-3 .scroll-content").height();
	}
	
		
	//TEAM BIOS CLICKS
	$(".team-bio-li").click(function(){
		var bioNum = $(this).attr('id').replace('team-member-','');
		$(".team-bio-li").removeClass('team-bio-li-selected');
		$(this).addClass('team-bio-li-selected');
		$(".team-member-image, .team-bio-wrappers").hide();
		$("#team-member-image-" + bioNum + ", #team-member-bio-" + bioNum).fadeIn();
		childDiv3 = $("#team-member-bio-" + bioNum + " .scroll-content");
		childDiv3Height = childDiv3.height();
		scrollTop3 = 0;
		$("#team-member-bio-" + bioNum + " .scroll-content").css({top:0});
	});
	
	//PROJECT LIST CLICKS
	$(".project-list-li").click(function(){
		
		clearInterval(slide);
		
		var bioNum = $(this).attr('id').replace('project-list-','');  //Nuber - ex: 1, 2 etc
		
		//li class
		$(".project-list-li").removeClass('project-list-li-selected');
		$(this).addClass('project-list-li-selected');
		
		//hide all groups
		$(".project-list-image-group, .project-list-desc").css({'display': 'none'});
		
		//show selected group
		$("#project-list-image-group-" + bioNum + ", #project-list-desc-" + bioNum).css({'display': 'block'});
		$("#project-list-box-2 img").fadeOut(0);
		$("#project-list-image-group-" + bioNum + " img").fadeIn(0);
		
		
		
		//remove cycle class
		$(".project-list-image-group").removeClass('content-box-image-cycle-wrapper');
		
		//remove all id's
		$(".project-list-image").attr({ 'id' : '' });
		
		//add cycle class
		$("#project-list-image-group-" + bioNum).addClass('content-box-image-cycle-wrapper');
		
		//call cycle fucntion
		cycleImages();
		
		//content scroll stuff
		childDiv3 = $("#project-list-desc-" + bioNum + " .scroll-content");
		childDiv3Height = childDiv3.height();
		scrollTop3 = 0;
		$("#project-list-desc-" + bioNum + " .scroll-content").css({ 'top' : '0' });
	});
	
	
	//SCROLLABLE DIVS
	$(".box-1-scroll-btn").click(function(){
		
		if(!isScrolling){
			
			var clickedArrow = $(this).attr('id'); // use to dictate up or down scroll
			var parentDiv = $(this).parent().parent().attr('id');
			var childDiv = $("#" + parentDiv +  " .scroll-content");
			var parentDivHeight = $("#" + parentDiv).height();
			var childDivHeight = childDiv.height();
			var scrollTop = childDiv.position().top;
			var scrollLimit = (parentDivHeight - childDivHeight) - 50;
			
			if(clickedArrow.indexOf('up') > -1)
			{
				if(scrollTop < 0)
				{
					isScrolling = true;
					$(childDiv).animate({top:scrollTop + 100}, function()
					{
						isScrolling = false;
					});
				}
			}
			else
			{
				if(scrollTop > scrollLimit)
				{
					
					isScrolling = true;
					$(childDiv).animate({top:scrollTop - 100}, function()
					{
						isScrolling = false;
					});
					
				}
	
			}
		}
		
	});
	$(".box-3-scroll-btn").click(function(){
		
		if(!isScrolling){
			
			var clickedArrow = $(this).attr('id'); // use to dictate up or down scroll
			var parentDiv3 = $(this).parent().parent().attr('id'); //done
			var parentDivHeight3 = $("#" + parentDiv3).height(); //done
			var scrollTop3 = childDiv3.position().top;
			var scrollLimit3 = (parentDivHeight3 - childDiv3Height) - 50;
					
			if(clickedArrow.indexOf('up') > -1){
				if(scrollTop3 < 0){
					isScrolling = true;
//					$(childDiv3).animate({top:scrollTop3 - (Math.ceil((scrollLimit3 * .2)) )}, function()
					$(childDiv3).animate({top:scrollTop3 + 100}, function()
					{
						isScrolling = false;
					});
				}
			}
			else{
				if(scrollTop3 > scrollLimit3){
					isScrolling = true;
//					$(childDiv3).animate({top:scrollTop3 + (Math.ceil((scrollLimit3 * .2)) )}, function()
					$(childDiv3).animate({top:scrollTop3 - 100}, function()
					{
						isScrolling = false;
					});
				}
	
			}
	
		}//END if not isScrolling
		
	});
	
});
