var fps = 30;
var timeinterval = Math.round(1000/fps);
var secs = 40; //seconds x 10

var obj1time = 0;
var obj1top = 0;
var obj1left = 0;
var footrun = 1;
var footcoltime = 0;
var footrbase = 0;
var footgbase = 0;
var footbbase = 0;
var footr = 0;
var footg = 0;
var footb = 0;


//main function to make everything work
function runner(){
	//move logo around
	if (window.obj1time == 0){
		window.obj1time = Math.round(((Math.random()*secs))*(fps/10))+1;
		setobj1();
		document.getElementById('div1').style.top = parseFloat(document.getElementById('div1').style.top) + window.obj1top + '%';
		document.getElementById('div1').style.left = parseFloat(document.getElementById('div1').style.left) + window.obj1left + '%';

	}else{
		document.getElementById('div1').style.top = parseFloat(document.getElementById('div1').style.top) + window.obj1top + '%';
		document.getElementById('div1').style.left = parseFloat(document.getElementById('div1').style.left) + window.obj1left + '%';
	}
	
	//cycle footer color
	if(window.footrun==1){	
		if (window.footcoltime == 0){
			window.footcoltime = Math.round(((Math.random()*secs))*(fps/10))+1;
			footercolor();
			document.getElementById('footer').style.backgroundColor = 'rgb('+Math.round(window.footrbase)+", "+Math.round(window.footgbase)+", "+Math.round(window.footbbase)+")";
			window.footrbase = parseFloat(window.footrbase) + window.footr;
			window.footgbase = parseFloat(window.footgbase) + window.footg;
			window.footbbase = parseFloat(window.footbbase) + window.footb;
		}
	document.getElementById('footer').style.backgroundColor = 'rgb('+Math.round(window.footrbase)+", "+Math.round(window.footgbase)+", "+Math.round(window.footbbase)+")";
	window.footcoltime --;
	window.footrbase = parseFloat(window.footrbase) + window.footr;
	window.footgbase = parseFloat(window.footgbase) + window.footg;
	window.footbbase = parseFloat(window.footbbase) + window.footb;
	}
	
	setTimeout('runner()',timeinterval);
	window.obj1time --;	
	
}

//set the new target position of the logo and increments to get there
function setobj1(){
	var ot = parseInt(document.getElementById('div1').style.top.substr(0,2));
	var ol = parseInt(document.getElementById('div1').style.left.substr(0,2));
	var nt = Math.round(Math.random()*80);
	var nl = Math.round(Math.random()*55);
	window.obj1top = (nt - ot) / window.obj1time;
	window.obj1left = (nl - ol) / window.obj1time;
}

//set the target color of the footer and increments to get there
function footercolor(){
	var colrgb = document.getElementById('footer').style.backgroundColor.substr(document.getElementById('footer').style.backgroundColor.indexOf("(")+1);
	window.footrbase = parseInt(colrgb);
	window.footgbase = parseInt(colrgb.substr(colrgb.indexOf(",")+1));
	window.footbbase = parseInt(colrgb.substr(colrgb.indexOf(",",colrgb.indexOf(",")+1)+1));
	var nr = Math.round(Math.random()*255);
	var ng = Math.round(Math.random()*255);
	var nb = Math.round(Math.random()*255);
	window.footr = (nr - footrbase) / window.footcoltime;
	window.footg = (ng - footgbase) / window.footcoltime;
	window.footb = (nb - footbbase) / window.footcoltime;
}

//button controls

//play song
function songplay(){
	if (document.getElementById('playsong').value=='Play Song'){
		if (document.getElementById('songtitle').value != 0) {
			document.getElementById('playsong').value='Stop Song';
			soundManager.play("selectedtrack", document.getElementById('songtitle').value);
		}
	}else{
		document.getElementById('playsong').value='Play Song';
		soundManager.stop('selectedtrack');
		soundManager.destroySound('selectedtrack');
	}
}


//show or hide logo
function showlogo(){
	if (document.getElementById('viewlogo').value=='Hide Logo'){
		document.getElementById('viewlogo').value='Show Logo';
		document.getElementById('div1').style.visibility='hidden';
	}else{
		document.getElementById('viewlogo').value='Hide Logo';
		document.getElementById('div1').style.visibility='visible';
	}
}


//fix panel/footer color
function fixfootcol(){
	if (document.getElementById('fixfoot').value=='Fix Panel Color'){
		document.getElementById('fixfoot').value='Cycle Panel Color';
		document.getElementById('footer').style.backgroundColor='rgb(204, 204, 204)';
		window.footrbase=204;
		window.footgbase=204;
		window.footbbase=204;
		window.footrun = 0;    
		window.footcoltime = 0;                  
	}else{
		document.getElementById('fixfoot').value='Fix Panel Color';
		window.footrun = 1;
	}
}
