<!--//Javascipt Coding by Seth Toles for CybermonkeyStudios.com


																//--VARIABLES--//
var playPause = 0;
var titles = new Array();
var artists = new Array();
var playlist = new Array();
var infoHeight = new Array();
var timerStart;
var targetID;
var closingID;
var currentTrack;
var cTime;
var cVolume = 1;
var seek;
var vol;
var opening;
var closing;
var mousePos;
var check = 0;
var currentArtist = "None";
var fullNames = new Array();
var birthdays = new Array();
var locations = new Array();
var bios = new Array();

titles[0] = "Sample One";
titles[1] = "Sample Two";

artists[0] = "Seth Toles";
artists[1] = "Seth Toles";



																//--SETUP TASKS--//
function SetupTasks(){
	if (currentPage == "audio"){
		for (var i = 0; i < titles.length; i++){
			infoHeight["info"+i] = document.getElementById("info"+i).scrollHeight;
			document.getElementById("info"+i).style.height = "0px";
			document.getElementById("info"+i).style.display = "none";
			playlist[i] = document.getElementById(titles[i]);
			playlist[i].addEventListener("progress",DisplayProg,false);
			playlist[i].addEventListener("canplaythrough",SetPlayable,false);
			playlist[i].addEventListener("timeupdate",UpdateTime,false);
		}
	}
}


																//--INPUT TRACKING--//
document.onmousemove = MouseMove;
document.onmouseup = EndHold;
document.onkeypress = CheckSubmittable;

function MouseMove(evt){
	evt = evt || window.event;
	mousePos = mouseCoords(evt); 
} 

function mouseCoords(evt){ 
	if (evt.pageX || evt.pageY){ 
		return {x:evt.pageX, y:evt.pageY}; 
	} else if (evt.clientX || evt.clientY){
		return { 
			x:evt.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:evt.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}
}

function EndHold(){
	clearInterval(seek);
	clearInterval(vol);
	check = 0;
}


																//--SHOW/HIDE DIV--//
function ShowHide(divID){
	targetID = divID;
	timerStart = (new Date()).getTime();
	var targetElement = document.getElementById(targetID);
	if (targetElement.style.display == "none"){
		for (var i=0; i<titles.length; i++){
			if ("info" + i != targetID){
				closingID = "info" + i;
				closing = setInterval(HideDiv, 5);
				document.getElementById("B" + closingID).innerHTML = "More";
			}
		}
		targetElement.style.height = "0px";
		targetElement.style.display = "block";
		opening = setInterval(ShowDiv, 5);
		document.getElementById("B" + targetID).innerHTML = "Less";
	} else {
		closingID = targetID;
		closing = setInterval(HideDiv, 5);
		document.getElementById("B" + targetID).innerHTML = "More";
	}
}

function ShowDiv(){
	var elapsed = (new Date()).getTime() - timerStart;
	var targetElement = document.getElementById(targetID);
	if (elapsed < 150){
		var newHeight = (elapsed / 150) * infoHeight[targetID];
		targetElement.style.height = newHeight + "px";
		var newMargin = (elapsed / 150) * 10;
		targetElement.style.marginTop = newMargin + "px";
	} else {
		targetElement.style.height = infoHeight[targetID] + "px";
		targetElement.style.marginTop = "10px";
		clearInterval(opening);
	}
}

function HideDiv(){
	var elapsed = (new Date()).getTime() - timerStart;
	var targetElement = document.getElementById(closingID);
	if (elapsed < 150){
		var newHeight = infoHeight[closingID] - ((elapsed / 150) * infoHeight[closingID]);
		targetElement.style.height = newHeight + "px";
		var newMargin = 10 - ((elapsed / 150) * 10);
		targetElement.style.marginTop = newMargin + "px";
	} else {
		targetElement.style.height = "0px";
		targetElement.style.marginTop = "0px"
		targetElement.style.display = "none";
		clearInterval(closing);
	}
}


																//--ARTIST BOXES--//
function SelectArtist(selectedArtist){
	var artistBox = document.getElementById("ArtistSection");
	if (currentArtist == "None"){
		currentArtist = selectedArtist;
		timerStart = (new Date()).getTime();
		opening = setInterval(ShowArtist, 5);
	}
	SwitchInfo(selectedArtist);
}

function SwitchInfo(selectedArtist){
	document.getElementById("ArtistPortrait").style.backgroundImage = "url(/styles/Layout_Images/ArtistPortrait" + selectedArtist + ".png)";
	document.getElementById("ArtistName").innerHTML = fullNames[selectedArtist];
	document.getElementById("ArtistAge").innerHTML = AgeCalc(birthdays[selectedArtist]);
	document.getElementById("ArtistLocation").innerHTML = locations[selectedArtist];
	document.getElementById("ArtistBio").innerHTML = bios[selectedArtist];
}

function SendMessage(){
	alert("Sorry, this functionality has not been implemented yet.");
}

function CloseArtistBox(){
	timerStart = (new Date()).getTime();
	closing = setInterval(HideArtist, 5);
}

function ShowArtist(){
	var elapsed = (new Date()).getTime() - timerStart;
	var artistBox = document.getElementById("ArtistSection");
	if (elapsed < 300){
		artistBox.style.bottom = (-225 + ((elapsed / 300) * 225)) + "px";
	} else {
		artistBox.style.bottom = "0px";
		clearInterval(opening);
	}
}

function HideArtist(){
	var elapsed = (new Date()).getTime() - timerStart;
	var artistBox = document.getElementById("ArtistSection");
	if (elapsed < 300){
		artistBox.style.bottom = (-(elapsed / 300) * 225) + "px";
	} else {
		artistBox.style.bottom = "-225px";
		currentArtist = "None";
		clearInterval(closing);
	}
}

function AgeCalc(mySQLbirthday){
	var parts = String(mySQLbirthday).split('-');
	var birthday = new Date()
	birthday.setFullYear(parts[0]);
	birthday.setMonth(parts[1] - 1);
	birthday.setDate(parts[2]);
	var today = new Date();
	if (today.getMonth() > birthday.getMonth()){
		return(today.getYear() - birthday.getYear());
	}
	if ((today.getMonth() == birthday.getMonth()) && (today.getDate() >= birthday.getDate())){
		return(today.getYear() - birthday.getYear());
	} else {
		return(today.getYear() - birthday.getYear() - 1);
	}
}

function PopulateProfile(tag){
	var dispBio = bios[tag].replace(/<br>/gi,"\n");
	document.getElementById("bio").innerHTML = dispBio;
	document.getElementById("location").value = locations[tag];
}


																//--DONATION VALIDATION--//
function CheckDonation(inputVal){
	if (parseFloat(inputVal) != inputVal){
		document.getElementById("DonationAlert").innerHTML = "Entry is not a number.";
		document.getElementById("SubmitDonation").disabled = true;
		document.getElementById("SubmitDonation").style.opacity = .5;
	} else if (inputVal <= 0){
		document.getElementById("DonationAlert").innerHTML = "Entry is negative.";
		document.getElementById("SubmitDonation").disabled = true;
		document.getElementById("SubmitDonation").style.opacity = .5;
	} else {
		document.getElementById("DonationAlert").innerHTML = "";
		document.getElementById("SubmitDonation").disabled = false;
		document.getElementById("SubmitDonation").style.opacity = 1;
	}
}

function CheckSubmittable(evt){ 
	var evt = (evt) ? evt : ((event) ? event : null); 
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
	if ((evt.keyCode == 13) && (node.type=="text")){
		if (document.getElementById("SubmitDonation").disabled == true){
			return false;
		}
	}
} 


																//--UNIVERSAL PLAYER FUNCTIONS--//
function Counter(secondsIn){
	var m = Math.floor(secondsIn/60);
	var s = (secondsIn % 60);
	return((m >= 10 ? m + "" : (m > 0 ? "0" + m + ":" : "00:")) + (s >= 10 ? s : "0" + s));
}


																//--AUDIO PLAYER FUNCTIONS--//
function SongSelected(trackNumber){
	if (currentTrack >= 0){
		playlist[currentTrack].pause();
	}
	ChooseSource(trackNumber);
	if (playlist[currentTrack].readyState == 4){
		if (playlist[currentTrack].paused){
			PlayPause();
		}
	}
}

function ChooseSource(trackNumber){
	currentTrack = trackNumber;
	document.getElementById("AudioTitle").innerHTML = titles[currentTrack];
	document.getElementById("AudioArtist").innerHTML = artists[currentTrack];
	DisplayProg(1989);
}

function DisplayProg(evt){
	if ((evt.target == playlist[currentTrack]) || (evt == 1989)){
		var loadWidth = 500 - parseInt((playlist[currentTrack].buffered.end(0) / playlist[currentTrack].duration) * 500);
		document.getElementById("AudioLoading").style.width = loadWidth + "px";
		document.getElementById("AudioLoading").style.backgroundPositionX = loadWidth + "px";
	}
}

function SetPlayable(evt){
	if (evt.target == playlist[currentTrack]){
		PlayPause();
	}
}

function PlayPause(){
	if (currentTrack >= 0){
		if (playlist[currentTrack].paused){
			document.getElementById("AudioPlay").style.backgroundPositionX = "120px";
			playlist[currentTrack].volume = cVolume;
			playlist[currentTrack].play();
		} else {
			document.getElementById("AudioPlay").style.backgroundPositionX = "0px";
			playlist[currentTrack].pause();
		}
	}
}

function Forward(){
	if (currentTrack >= 0){
		if (currentTrack != playlist.length-1){
			playlist[currentTrack].currentTime = 0;
			if (playlist[currentTrack].paused){
				currentTrack++;
				ChooseSource(currentTrack);
			} else {
				playlist[currentTrack].pause();
				currentTrack++;
				ChooseSource(currentTrack);
				playlist[currentTrack].volume = cVolume;
				playlist[currentTrack].play();
			}
		}
	}
}

function Back(){
	if (currentTrack >= 0){
		playlist[currentTrack].currentTime = 0;
		if ((cTime < 3) && (currentTrack != 0)){
			if (playlist[currentTrack].paused){
				currentTrack--;
				ChooseSource(currentTrack);
			} else {
				playlist[currentTrack].pause();
				currentTrack--;
				ChooseSource(currentTrack);
				playlist[currentTrack].volume = cVolume;
				playlist[currentTrack].play();
			}
		}
	}
}

function SeekTo(){
	if (currentTrack >= 0){
		check++;
		if (window.innerWidth > 800){
			var mousePosition = mousePos.x - (((window.innerWidth - 800) / 2) + 236);
		} else {
			var mousePosition = mousePos.x - 236;
		}
		if (playlist[currentTrack].paused){
			if (mousePosition < 0){
				mousePosition = 0;
			} else if (mousePosition > 505){
				mousePosition = 505;
			} else {
				document.getElementById("ScrubberKnob").style.left = mousePosition + "px";
			}
			playlist[currentTrack].currentTime = (playlist[currentTrack].duration / 505) * mousePosition;
		} else {
			playlist[currentTrack].pause();
			if (mousePosition < 0){
				mousePosition = 0;
			} else if (mousePosition > 505){
				mousePosition = 505;
			} else {
				document.getElementById("ScrubberKnob").style.left = mousePosition + "px";
			}
			playlist[currentTrack].currentTime = (playlist[currentTrack].duration / 505) * mousePosition;
			playlist[currentTrack].play();
		}
		if (check == 1){
			seek = setInterval(SeekTo, 50);
		}
	}
}

function UpdateTime(){
	if (currentTrack >= 0){
		if (!playlist[currentTrack].paused){
			cTime = parseInt(playlist[currentTrack].currentTime);
			var cDuration = parseInt(playlist[currentTrack].duration);
			var cRemains = cDuration - cTime;
			var scrubberPos = (((cTime/cDuration) * 495) + 5) + "px";
			document.getElementById("ScrubberKnob").style.left = scrubberPos;
			document.getElementById("AudioTimeIn").innerHTML = Counter(cTime);
			document.getElementById("AudioTimeOut").innerHTML = Counter(cRemains);
			if (playlist[currentTrack].currentTime >= playlist[currentTrack].duration){
				document.getElementById("AudioPlay").style.backgroundPositionX = "0px";
				playlist[currentTrack].pause();
			}
		} else {
			cTime = parseInt(playlist[currentTrack].currentTime);
			var cDuration = parseInt(playlist[currentTrack].duration);
			var cRemains = cDuration - cTime;
			var scrubberPos = (((cTime/cDuration) * 495) + 5) + "px";
			document.getElementById("ScrubberKnob").style.left = scrubberPos;
			document.getElementById("AudioTimeIn").innerHTML = Counter(cTime);
			document.getElementById("AudioTimeOut").innerHTML = Counter(cRemains);
		}
	}
}

function SetVolume(){
	if (playlist[currentTrack]){
		check++;
		if (window.innerWidth > 800){
			var mousePosition = mousePos.x - (((window.innerWidth - 800) / 2) + 655);
		} else {
			var mousePosition = mousePos.x - 655;
		}
		if (mousePosition < 0){
			mousePosition = 0;
		} else if (mousePosition > 90){
			mousePosition = 90;
		} else {
			document.getElementById("VolumeKnob").style.left = mousePosition + "px";
		}
		cVolume = mousePosition / 90;
		playlist[currentTrack].volume = cVolume;
		if (check == 1){
			vol = setInterval(SetVolume, 50);
		}
	}
}
//-->
