// johnny cison
// www.cison.com
// if you're swiping the code, please leave my name in it.

var words, words_l1, words_l2;
var char_space=7, char_offset=30;
var slide_xt, slide_xt_home, slide_xt_run, slide_yt, slide_yt_home, slide_yt_run;
var slide_xb, slide_xb_home, slide_xb_run, slide_yb, slide_yb_home, slide_yb_run;
var mouse_x, mouse_y, mouse_x_max, mouse_y_max, mouse_x_ctr, mouse_y_ctr, mouse_d, mouse_d_max, mouse_ctr, mouse_dead=0.04;;

function slide_init(l)
{
	var i=0, content='', x, ptr;

	mouse_init();

	words=l.split('|');
	words_l1=words[0].split(' ');
	words_l2=words[1].split(' ');

	for (i=0; i<words_l1.length; i++) { content += '<span id="slide_t_'+i+'" class="slide">'+words_l1[i]+'</span>'; }
	for (i=0; i<words_l2.length; i++) { content += '<span id="slide_b_'+i+'" class="slide">'+words_l2[i]+'</span>'; }
	document.getElementById('d_slides').innerHTML=content;


	slide_xt=new Array(words_l1.length); slide_xt_home=new Array(words_l1.length); slide_xt_run=new Array(words_l1.length);
	slide_yt=new Array(words_l1.length); slide_yt_home=Math.round(mouse_y_max/2)+char_offset-9; slide_yt_run=new Array(words_l1.length);

	slide_xb=new Array(words_l2.length); slide_xb_home=new Array(words_l2.length); slide_xb_run=new Array(words_l2.length);
	slide_yb=new Array(words_l2.length); slide_yb_home=Math.round(mouse_y_max/2)+char_offset+5; slide_yb_run=new Array(words_l2.length);


	x=Math.round(mouse_x_max/2)-(Math.round(words[0].length/2)*char_space);
	for (i=0; i<words_l1.length; i++) { slide_xt_home[i]=x; x += ((words_l1[i].length+1)*char_space); }

	x=Math.round(mouse_x_max/2)-(Math.round(words[1].length/2)*char_space);
	for (i=0; i<words_l2.length; i++) { slide_xb_home[i]=x; x += ((words_l2[i].length+1)*char_space); }

	slide_position();


//	for (i=0; i<words_l1.length; i++) { ptr=document.getElementById('slide_t_'+i); ptr.style.left=slide_xt[i]+'px'; ptr.style.top=slide_yt[i]+'px'; }
//	for (i=0; i<words_l2.length; i++) { ptr=document.getElementById('slide_b_'+i); ptr.style.left=slide_xb[i]+'px'; ptr.style.top=slide_yb[i]+'py'; }

	document.getElementById('d_slides').style.display='block';
	slide_update();
}

function slide_position()
{
	var x;
	for (i=0; i<words_l1.length; i++)
	{
		x=(words_l1[i].length*char_space);
		slide_xt_run[i]=slide_xt[i]=Math.round(Math.random() * (mouse_x_max-x))+10;
		slide_yt_run[i]=slide_yt[i]=Math.round(Math.random() * (mouse_y_max-40))+10;
	}
	for (i=0; i<words_l2.length; i++)
	{
		x=(words_l2[i].length*char_space);
		slide_xb_run[i]=slide_xb[i]=Math.round(Math.random() * (mouse_x_max-x))+10;
		slide_yb_run[i]=slide_yb[i]=Math.round(Math.random() * (mouse_y_max-40))+10;
	}
}

function slide_update()
{
	var ptr;
	mouse_d=Math.sqrt(Math.pow(mouse_x-mouse_x_ctr,2) + Math.pow(mouse_y-mouse_y_ctr,2));

	var temp=(mouse_d/mouse_d_max) - mouse_dead;
	if (temp > 1) { temp=1; mouse_ctr=0; }
	else if (temp < 0)
	{
		temp=0;
		if (mouse_ctr == 0) { slide_position(); }
		mouse_ctr=1;
	}
	else { mouse_ctr=0; }

	for (i=0; i<words_l1.length; i++)
	{
		slide_xt[i]=slide_xt_home[i] + Math.round((slide_xt_run[i]-slide_xt_home[i])*temp);
		slide_yt[i]=slide_yt_home + Math.round((slide_yt_run[i]-slide_yt_home)*temp);

		ptr=document.getElementById('slide_t_'+i);
		ptr.style.left=slide_xt[i]+'px';
		ptr.style.top=slide_yt[i]+'px';
	}
	for (i=0; i<words_l2.length; i++)
	{
		slide_xb[i]=slide_xb_home[i] + Math.round((slide_xb_run[i]-slide_xb_home[i])*temp);
		slide_yb[i]=slide_yb_home + Math.round((slide_yb_run[i]-slide_yb_home)*temp);

		ptr=document.getElementById('slide_b_'+i);
		ptr.style.left=slide_xb[i]+'px';
		ptr.style.top=slide_yb[i]+'px';
	}

	//setTimeout('slide_update()',40);
}

function mouse_init()
{
	document.onmousemove=mouse_update;
	mouse_x=mouse_y=0;

	mouse_x_max=document.documentElement.clientWidth; mouse_y_max=document.documentElement.clientHeight;
	mouse_x_ctr=Math.round(mouse_x_max/2); mouse_y_ctr=Math.round(mouse_y_max/2);

	mouse_d=Math.sqrt(Math.pow(mouse_x-mouse_x_ctr,2) + Math.pow(mouse_y-mouse_y_ctr,2));
	mouse_d_max=Math.sqrt(Math.pow(mouse_x_max-mouse_x_ctr,2) + Math.pow(mouse_y_max-mouse_y_ctr,2));
}
function mouse_update(e) { if (document.all) { mouse_x=window.event.clientX; mouse_y=window.event.clientY; } else { mouse_x=e.clientX; mouse_y=e.clientY; } slide_update(); }

