$(document).ready(function() {

	//Set initial states for hero
	$("#slide-nav li a:first").addClass('active');
	
	var allscreens = new Array;
	$('.screen').each(function(index) {
        allscreens[index] = $(this);
    });
	
	//Set initial states for quotes
    $('.quote blockquote:first').addClass('active');
	
	var allquotes = new Array;
	$('.quote blockquote').each(function(index) {
        allquotes[index] = $(this);
    });
    

//------- START HERO SLIDESHOW FUNCTIONS --------------
		
	//Change the screens
	changeScreen = function(){	
        
        var currentID = $("#slide-nav li a.active").attr("rel") - 1;
        var nextID = $active.attr("rel") - 1;
        
        $('#slide-nav li a').removeClass('active');
        $active.addClass('active');
      
        allscreens[currentID].fadeOut(400, function() {
            $('#slideshow').removeClass();
            $('#slideshow').addClass(allscreens[nextID].attr('id') + '-theme');
            allscreens[nextID].fadeIn(500);
        });
		
		
	}; 
	
	//The Timing Function
	startShow = function(){		
		play = setInterval(function(){ 
			$active = $('#slide-nav li a.active').parent().next().children('a');
			if ( $active.length === 0) { 
				$active = $('#slide-nav li a:first'); 
			}
			changeScreen();
		}, 8000);
	};
	
	startShow(); 
	
	//On Hover
	$(".screen").hover(function() {
		clearInterval(play); 
	}, function() {
		startShow();
	});	
	
	//On Click
	$("#slide-nav a").click(function() {	
		$active = $(this); 
		//Reset Timer
		clearInterval(play); 
		changeScreen(); 
		startShow();
		return false; 
	});	

//------- END HERO SLIDESHOW FUNCTIONS --------------

//------- START QUOTE SLIDESHOW FUNCTIONS --------------
	
	//rotate quotes
	rotateQuote = function(){	
        
        var currentQuote = $(".quote blockquote.active");
        
        $('.quote blockquote').removeClass('active');
        $activeQuote.addClass('active');
      
        currentQuote.fadeOut(400, function() {
            $activeQuote.fadeIn(500);
        });
		
		
	}; 

	//The Timing Function
	startRotate = function(){		
		playQuote = setInterval(function(){ 
			$activeQuote = $('.quote blockquote.active').next();
			if ( $activeQuote.length === 0) { 
				$activeQuote = $('.quote blockquote:first'); 
			}
			rotateQuote();
		}, 12000);
	};
	
	startRotate(); 
	
	//On Hover
	$("blockquote").hover(function() {
		clearInterval(playQuote); 
	}, function() {
		startRotate();
	});	

//------- END QUOTE SLIDESHOW FUNCTIONS --------------
	
});

