// JavaScript Document
$(document).ready(function(){
	//width of individual featured divs
	fboxwidth = 1000;
	//sets control variable
	loopy = 1;
	
	//dwell time
	loopTime = 3500;
	
	//animation time
	animetime = 'slow';
	
	
// sets background color for nav boxes	
$('#navb' + loopy).css ('background-color', "#666666");	


// sets the loop to start when the page loads	
var timerloop = setInterval (function() {
		
		$('#featured_box_inner').animate ({'margin-left': -loopy*fboxwidth + 'px'}, animetime);
		loopy += 1;
		//nav background color
		$('.featured_nav_button').css ('background-color', "#CACACA");
		$('#navb' + loopy).css ('background-color', "#666666");
		
		//resets controlling variable, loopy
		if (loopy == 3) {
			loopy = 0};
	},
			loopTime)	

//code for nav buttons and subsequent loop
$('.featured_nav_button').click (function() {
		
		
		//stops loop
		clearInterval (timerloop);
		//determine which button was pressed
		var currentId = $(this).attr('id');
		//sets defines loopy based on which button
		if ( currentId == 'navb1'){
			loopy = 0;
			};
			
		if ( currentId == 'navb2'){
			loopy = 1;
			};
			
		if ( currentId == 'navb3'){
			loopy = 2;
			};
		//runs animation
		$('#featured_box_inner').animate ({'margin-left': -loopy*fboxwidth + 'px'}, animetime);
		loopy += 1;
		$('.featured_nav_button').css ('background-color', "#CACACA");
		$('#navb' + loopy).css ('background-color', "#666666");
		if (loopy == 3) {
			loopy = 0};
			
			//restarts the loop
			timerloop = setInterval (function() {
		$('#featured_box_inner').animate ({'margin-left': -loopy*fboxwidth + 'px'}, animetime);
		loopy += 1;
		$('.featured_nav_button').css ('background-color', "#CACACA");
		$('#navb' + loopy).css ('background-color', "#666666");
		if (loopy == 3) {
			loopy = 0};
	},
			loopTime);
	return false;});
	
	
});
