// touchles javascript™ -- no event handlers in html

window.onload = kickOff;
window.onresize = pageCalc;

var curLeft = 0;
var logoObj;
var aAll;

function kickOff() {
	aAll = document.getElementsByTagName("a");
	// disable and change color of active page's link
    for (var i=0; i<aAll.length; i++) {
        if (window.location.href.split("#")[0] == aAll[i].href) {
            aAll[i].onclick = function() {if (this.blur) {this.blur();} return false;}
            aAll[i].style.cursor = "text";
			aAll[i].style.borderBottom = "none";
			aAll[i].style.color = "#9999aa";
            if (aAll[i].className == "site") {
				aAll[i].style.color = "#ffffff";
           	}
        }
		// fix ie's lack of support for css :focus so tabbers see skip links on focus
		if (navigator.appName == "Microsoft Internet Explorer" && aAll[i].className == "skip") {
			var restoreColor = aAll[i].style.color;
			var restoreBorder = aAll[i].style.borderBottom;
			aAll[i].onfocus = function() {this.style.color = "#777777"; this.style.borderBottom = "1px solid #777777";}
			aAll[i].onblur = function() {this.style.color = restoreColor; this.style.borderBottom = restoreBorder;}
		}
     }
	// fixes in-page link bug for Internet Explorer
	if (navigator.appName == "Microsoft Internet Explorer") {
		getElementsByClass("target");
	}
    // calculate certain elements for placement:
	if(document.getElementById("pic")) {
		profileLoad();
	}
	if(document.getElementById("home")) {
		homeLoad();
	}
    // calculate certain elements for placement:
	pageCalc();
}

function findPos() {
	// position logo-aligned bg image relative to window width accounting for browsers' differing def of offsetParent:
	logoObj = document.getElementById("footerbox").firstChild.firstChild;
	if (logoObj.offsetParent) {
		curLeft = logoObj.offsetLeft;
		while (logoObj.offsetParent!=null) {
			logoObj = logoObj.offsetParent;
			curLeft += logoObj.offsetLeft;
		}
	}
	document.getElementsByTagName("body")[0].style.backgroundImage = "url(/images/bgbody.png)";
	document.getElementsByTagName("body")[0].style.backgroundRepeat = "repeat-y";
	document.getElementsByTagName("body")[0].style.backgroundPosition = curLeft - 649 + "px";
}

function equalCol() {
	var colArray = new Array(["nav",0],["main",0],["sidebar",0]);
	// make the column depths match so they have full-height attributes (bg colors, etc):
	for (var i=0; i<colArray.length; i++) {
		// everyone expresses their natural column heights:
		document.getElementById(colArray[i][0]).style.height = "100%";
		// detect natural column heights in px and store in the array:
		colArray[i][1] = document.getElementById(colArray[i][0]).offsetHeight;
	}
	// determine tallest column in the array:
	var tallCol = Math.max(colArray[0][1],colArray[1][1],colArray[2][1]);
	// make all columns the height of the tallest column:
	for (var i=0; i<colArray.length; i++) {
		if (document.getElementById(colArray[i][0]).offsetHeight == tallCol) {
			var fullCol = document.getElementById(colArray[i][0]);
		}
		document.getElementById(colArray[i][0]).style.height = tallCol + "px";
	}
	fullCol.style.height = "100%"
}

function pageCalc() {
	// position logo-aligned bg image relative to window width:
	findPos();
	// make the column depths match so they have full-height attributes:
	equalCol();
}

function getElementsByClass(searchClass,node,tag) {
	// fixes in-page link bug for Internet Explorer; first find all destinations (elements with classname "target"):
    var classElements = new Array();
	if ( node == null ) {
			node = document;
	}
	if ( tag == null ) {
			tag = '*';
	}
	var elAll = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (var i = 0, j = 0; i < elAll.length; i++) {
		if (pattern.test(elAll[i].className)) {
			classElements[j] = elAll[i];
			j++;
		}
	}
	// then insert what is an invalid attribute for most elements, with an invalid value to boot:
	for (var i=0; i<classElements.length; i++) {
		classElements[i].setAttribute("tabIndex",-1)
	}
}


function homeLoad() {
	// randomly choose imagebar for home page:
    var randomNum = Math.floor((Math.random() * 3));
	document.getElementById("imagebox").style.backgroundImage = "url(images/imageboxhome_" + randomNum + ".jpg)";
	document.getElementById("imagestripe").style.backgroundImage = "url(images/imageboxhome_" + randomNum + ".jpg)";
}

function profileLoad() {
	var profilePeeps = new Array();
	// students
	profilePeeps[0] = [["Sergey Arzumanov"],["Undergraduate, Astrophysics and Russian"],["arzumanov_s"],["The professors at SF State are very diverse in their styles and approaches to their students and subjects they teach."]];
	profilePeeps[1] = [["Charlotte Mårtén"],["Undergraduate, Journalism"],["marten_c"],["I've always wanted to be a journalist because I love to write, but now I realize that you can actually help other people by informing others in the modern world about what's going on out there."]];
	profilePeeps[2] = [["Herbert Leon Hatcher"],["Undergraduate, Sociology"],["hatcher_h"],["At some universities, everybody walks the walk; you have to look a certain way. Here, it's so diverse, come as you want, be who you want."]];
	profilePeeps[3] = [["Robert M. Hawkins"],["BA, English Literature"],["hawkins_r"],["The award-winning speech and debate program... captures what makes SF State and San Francisco great — an open-minded, progressive and thriving community, full of people with unique perspectives on life. It rocks!"]];
	profilePeeps[4] = [["Alison Victor"],["BA, Radio and Television"],["victor_a"],["The Broadcast and Electronic Communication Arts program... is well respected. I had a rock 'n' roll career for 13 years and played around the world. But I thought it was time to learn something else -- something that comes with a 401K, retirement, health insurance — grown-up stuff."]];
	profilePeeps[5] = [["Christopher Quock"],["Undergraduate, Zoology"],["quock_c"],["...since there are many people from different parts of California, other states, and even other countries, it provides a perfect environment in which to form relationships or friendships with some really unique characters."]];
	profilePeeps[6] = [["Lauren Mishork"],["Grad Student, Elementary Education"],["mishork_l"],["I was drawn in by the diversity, the large student population and liberal views. SF State also offered an accelerated, four-year blended B.A. and credential program for entering freshmen called Liberal Studies Integrated Teacher Education (LSITE)."]];
	profilePeeps[7] = [["David Abella"],["Grad Student, Political Science/Public Administration"],["abella_d"],["It's important to stay focused on your education in the classroom, but this campus offers so many more opportunities to learn about the world as you interact with the student body. Do your best to not leave any stone on this campus unturned."]];
	// faculty
	profilePeeps[8] = [["Kenneth Monteiro"],["Dean, College of Ethnic Studies"],["monteiro_k"],["SF State students are bright and energetic. They arrive with experiences as diverse as their ages, ethncities, cultures, political affiliations, (dis)abilities, genders, and identities. I enjoy teaching at SF State because I learn from everyone I teach."]];
	profilePeeps[9] = [["Diane Harris"],["Professor, Psychology"],["harris_d"],["When students are able to apply what they've learned to their lives, I believe we have accomplished some of the most important goals of teaching."]];
	profilePeeps[10] = [["Megumi Fuse"],["Assistant Professor, Biology"],["fuse_m"],["At SF State, the classroom provides the venue for innovative teaching ideas, and provides a link with the scientific research community. I expect students to come out of my classes able to think critically, and to appreciate the contributions of scientific research to our understanding of biology."]];
	profilePeeps[11] = [["Robert Smith"],["Professor, Political Science"],["smith_r"],["San Francisco is a great city. It has a self-conscious, thoughtful kind of radicalism, and the University has reflected that. The diversity at San Francisco State allows you to confront the future in a way that you could not do in many other states."]];
	profilePeeps[12] = [["Ralf Hotchkiss"],["Director and Chief Engineer, Whirlwind Wheelchair International, San Francisco Urban Institute/Institute for Civic and Community Engagement"],["hotchkiss_r"],["SF State is an innovative place, with older students whom I'm more likely to learn from because of their life experience. Most ideas incorporated into the designs of my chairs come from people whom I helped start in the design process. They encountered problems and came up with solutions."]];
	profilePeeps[13] = [["Toni Mirosevich"],["Associate Professor, Creative Writing"],["mirosevich_t"],["Here, people are willing to risk it, to go out on a limb, to try something different in the classroom, to honor traditional and nontraditional models of teaching. Students are allowed to find their own way in the classroom and unveil their own truths."]];
	//profilePeeps[14] = [["name"],["title"],["path"],["quote"]];
	// randomly choose profile for sidebar:
    var randomNum = Math.floor((Math.random() * profilePeeps.length));
	document.getElementById("pic").src = "../profiles/" + profilePeeps[randomNum][2] + ".jpg";
	document.getElementById("pic").setAttribute("alt",profilePeeps[randomNum][0]);
	document.getElementById("quote").firstChild.nodeValue = profilePeeps[randomNum][3];
	document.getElementById("name").firstChild.nodeValue = profilePeeps[randomNum][0];
	document.getElementById("title").firstChild.nodeValue = profilePeeps[randomNum][1];
}





