// startup functions

var thisProcess = 0;

$(document).ready(function() {

	// var randomImage = Math.floor(Math.random() * 5);
	var randomImage=0;
	var topVar = (randomImage * -552);
	$("#sliders").css("top",topVar);
	$("#hometext-" + (randomImage + 1)).css("display", "");
	$("#desc-" + (randomImage + 1)).css("display", "");

	var homeText = (randomImage + 1);
	var homeNew;

	// staff sliders
	$("#num1").click(function(){
		var currentLeft = $("#slider").css("left");
		currentLeft = parseFloat(currentLeft);
		currentDiff = currentLeft - parseInt(currentLeft);
		if (currentLeft < 0 && currentDiff == 0) { 
			$("#slider").animate({
				"left": (currentLeft + 504) + "px"
			}, 1500 );
			if ((currentLeft + 504) < 0) {
				document.getElementById("num1").setAttribute("class","current");
			} else {
				document.getElementById("num1").setAttribute("class",""); 				
			}
			document.getElementById("num2").setAttribute("class","current");
		}
	});
	$("#num2").click(function(){
		var currentLeft = $("#slider").css("left");
		currentLeft = parseFloat(currentLeft);
		currentDiff = currentLeft - parseInt(currentLeft);
		maxLeft = $(".block").size();
		maxLeft = (maxLeft - 1) * -504;
		if (currentLeft > maxLeft && currentDiff == 0) {
			$("#slider").animate({
				"left": (currentLeft - 504) + "px"
			}, 1500 );
		}
		document.getElementById("num1").setAttribute("class","current");
		if ((currentLeft - 504) > maxLeft) {
			document.getElementById("num2").setAttribute("class","current");
		} else {
			document.getElementById("num2").setAttribute("class",""); 
		} 
	});
	$("#num3").click(function(){
		$("#boxes2").css("display", "none");
		$("#boxes").css("display", "block");
	});
	$("#num4").click(function(){
		$("#boxes").css("display", "none");
		$("#boxes2").css("display", "block");
	});
	
	// staff name/titles
	$("#team-images-pics .square").hover(
	  function() {
		  $(this).find('div').animate({
			"top": "110px"
		  }, 500 );
	  },
	  function() {
		  $(this).find('div').animate({
			"top": "160px"
		  }, 500 );  
	  }
	);
	
	// staff member page info slider
	$("#team-member-next #next").click(function(){	  
	  $("#slider").animate({
		"top": "-35.50em"
	  }, 1500 );
	  document.getElementById("prev").setAttribute("class","current");
	  document.getElementById("next").setAttribute("class","");  
	});
	$("#g3-next #prev").click(function(){
	  $("#slider").animate({
		"top": "0px"
	  }, 1500 );
	  document.getElementById("prev").setAttribute("class","");
	  document.getElementById("next").setAttribute("class","current");  
	});
	
	// g3 page text slider
	$("#g3-next #next").click(function(){	  
	  $("#slider").animate({
		"top": "-29.6em"
	  }, 1500 );
	  document.getElementById("prev").setAttribute("class","current");
	  document.getElementById("next").setAttribute("class","");  
	});
	$("#team-member-next #prev").click(function(){
	  $("#slider").animate({
		"top": "0px"
	  }, 1500 );
	  document.getElementById("prev").setAttribute("class","");
	  document.getElementById("next").setAttribute("class","current");  
	});

	
	// home page scrolling
	function move(upDown) {
		var thisTop = parseInt(document.getElementById("sliders").style.top,10);
		if ((thisTop/552) == Math.round(thisTop/552)) {
			if (upDown == "+" && thisTop == 0) {
				$("#sliders").animate({
					"top": "-4416px" // change if adding a new slide
				}, 2000 ); 			
			} else if (upDown == "-" && thisTop == -4416) {
				$("#sliders").animate({
					"top": "0px"
				}, 2000 ); 			
			} else {
				$("#sliders").animate({
					"top": upDown + "=552px" // change if adding a new slide
				}, 2000 ); 
			}
		}
	}
	
	function fade(upDown) {
		if (thisProcess == 0) {
			thisProcess = 1;
			if (upDown == "+") {homeNew = homeText - 1;}
			if (upDown == "-") {homeNew = homeText + 1;}
			if (homeNew == 0) {homeNew = 9;} // change if adding a new slide
			if (homeNew == 10) {homeNew = 1;} // change if adding a new slide
			$("#hometext-" + homeText).fadeOut( 2000 );
			$("#desc-" + homeText).css("display", "none");
			$("#desc-" + homeNew).css("display", "inline");
			$("#hometext-" + homeNew).fadeIn( 2000, function() { 
				thisProcess = 0;
			});		
			homeText = homeNew;
		}
	}
	
	$("#pwdoes-top-arrow a").click(function(){	  
		move("+");
		fade("+");
	});	
	
	$("#pwdoes-bottom-arrow a").click(function(){  
		move("-");
		fade("-");
	});	

	
	// g3 project sliders
	$("#our-work-images .rectangle").hover(
	  function() {
		  $(this).find('div').animate({
			"top": "164px"
		  }, 500 );
	  },
	  function() {
		  $(this).find('div').animate({
			"top": "328px"
		  }, 500 );  
	  }
	);
	
	// work functions
	$(".project-box").click(function(){	  
		var thisID = ($(this).attr('id')).substr(5,1);
		$(".graphic").css('display', 'none');
		$("#graphic-" + thisID).css('display', 'block');
		$(".project-box").removeClass("current");
		$("#work-" + thisID).addClass("current");
		$(".worktext").css('display', 'none');
		$("#worktext-" + thisID).css('display','inline');
	});		

});

