/*
CLCP v2.1 Clear Links to Current Page
Jonathan Snook
This code is offered unto the public domain
http://www.snook.ca/jonathan/
*/

function clearCurrentLink(){
	var a = document.getElementsByTagName("A");
	
    for(var i=0;i<a.length;i++){
        if(a[i].href == window.location.href.split("#")[0]){
        		
            removeNode(a[i]);
        }
    }
}

function removeNode(n){
    if(n.hasChildNodes()){
        for(var i=0;i<n.childNodes.length;i++){
            n.parentNode.insertBefore(n.childNodes[i].cloneNode(true),n);
        }
    }
    n.parentNode.removeChild(n);
    
}

/* Set class for current page links, etc */
function setClass() {
  var cssClass = "current"; 
  var aElem=document.getElementsByTagName("a");
  for (i=0; i<aElem.length; i++) {  
    if(aElem[i].href == window.location.href.split("#")[0] && aElem[i].parentNode.tagName == "LI" )	{ 	
	   if(aElem[i].parentNode.className == "subnav")	{
		   aElem[i].parentNode.className = cssClass + " subnav"; 
	   }
	   else	{		  
      	 aElem[i].parentNode.className = cssClass;
	   }	
       clearCurrentLink();         
	}	 
  }
}
/* preLoad 150x150 photos of scholars from current and previous years to be used on pages throughout website.  */
/* these are the "buckets" of photos Nancy wants available */
/* related quotes must be entered in html code manually */
function preLoad()	{
   var class2010Photos = new Array();
   var class2009Photos = new Array();	
   if(document.images)	{
	  for (i=0; i<16; i++)	{   
	  class2010Photos[i] = new Image(150,150);
	  class2010Photos[i].src = "images/2010_scholars/scholar_" + (i+1) + ".jpg";		
	  }  
	  for (i=0; i<13; i++)	{   
	  class2009Photos[i] = new Image(150,150);
	  class2009Photos[i].src = "images/2009_scholars/scholar_" + (i+1) + ".jpg";		
	  }	
	  /* also preload photo of frosh restreat and any other misc. photos */
	  other_photos = new Image(299,116);
	  other_photos.src = "images/froshretreat.jpg";
   }   
}
/* Load scholar photos that go on the home page and are randomly selected and displayed along with their quotes */
/* Right now divided into two groups by orientation of photo- that might change */
/* Select one from each group randomly and using the DOM write to the page dynamically */
function photoLoad()	{	
   var scholarPhotos = new Array(8);
   if(document.images)	{
	  for (i=0; i<4; i++)	{   
	    scholarPhotos[i] = new Image(225,300);
	    scholarPhotos[i].src = "images/scholar_0" + (i+1) + ".jpg";
      }
	  for (i=4; i<8; i++)	{   
	    scholarPhotos[i] = new Image(300,225);
	    scholarPhotos[i].src = "images/scholar_0" + (i+1) + ".jpg";
      }
   }   
   var n = randomNum1();
   var m = randomNum2();
   var scholarIntros = new Array("Jose- Technology & Innovations editor at the Huffington Post,  Pulitzer Prize winning journalist, SFSU '04","Hiram- freshman at Foothill College","Will- freshman at UCLA majoring in Business","Kristine- freshman at Foothill College","Nicolette-junior at UC Davis majoring in English","Donna- senior at UCLA majoring in Business Economics (pictured with mentor Paul Gonella)","Ana- sophomore at West Valley College majoring in Business (pictured with mentor Dee Gibson)","Alicia- senior at UC Davis majoring in  Business");
   var scholarQuotes = new Array(8);
   scholarQuotes[0] = "I wouldn't have graduated from a four-year university or become a journalist without the scholarship program. Going to college was simply not in my mind. The foremost concern was: How am I going to make money?\"";
   scholarQuotes[1] = "Words cannot describe how grateful I am; you've helped make my dream come true.  Your financial support enabled me to pay for some room and board costs, as well as books.  The emotional and academic guidance I received from my mentor has been essential.\""; 
   scholarQuotes[2] = "I am the first person in my family to graduate from high school and go to college.  At UCLA I will study business; there I will get the knowledge to start my own business.  My dream is to begin my own hotel chain and be able to pay for my mother's retirement.  I want to buy her a house and give her everything she deserves for the sacrifices she has made in order for me to succeed.\"";
   scholarQuotes[3] = "I want to major in kinesiology so that I may become a physical therapist and personal trainer as an adult, My ultimate dream is to open my own training facility. I have faith that I can help people with difficult circumstances in their lives, and that gives me a reason to believe I have a purpose in this life.\"";
   scholarQuotes[4] = "My mentor has always believed in me, and I could never thank her enough for this.   There have been several instances this year in which I disappointed and lost faith in myself, so I expected everyone else to lose faith in me as well.  But not once during our time together has my mentor done that.  The changes in my attitude that she has taught me, just by example, are significant.  I feel more positive and free.\"";
   scholarQuotes[5] = "The involvement of MVLA Community Scholars in my education is indispensable.  Your support both financially and personally empowers me to succeed, and allows me to do so. Knowing that I belong to such a unique network of resourceful Scholars increases my confidence and ambition. My mentor always make me feel like I have someone on my side and I cannot wait for her to attend my graduation next year.\"";
   scholarQuotes[6] = "For my entire college career, MVLA has been an amazing support system.  My mentor always asks me thoughtful questions and is genuinely interested in my academic and personal accomplishments.  She always makes me feel like I have someone on my side, and I cannot wait for her to attend my graduation next year.\"";
   scholarQuotes[7] = "My mentor has been here for me since before college started and she is always willing and ready to help me out when I need it.  There have been a few days where I have been so stressed and she always asks the right questions and knows what to say to put things into perspective. I value her opinions and advice.\"";
   var divNode = document.getElementById("photo1");
   var imgNode = addNode(divNode,"img","scholar_photo1","");
   imgNode.setAttribute("src",scholarPhotos[m].src);
   imgNode.setAttribute("width","300");
   imgNode.setAttribute("height","225");
   imgNode.setAttribute("alt","scholar photo");
   var pNode = document.getElementById("intro1");
   var textNode = document.createTextNode(scholarIntros[m]);
   pNode.appendChild(textNode);
   pNode = document.getElementById("quote1");
   var textNode = document.createTextNode(scholarQuotes[m]);
   pNode.appendChild(textNode);
   divNode = document.getElementById("photo2");
   var imgNode = addNode(divNode,"img","scholar_photo2","");
   imgNode.setAttribute("src",scholarPhotos[n].src);
   imgNode.setAttribute("width","225");
   imgNode.setAttribute("height","300");
   imgNode.setAttribute("alt","scholar photo");
   pNode = document.getElementById("intro2");
   textNode = document.createTextNode(scholarIntros[n]);
   pNode.appendChild(textNode);
   pNode = document.getElementById("quote2");
   var textNode = document.createTextNode(scholarQuotes[n]);
   pNode.appendChild(textNode);
  
}

//creates a new element node, appends it to parent.
// if text != "", this also creates a text node with text in it and appends it to element.
//sets the name and id attributes to nameId.
//adapted From page 48 of Crane and Pescarello.
function addNode(parent, element, nameId, text)
{	var childEl = document.createElement(element);
	childEl.setAttribute("id", nameId);
	childEl.setAttribute("name", nameId);
	if (text != "")
	{	textNode = document.createTextNode(text);
		childEl.appendChild(textNode);
	}
	parent.appendChild(childEl);
	return childEl;
}

function randomNum1()	{
	var rNum = Math.random();
	rNum = rNum * 4;
	rNum = Math.floor(rNum);	
	return rNum;
}
function randomNum2()	{
	var rNum = Math.random();
	rNum = rNum * 4;
	rNum = 4 + Math.floor(rNum);	
	return rNum;
}


//function to map location of office using google maps
function mapit() {	
    if (GBrowserIsCompatible()) {		
       	var map = new GMap2(document.getElementById("mapDiv"));
		map.setCenter(new GLatLng(37.3798, -122.1103), 15);
		var point = new GLatLng(37.3798, -122.1103);
        map.addOverlay(new GMarker(point));	
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
    }
}

window.onload=function()
{	
	setClass();
	photoLoad();	 
}
/* UseGoogle Calendar API to imbed calendar in events
google.load("gdata", "1");
google.setOnLoadCallback(getMyFeed);

var myService;
var feedUrl = "http://www.google.com/calendar/feeds/gerimacomber@gmail.com/public/full";

function setupMyService() {
  myService = new google.gdata.calendar.CalendarService('MVLA Community Scholars');
}

function getMyFeed() {
  setupMyService();
 
  myService.getEventsFeed(feedUrl, handleMyFeed, handleError);
}
function handleMyFeed(myResultsFeedRoot) {
  alert("This feed's title is: " + myResultsFeedRoot.feed.getTitle().getText());
}

function handleError(e) {
  alert("There was an error!");
  alert(e.cause ? e.cause.statusText : e.message);
} */

/*Accordian */
$(document).ready(function(){

/* $(".accordian h2:first").addClass("active");*/
	$(".accordian ul").hide();

	$(".accordian h2").click(function(){

	  $(this).next("ul").slideToggle("fast")
	  .siblings("ul:visible").slideUp("fast");
	  $(this).toggleClass("active");
	  $(this).siblings("h2").removeClass("active");

	});

});

$(function() {
        $('.accordian h2').hover(function(){
               $(this).addClass('over');
			   $(this).removeClass('out');
        }, function() {
			$(this).removeClass('over');
               $(this).addClass('out');
        });
});


