var divWidth = 740;
var divHeight = 360;
var maxSections = 0;
var currentSection = 1;
var sectionDiv = Array();


function Setup(div, divShadow, sectionNum)
{
	if(sectionNum < 1 || sectionNum > maxSections) {
		return; }

	sectionDiv[sectionNum - 1] = $(div).childNodes[0];
	var top = -(sectionNum - 1) * divHeight;
	var left = (sectionNum - 1) * divWidth;
	
	if(isIE6 === true)
	{
		$(div).setStyle({top: top + 'px', left: left + 'px', filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/background/section" + sectionNum + ".png', sizingMethod='crop')"});
		$(divShadow).setStyle({top: top + 'px', left: left + 'px', filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/background/shadow" + sectionNum + ".png', sizingMethod='crop')"});
	}
	else
	{
		$(div).setStyle({top: top + 'px', left: left + 'px', backgroundImage: 'url(images/background/section' + sectionNum + '.png)'});
		$(divShadow).setStyle({top: top + 'px', left: left + 'px', backgroundImage: 'url(images/background/shadow' + sectionNum + '.png)'});
	}
}

function CustomAction(sectionNum)
{
	if(sectionNum == 8)
	{
		$('bmi-result').update('Result:');
		$('bmi-form').reset();
	}
}

function MoveTo(sectionNum)
{
	if(sectionNum < 1 || sectionNum > maxSections || sectionNum == currentSection) {
		return; }

	// Store the old div and set the new one
	var prevSection = currentSection;
	var distance = (currentSection - sectionNum) * divWidth;
	currentSection = sectionNum;
	
	// Call functions to work with textScroll.js
	scrollTextDiv = sectionDiv[currentSection-1];
	EnableScroll(false);

	// Adjust the duration of the slide depending on the distance
	var absDistance = Math.abs(distance);
	var duration = Math.exp(-absDistance / (4*divWidth)) * (1.7*absDistance / divWidth);

	// Call and pre-slide custom actions
	CustomAction(sectionNum);

	// Initiate the slide
	var effect = new Effect.Parallel( [
		new Effect.Move('hit-center-wrapper', {sync: 'true', x: distance, y: 0, mode: 'relative'}),
		new Effect.Move('hit-shadow-wrapper', {sync: 'true', x: distance, y: 0, mode: 'relative'})
	], { duration: duration, fps: 30, queue: 'end',
		afterFinish: function(effect) {
			// Call functions to work with textScroll.js
			InitArrows();
			$(sectionDiv[prevSection-1]).setStyle({top: '0px'});
		}
	});
}