//Configure the scrolling section settings
var section_positions = 1;
var section_width = 653;
var section_padding = 14;
var total_sections = 8;
var scroll_speed = 300;
var sectionTimer = 0;

var processNames = new Array();
processNames[0] = "Design";
processNames[1] = "Simulation";
processNames[2] = "Visualise";
processNames[3] = "Manage";
processNames[4] = "Collaborate";
processNames[5] = "Prototype";
processNames[6] = "Manufacture";
processNames[7] = "Hardware";


$(document).ready(function(){
	//$("#homepage_story_list li").hide();
	//$(".display_1").show();
	
	
	$("#more_link").html(processNames[section_positions-1]);
	$("#more_text a").attr("href", "http://develop3d.com/process/" + processNames[section_positions-1].toLowerCase());
	
	$("#homepage_story_list li div.homepage_story:odd").css("border-bottom","none");
	
	sectionShowHandler();

	$("#process_nav a").click(function(){
		clearTimeout (sectionTimer);
	});
	
	$("#des_tab").addClass("selected_process selected_lend");
	
	$("#des_tab a").click(
		function(){
			prev_selected = $("#des_tab").hasClass("selected_process");
			section_positions = moveToSection(section_positions,1);
			
			$("#process_nav li").removeClass("selected_process selected_rend selected_lend");
			
			if (prev_selected != true) {
				$("#des_tab").addClass("selected_process selected_lend");
				return false;
			}
		}
	);
	
	$("#sim_tab a").click(
		function(){
			prev_selected = $("#sim_tab").hasClass("selected_process");
			
			section_positions = moveToSection(section_positions,2);
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				$("#sim_tab").addClass("selected_process");
				return false;
			}
		}
	);
	
	$("#vis_tab a").click(
		function(){
		
			prev_selected = $("#vis_tab").hasClass("selected_process");
			
			section_positions = moveToSection(section_positions,3);
			
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				$("#vis_tab").addClass("selected_process");
				return false;
			}
		}
	);
	
	$("#man_tab a").click(
		function(){
		
			prev_selected = $("#man_tab").hasClass("selected_process");
			section_positions = moveToSection(section_positions,4);
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				$("#man_tab").addClass("selected_process");
				return false;
			}
		}
	);
	
	$("#collab_tab a").click(
		function(){
		
			prev_selected = $("#collab_tab").hasClass("selected_process");
			
			section_positions = moveToSection(section_positions,5);
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				$("#collab_tab").addClass("selected_process");
				return false;
			}
		}
	);
	
	$("#proto_tab a").click(
		function(){
		
			prev_selected = $("#proto_tab").hasClass("selected_process");
			
			section_positions = moveToSection(section_positions,6);
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				$("#proto_tab").addClass("selected_process");
				return false;
			}
		}
	);
	
	$("#manf_tab a").click(
		function(){
		
			prev_selected = $("#manf_tab").hasClass("selected_process");
			
			section_positions = moveToSection(section_positions,7);
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				
				$("#manf_tab").addClass("selected_process");
				return false;
			}
		}
	);
	
	$("#hard_tab a").click(
		function(){
		
			prev_selected = $("#hard_tab").hasClass("selected_process");
			
			section_positions = moveToSection(section_positions,8);
			
			$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
			
			if (prev_selected != true) {
				
				$("#hard_tab").addClass("selected_process selected_rend");
				return false;
			}
		}
	);
	

});


function moveToSection(currentPosition,sectionIndex) {
	scrollSpeed = (scroll_speed * Math.abs(sectionIndex - currentPosition));

	leftOffset = (((sectionIndex - 1) * section_width) + ((sectionIndex - 1) * section_padding)) * -1;
	$("#homepage_story_list").animate( { left: leftOffset }, scrollSpeed);
	
	$("#more_link").html(processNames[sectionIndex-1]);
	$("#more_text a").attr("href", "http://develop3d.com/process/" + processNames[sectionIndex-1].toLowerCase());
	
	return sectionIndex;
}

function autoscroll(currentPosition,sectionIndex) {
	scrollSpeed = ((scroll_speed * Math.abs(sectionIndex - currentPosition)) * 1.8);

	leftOffset = (((sectionIndex - 1) * section_width) + ((sectionIndex - 1) * section_padding)) * -1;
	//$("#homepage_story_list").fadeOut("medium",function() {
	//	$("#homepage_story_list").css("left",leftOffset);
	//	$("#homepage_story_list").fadeIn("slow");
	//});
	
	$("#homepage_story_list").animate({
 			
 				left: leftOffset
 			
 	}, 800 );
	
	$("#more_link").html(processNames[sectionIndex-1]);
	$("#more_text a").attr("href", "http://develop3d.com/process/" + processNames[sectionIndex-1].toLowerCase());
	
	return sectionIndex;
}


function sectionShowHandler() {
    sectionTimer = setTimeout ("nextSection()", 7000);
}

function nextSection() {
	
	if (section_positions < 8) {
	
		autoscroll(section_positions,(section_positions + 1));
		section_positions =  section_positions + 1;
		sectionShowHandler();
		selectButton(section_positions);
	} else {
		autoscroll(section_positions,1);
		section_positions = 1;
		sectionShowHandler();
		selectButton(section_positions);
	}

}

function selectButton (selected_button) {
	
	$("#process_nav li").removeClass("selected_process selected_lend selected_rend");
	$(".tab_" + selected_button).addClass("selected_process");
	
	if (selected_button == 1) {
		$(".tab_1").addClass("selected_lend");
	}
	
	if (selected_button == 8) {
		$(".tab_7").addClass("selected_rend");
	}
}
