//SINE SCROLLER
//FROM SOME REPOSITORY
//USE AS STARTING POINT TO ANIMATE BUTTONS

// globals
var initialx, initialy, scrolltext;
var speed = 0.2, speed2 = 0.35;
var frame = 0, frame2 = 0.5;

var amplitude1 = 50, amplitude2 = 75;
var offset = 0.2, offset2 = 0.6;

var amplitude3 = 100, amplitude4 = 100;
var offset3 = 0.3, offset4 = 1.9;

var scrollspeed = 6;
var charwidth = 4;
var twopi = Math.PI * 2;
var characters, position, numvisible, nextchar, firstchar;

var interval, interval2;
var countstep = 1;//this is incremented
//var totalSteps = 200;//this is the final step
var numv = 200;

var angle;
var angle2;
var angle3;
var angle4;
var pos;


// start the animation
function start (obj,name,expobj)
{
	//console.info('here'); //firebug thing
	var theObj = getObject(obj);
	theObj.display = "block";

	setZIndex(obj,1000);//don't set to make go behind main area
	expandBox(name,expobj);

	for (var k=0;k < numv;k++) {
		temp_id = "character"+k;
		characters[k] = document.getElementById(temp_id);
	}

	// get all of the DIV tags into an array
	if (document.all) { //IE

		intervalID = setInterval("shiftBy('" + theObj + "',7,4)",20);
		//alert("IE number of array entries="+characters.length);
	}
	
	// increment counters
	frame += speed;
	frame2 += speed2;
	position -= scrollspeed; 
	// check for 'offscreen'
	if (position < (initialx - charwidth))
	{
		// set nextchar into characters array
		characters[firstchar].innerHTML = '<p class=scroll></p>';
		nextchar++;
		// check for wrap-around
		if (nextchar >= scrolltext.length) nextchar = 0;
		// change position and counters by offset
		position += charwidth;
		frame += offset;
		frame2 += offset2;
		firstchar++;
		if (firstchar >= numvisible) firstchar = 0;
	}
	// wrap-around counters
	if (frame > twopi) frame -= twopi;
	if (frame2 > twopi) frame2 -= twopi;
	// set up loop variables
	//angle = frame;
	//angle2 = frame2;
	angle3 = frame;
	angle4 = frame2;
	pos = position;
	interval2 = window.setInterval("stepThru2();", 50);

}



function sinescroll (x, y)
{
	// setup globals
	value = " ";
	scrolltext = new String(value);
	initialx = x; initialy = y;
	nextchar = numv; firstchar = 0;
	// create fixed-size arrays of characters and positions
	characters = new Array(numv);
	position = initialx;

	// write DIVs to hold characters; prints numv divs
	for (var i = 0; i < numv; i++)
	{
		document.write('<DIV ID="character'+i+'" STYLE="position:absolute;top:',
			initialy, ';z-index:4000;left:', initialx, ';width:', charwidth,
			'px;height:50px;" ><p class=scroll></p></DIV>');
	}

}

/*
function stepThru() {
	
	if (countstep < numv){

		newY = initialy + amplitude1 * Math.sin(angle) + amplitude2 * Math.sin(angle2);
		//shiftTo(characters[countstep],pos,newY);
		shiftTo("moveBox1",pos,newY);
		angle += offset; 
		angle2 += offset2;
		pos += charwidth;
		countstep++;
		
	} else {
		//alert("about to clear interval2");	
		clearInterval(interval2);
		setZIndex("moveBox1",1000);//don't set to make go behind main area		
		//alert("cleared interval2");		
	}

}
*/
 
function stepThru2() {
	
	//alert("at step thru="+countstep+", numvis="+numv);
	if (countstep < numv){

		//this one oscillates faster, then slower: offset3 = 0.4, offset4 = 0.5
		//newY = initialy + amplitude1 * Math.sin(angle3) + amplitude2 * Math.sin(angle4);
		
		//this one is a pretty normal straight sine wave
		//increase amplitude to make it taller
		newY = initialy + amplitude3 + amplitude4 * Math.sin(angle3);

		//shiftTo(characters[countstep],pos,newY);
		shiftTo("moveBox1",pos,newY);
		angle3 += offset3; 
		angle4 += offset4;
		pos += charwidth;
		countstep++;
		
	} else {
		clearInterval(interval2);
		//shiftTo("moveBox1",205,444);
		setZIndex("moveBox1",1000);//don't set to make go behind main area
		//contractBox('mpart7')	
	}

}

// stop the animation
function stop ()
{
	if (interval) clearInterval(interval);
}

window.onunload=stop

sinescroll(-200, 200);
//sinescroll(-10, 300);

