/* Anim variables */
var moveVertic = new Array(); //this is an array of arrays of properties incl element,dist,follow
var moveHorizo = new Array();
var notes = new Array();
var itit = 0;
var animOn = 1;
var notese = new Array("quarternote","sixteennote","eighthnote","halfnote","wholenote","flat","sharp","quarterrest","eightrest","wholerest");
var browserH = 0;
var noteAddition = 300;
var timer = null;
var bannerNum = 1;
var randind = 0;

function startA() {
	setTimeout("timer = setInterval(animateAll,50)",100);
}

function moveNote(note,ind) {
	if(note._vert) {
		if(note._pos >= (note._targ-30)) {
			note.style.top = note._targ+'px';
			note._pos = 40;
			note._vert = false;
		} else {
			note._pos += 30;
			note.style.top = note._pos+'px';
		}
	} else {
		if(note._pos >= 740) {
			noteDone(ind);
		} else {
			note._pos += 1;
			note.style.left = note._pos+'px';
		}
	}
}

getWindowHeight = (navigator.userAgent.toLowerCase().indexOf('firefox')>0||navigator.userAgent.toLowerCase().indexOf('opera')>0||navigator.appVersion.toLowerCase().indexOf('safari')!=-1)?function() {
  browserH = window.innerHeight;
}:function() {
  browserH = document.documentElement.clientHeight||document.body.clientHeight||document.body.scrollHeight;
}

function changeBanner() {
	bannerNum++;
	if(bannerNum>3) bannerNum = 1;
	document.getElementById('bannerchange').src = "graphics/vancebanner/change"+bannerNum+".png";
}

function randomlyChooseLocation() {
	if(randind > 6) {
		randchange = 20+noteAddition;
	} else { 
		randchange = Math.floor(Math.random()*9)*5+noteAddition;
	}
	return randchange;
}

function randomlyChooseNote() {
	randind = Math.floor(Math.random()*10)
	randnote = "graphics/"+notese[randind]+".gif";
	return randnote;
}

function noteDone(inde) {
	changeBanner();
	notes[inde].src = randomlyChooseNote();
	notes[inde].style.left = '40px';
	notes[inde].style.top = '130px';
	notes[inde]._pos = 130;
	notes[inde]._vert = true;
	notes[inde]._targ = randomlyChooseLocation();
}

function animateAll() {
	for(i=notes.length;i--;) {
		moveNote(notes[i],i);
	}
	itit++;
	if(itit > 100) {
		if(notes.length < 7) {
			addNote();
		}
		itit = 0;
	}
}

function addNote() {
	document.getElementById("notediv").appendChild(notes[0].cloneNode(true));
	bla = notes.length-1;
	changeBanner();
	notes[bla].src = randomlyChooseNote();
	notes[bla].style.left = '40px';
	notes[bla].style.top = '130px';
	notes[bla]._pos = 130;
	notes[bla]._vert = true;
	notes[bla]._targ = randomlyChooseLocation();
}
window.onresize = resized;
function resized() {
	prevNA = noteAddition;
	getWindowHeight();
	noteAddition = Math.max(browserH-115,410);
	document.getElementById('staffdiv').style.top = (noteAddition+15)+'px';
	document.getElementById('contentarea').style.height = (noteAddition-225) +'px';
	for(var i=0;i<notes.length;i++) {
		if(notes[i]._vert) {
			notes[i]._targ = notes[i]._targ+(noteAddition-prevNA);
		} else {
			notes[i].style.top = (parseInt(notes[i].style.top)+(noteAddition-prevNA))+'px';
		}
	}
}

function toggleAnim() {
	if(animOn == 1) {
		clearInterval(timer);
		document.getElementById("comping").src = "graphics/playbutover.png";
		animOn = 0;
	} else {
		timer = setInterval(animateAll,50);
		document.getElementById("comping").src = "graphics/pausebutover.png";
		animOn = 1;
	}
}

function init() {
	j = preloadImages();
	getWindowHeight();
	noteAddition = Math.max(browserH-115,410);
	document.getElementById('staffdiv').style.top = (noteAddition+15)+'px';
	document.getElementById('contentarea').style.height = (noteAddition-225) +'px';
	notes = document.getElementById('notediv').getElementsByTagName('img');
	notes[0]._pos = 130;
	notes[0]._vert = true;
	notes[0].src = randomlyChooseNote();
	notes[0]._targ = randomlyChooseLocation();
	startA();
}

function initNoAnim() {
	getWindowHeight();
	noteAddition = Math.max(browserH-115,410);
	document.getElementById('staffdiv').style.top = (noteAddition+15)+'px';
	document.getElementById('contentarea').style.height = (noteAddition-225) +'px';
}

function preloadImages() {
	imgpreload = new Image();
	imgs = new Array();
	imgs[0] = "graphics/change2.png";
	imgs[1] = "graphics/change3.png";
	for(var i=0; i<=1; i++) imgpreload.src = imgs[i];
	return 1;
}

//animation on/off rollovers.
function compOver() {
	if(animOn==1) {
		document.getElementById("comping").src = "graphics/pausebutover.png";
	} else {
		document.getElementById("comping").src = "graphics/playbutover.png";
	}
}

function compOut() {
	if(animOn==1) {
		document.getElementById("comping").src = "graphics/pausebut.png";
	} else {
		document.getElementById("comping").src = "graphics/playbut.png";
	}
}

//linkbar rollovers
function toggleOn(elemid) {
	document.getElementById(elemid).src = "graphics/glossbutover.png";
}

function toggleOff(elemid) {
	document.getElementById(elemid).src = "graphics/glossbut.png";
}
