var startPos = 0;
var stopped = true;
var frameDelay = 10;
var slideWidth = 170;

function goToSlide(slide) {
	if (stopped) { // only do if not already moving 
		endPos = (slide-1)*slideWidth; // determine slide position in pixels
		sineMove(startPos,endPos,100); // start the animation: 100 frames
		startPos = endPos; // reset next start position 
		stopped= false; 
	}
}

function sineMove(from,to,frames) {
	for (var f = 1; f <=frames; f++)
	   {
	   longitude = ((180*f/frames)-90); // transpose to find relative position: range -90 to +90 
	   sine = Math.sin(longitude*Math.PI/180); // transpose to sine curve: range -1 to +1 (convert to radians) 
	   portion = (sine+1)/2; // portion of journey: range 0 to +1 
	   pos = Math.round((portion*(to-from)) + from); // proportion of journey added to start position
	   action = "setSlidesPosition("+pos+")";
	   setTimeout(action, (f*frameDelay));
	   }
	setTimeout("stopped=true;", (frames*frameDelay)); // declare when animation is done
}

function setSlidesPosition(xpos) {
	document.getElementById('slides').style.marginLeft=("-"+xpos+"px");
}

