//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();
		
	$("#homepage_story_list li div.homepage_story:odd").css("border-bottom","none");
	
	sectionShowHandler();

	$("#homepage_story_list").mouseenter(function(){
		clearTimeout (sectionTimer);
	});
	
	$("#homepage_story_list").mouseleave(function(){
		sectionShowHandler();
	});
	
	$("#page_position li").hover(
  		function () {
    		$(this).addClass("active_dot_over");
  		}, 
  		function () {
    		$(this).removeClass("active_dot_over");
  		}
	);
	
	$("#page_1").addClass("active_dot");
	
	$("#page_1").bind("click",function() {
		section_positions = 8;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_2").bind("click",function() {
		section_positions = 1;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_3").bind("click",function() {
		section_positions = 2;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_4").bind("click",function() {
		section_positions = 3;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_5").bind("click",function() {
		section_positions = 4;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_6").bind("click",function() {
		section_positions = 5;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_7").bind("click",function() {
		section_positions = 6;
		clearTimeout (sectionTimer);
		nextSection();
	});
	$("#page_8").bind("click",function() {
		section_positions = 7;
		clearTimeout (sectionTimer);
		nextSection();
	});
});


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) {

	moveScroller(sectionIndex,currentPosition);
	
	$("#page_position li").removeClass("active_dot");
	$("#page_" + sectionIndex).addClass("active_dot");
	
	return sectionIndex;
}

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

	leftOffset = (((sectionIndex - 1) * section_width) + ((sectionIndex - 1) * section_padding)) * -1;
	
	$("#homepage_story_list").animate({		
 		left: leftOffset
 	}, 800 );
}


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

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

}



