/*BrandonApp.js this script handles much of the js interactions for the site*/


function getPage(page){
	//ajax page content
} 

function remove(obj)
{
    return (elem = obj).parentNode.removeChild(elem);
}


function fade(e, time, oncomplete) {
	
	//fade content in and/or out
	if (typeof e === "string"){
		e = document.getElementById(e);
	}
	if (!time) {
		time = 500;
	}
	
	var ease = Math.sqrt;
	var start = (new Date()).getTime();
	
	animate();
	
	function animate() {
		
		var elapsed = (new Date()).getTime() - start;
		var fraction = elapsed/time;
		
		
		if (fraction < 1){
			
			var opacity = 1 - ease(fraction);
			e.style.opacity = String(opacity);
			setTimeout(animate, Math.min(25, time-elapsed));
			
		}
		else {
			e.style.opacity = "#000";
			e.style.display = "none";
			e.style.visibility = "hidden";
			
			remove(e);
			alert("LULZ"); //make it all gone! LULZ!!
			
			if (oncomplete) {
				oncomplete(e);
			}
		}
	}
}

/*AJAX file upload w/iframe*/
//get the frame(s) we are looking for...
function getFrameByName(name){
	for (var i = 0; i<frames.length; i++) {
		if (frames[i].name == name) {
			return frames[i];
		}
		return null;//These are not the frames you're looking for... nothing to see... move along.... move along
	}
}

function uploadDone(name){
	var frame = getFrameByName(name);
	if (frame){
		ret = frame.document.getElementsByTagName("body")[0].innerHTML;
		
		if (ret.length){
		console.log(ret);
		}
	}	
}

function submitform(id){
	var form = document.getElementById(id);
	if (form) {
		form.submit();	
	}
}

//fun function that changes colors of the nav item
function click(){	
	var e = document.getElementById('about_nav');
	var l = document.getElementById('links_nav');
	
	var blue = function() {
		if (this.style.color != "blue"){
			this.style.color="blue";	
			
		}
		else {this.style.color = "";}
		
	}
	//w3c
	if (l.addEventListener) {
		l.addEventListener('click',blue, true);
	}
	//ie8<
	else { l.attachEvent('onclick', blue);}
	
	e.onclick = function (){
		this.style.color="red";
	};
	
	
}

//load functions!
window.onload = function () {
	click();
};

