//Global variable to always know whether the user has recently clicked an arrow
var slideClicked = false;

function animationFunction() {
	$('li.nextSlide a:visible').click();
}

setInterval(function(){
if(slideClicked) {
	slideClicked = false;
}
else {
	animationFunction();
}}, 5000);


$(document).ready(function() {
	
	$('#slideOne').fadeIn(6000);
	$('img.slideOneOne').animate({ left: '470px', opacity: 1 }, 1500, 'easeInOutQuint' );
	$('img.slideOneTwo').animate({ left: '0px', opacity: 1 }, 1900, 'easeInOutQuint' );
	$('img.slideOneThree').animate({ left: '333px', opacity: 1 }, 2200, 'easeInOutQuint' );
	
	/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	Ascendio Slide Transitions
	(copy code from slide one and remove 
	comments for all other slides)
	Josiah Platt - 2011
	=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
	
	//Slide 1 -> Slide 2
	
	//Fired when you click the right arrow:
	$('#slideOneControls li.nextSlide a').click(function() {
		
		slideClicked=true;
		
		//Hide The Controls for Current
		$('#slideOneControls').hide();
		
		//Display The Null Controls Until Animation is Complete
		$('#slideNullControls').show();
		
		$('img.slideOneOne').animate({ left: '2000px', opacity: 0 }, 900, 'easeInOutQuint' );
		$('img.slideOneTwo').animate({ left: '2000px', opacity: 0 }, 1400, 'easeInOutQuint' );
		
		//Get outta heeerree!!! (animate slide backround to the right)
		$('img.slideOneThree').animate({
		    left: '2000px',
			opacity: 0			//CALLBACK! BOOM SHACKALACKA (fade out the current slide)
		  }, 1700, 'easeInOutQuint', function() {
			
										   //ANOTHER CALLBACK! HOLY CRAP! (fade in the next slide)
			$('#slideOne').fadeOut('slow', function(){ 
											  //IT'S RAINING CALLBACKS!!! (animate background image in)
				$('#slideTwo').fadeIn('slow', function(){
				
					$('img.slideTwoOne').animate({ left: '303px' }, 700, 'easeInOutQuint' );
					
					$('img.slideTwoTwo').animate({ left: '5px' }, 800, 'easeInOutQuint' );
				
					$('img.slideTwoThree').animate({
					    left: '91px'
					  }, 1100, 'easeInOutQuint', function() {
						
					    //Reset the Background Image (sets it back up for animation)
						
						$('img.slideOneOne').animate({ left: '-1999px', opacity: 1 });
						$('img.slideOneTwo').animate({ left: '-1999px', opacity: 1 });
						$('img.slideOneThree').animate({ left: '-1999px', opacity: 1 });
						
						$('#slideNullControls').hide();
						$('#slideTwoControls').show();
						
					  });
				
				}); 
			});
		});
		return false;
	});
	
	//Slide 1 <- Slide 2
	
	$('#slideTwoControls li.lastSlide a').click(function() {
		
		slideClicked=true;
		
		$('#slideTwoControls').hide();
		
		$('#slideNullControls').show();
		
		$('img.slideTwoOne').animate({ left: '2000px', opacity: 0 }, 900, 'easeInOutQuint' );
		$('img.slideTwoTwo').animate({ left: '2000px', opacity: 0 }, 1100, 'easeInOutQuint' );
		
		$('img.slideTwoThree').animate({
		    left: '2000px',
			opacity: 0
		  }, 1400, 'easeInOutQuint', function() {
			
			$('#slideTwo').fadeOut('slow', function(){ 
				
				$('#slideOne').fadeIn('slow', function(){
				
					$('img.slideOneOne').animate({ left: '470px', opacity: 1 }, 500, 'easeInOutQuint' );
					$('img.slideOneTwo').animate({ left: '0px', opacity: 1 }, 900, 'easeInOutQuint' );
				
					$('img.slideOneThree').animate({
					    left: '333px',
						opacity: 1
					  }, 1100, 'easeInOutQuint', function() {
						$("img.slideTwoImage").animate({'left' : '-1999px', 'opacity' : '1'});
						
						$('img.slideTwoOne').animate({ left: '-1999px', opacity: 1 } );
						$('img.slideTwoTwo').animate({ left: '-1999px', opacity: 1 } );
						$('img.slideTwoThree').animate({ left: '-1999px', opacity: 1 } );
						
						$('#slideNullControls').hide();
						$('#slideOneControls').show();
						
					  });
				
				}); 
			});
		});
		return false;
	});
	
	//Slide 2 -> Slide 3
	
	$('#slideTwoControls li.nextSlide a').click(function() {
		
		slideClicked=true;
		
		$('#slideTwoControls').hide();
		
		$('#slideNullControls').show();
		
		$('img.slideTwoOne').animate({ left: '2000px', opacity: 0 }, 900, 'easeInOutQuint' );
		$('img.slideTwoTwo').animate({ left: '2000px', opacity: 0 }, 1400, 'easeInOutQuint' );
		
		$('img.slideTwoThree').animate({
		    left: '2000px',
			opacity: 0
		  }, 1700, 'easeInOutQuint', function() {
			
			$('#slideTwo').fadeOut('slow', function(){ 

				$('#slideThree').fadeIn('slow', function(){
				
					$('img.slideThreeOne').animate({ left: '325px' }, 700, 'easeInOutQuint' );
					$('img.slideThreeTwo').animate({ left: '10px' }, 800, 'easeInOutQuint' );
				
					$('img.slideThreeThree').animate({
					    left: '324px'
					  }, 1100, 'easeInOutQuint', function() {
						
						$('img.slideTwoOne').animate({ left: '-1999px', opacity: 1 });
						$('img.slideTwoTwo').animate({ left: '-1999px', opacity: 1 });
						$('img.slideTwoThree').animate({ left: '-1999px', opacity: 1 });
						
						$('#slideNullControls').hide();
						$('#slideThreeControls').show();
						
					  });
				
				}); 
			});
		});
		return false;
	});
	
	//Slide 2 <- Slide 3
	
	$('#slideThreeControls li.lastSlide a').click(function() {
		
		slideClicked=true;
		
		$('#slideThreeControls').hide();
		
		$('#slideNullControls').show();
		
		$('img.slideThreeOne').animate({ left: '2000px', opacity: 0 }, 900, 'easeInOutQuint' );
		
		$('img.slideThreeTwo').animate({ left: '2000px', opacity: 0 }, 1100, 'easeInOutQuint' );
		
		$('img.slideThreeThree').animate({
		    left: '2000px',
			opacity: 0
		  }, 1400, 'easeInOutQuint', function() {
			
			$('#slideThree').fadeOut('slow', function(){ 
				
				$('#slideTwo').fadeIn('slow', function(){
				
					$('img.slideTwoOne').animate({ left: '303px' }, 700, 'easeInOutQuint' );
					$('img.slideTwoTwo').animate({ left: '5px' }, 800, 'easeInOutQuint' );
				
					$('img.slideTwoThree').animate({
					    left: '91px',
						opacity: 1
					  }, 1100, 'easeInOutQuint', function() {
						$("img.slideTwoImage").animate({'left' : '-1999px', 'opacity' : '1'});
						
						$('img.slideThreeOne').animate({ left: '-1999px', opacity: 1 } );
						$('img.slideThreeTwo').animate({ left: '-1999px', opacity: 1 } );
						$('img.slideThreeThree').animate({ left: '-1999px', opacity: 1 } );
						
						$('#slideNullControls').hide();
						$('#slideTwoControls').show();
						
					  });
				
				}); 
			});
		});
		return false;
	});
	
	//Slide 3 -> Slide 1
	
	$('#slideThreeControls li.nextSlide a').click(function() {
		
		slideClicked=true;
		
		$('#slideThreeControls').hide();
		
		$('#slideNullControls').show();
		
		$('img.slideThreeOne').animate({ left: '2000px', opacity: 0 }, 900, 'easeInOutQuint' );
		$('img.slideThreeTwo').animate({ left: '2000px', opacity: 0 }, 1400, 'easeInOutQuint' );
		
		$('img.slideThreeThree').animate({
		    left: '2000px',
			opacity: 0
		  }, 1700, 'easeInOutQuint', function() {
			
			$('#slideThree').fadeOut('slow', function(){ 

				$('#slideOne').fadeIn('slow', function(){
				
					$('img.slideOneOne').animate({ left: '470px', opacity: 1 }, 500, 'easeInOutQuint' );
					$('img.slideOneTwo').animate({ left: '0px', opacity: 1 }, 900, 'easeInOutQuint' );
				
					$('img.slideOneThree').animate({
					    left: '333px'
					  }, 1100, 'easeInOutQuint', function() {
						
						$('img.slideThreeOne').animate({ left: '-1999px', opacity: 1 });
						$('img.slideThreeTwo').animate({ left: '-1999px', opacity: 1 });
						$('img.slideThreeThree').animate({ left: '-1999px', opacity: 1 });
						
						$('#slideNullControls').hide();
						$('#slideOneControls').show();
						
					  });
				
				}); 
			});
		});
		return false;
	});
	
	//I'm putting this down here so it doesn't get in the way of our commenting goodness:
	
	//Slide 3 <- Slide 1
	
	
	
	$('#slideOneControls li.lastSlide a').click(function() {
		
		slideClicked=true;
		
		$('#slideOneControls').hide();
		$('#slideNullControls').show();
		
		$('img.slideOneOne').animate({ left: '2000px', opacity: 0 }, 900, 'easeInOutQuint' );
		$('img.slideOneTwo').animate({ left: '2000px', opacity: 0 }, 1400, 'easeInOutQuint' );
		
		$('img.slideOneThree').animate({
		    left: '2000px',
			opacity: 0
		  }, 1700, 'easeInOutQuint', function() {
			
			$('#slideOne').fadeOut('slow', function(){ 
				
				$('#slideThree').fadeIn('slow', function(){
				
					$('img.slideThreeOne').animate({ left: '325px' }, 700, 'easeInOutQuint' );
					$('img.slideThreeTwo').animate({ left: '10px' }, 800, 'easeInOutQuint' );
				
					$('img.slideThreeThree').animate({
					    left: '324px',
						opacity: 1
					  }, 1100, 'easeInOutQuint', function() {
						$("img.slideTwoImage").animate({'left' : '-1999px', 'opacity' : '1'});
						
						$('img.slideOneOne').animate({ left: '-1999px', opacity: 1 } );
						$('img.slideOneTwo').animate({ left: '-1999px', opacity: 1 } );
						$('img.slideOneThree').animate({ left: '-1999px', opacity: 1 } );
						
							$('#slideNullControls').hide();
							$('#slideThreeControls').show();
						
					  });
				
				}); 
			});
		});
		return false;
	});
	
	//Work Grid Hover Goodness (The Beginning)

	$("ul#workGrid li", this).hover(
		function () {
			$('div.workDetails', this).fadeIn("fast");
		},
		function () {
			$('div.workDetails', this).fadeOut("fast");
	});
	
	//Navigation Hover FX
	$('#home #header ul#nav li a').hover(function() {
	          $(this).animate({"color": "#999999", "color": "#666666"}, 300);
	      }, function() {
	          $(this).animate({"color": "#666666", "color": "#999999"}, 300);
	});
	
	//Sub Page Navigation Hover FX
	$('#sub #header ul#nav li a').hover(function() {
	          $(this).animate({"color": "#4C4C4C", "color": "#cccccc"}, 300);
	      }, function() {
	          $(this).animate({"color": "#cccccc", "color": "#4C4C4C"}, 300);
	});
	
	//Sidebar Navigation Hover FX
	$('#content ul#subNav li a').hover(function() {
	          $(this).animate({"color": "#999999", "color": "#4C4C4C"}, 300);
	      }, function() {
	          $(this).animate({"color": "#4C4C4C", "color": "#999999"}, 300);
	});
	
	//Footer Border Color Hover FX
	$('#footer a.footerClick').hover(function() {
	          $(this).animate({"border-top-color": "#404040", "border-top-color": "#646464"}, 400);
	      }, function() {
	          $(this).animate({"border-top-color": "#646464", "border-top-color": "#404040"}, 400);
	});
	
	//Footer Link Hover FX
	$('#footer div.semita p.copyright a').hover(function() {
	          $(this).animate({"color": "#464646", "color": "#999999"}, 400);
	      }, function() {
	          $(this).animate({"color": "#999999", "color": "#464646"}, 400);
	});
	
	//Colorbox Links	
	$('a.projectOne').colorbox({width:"970px", height:"608px", iframe:true, transition:"none", scrolling:false});
	
	//Work Screenshot Slider
	$('ul#workSlider').simpleslider({  loop : false, easing : 'linear', speed : 500, transition : 'fade' });
	
	
//(document).ready(... close
});
