/* These are the Google Calendar ID's and colors for each area */
CHORAL_ID =             "s1sjjaa0lbgjkkf87manbrpa74%40group.calendar.google.com";
CHORAL_COLOR =          "A32929";
FOM_ID =                "8ktbfn44012k4up12tho4vdikk%40group.calendar.google.com";
FOM_COLOR =             "5A6986";
JAZZ_ID =               "hiep7ubgcgr8d6gncn57jstbeo%40group.calendar.google.com";
JAZZ_COLOR =            "BE6D00";
MARCHING_BAND_ID =      "1t32kgfhrf92fe0gdd7sr9rud4%40group.calendar.google.com";
MARCHING_BAND_COLOR =   "B1440E";
MUSICAL_THEATER_ID =    "fop32dcqpqdc0qfhfhlt17ou20%40group.calendar.google.com";
MUSICAL_THEATER_COLOR = "865A5A";
PREP_ID =               "c3027ltqjcbuk1pak8ticjgdeo%40group.calendar.google.com";
PREP_COLOR =            "4E5D6C";
RECITAL_ID =            "sbvd33hvb7vkedu419atrkhguk%40group.calendar.google.com";
RECITAL_COLOR =         "705770";
SPECIAL_EVENTS_ID =     "7cofu68af7b4ho1643f1acqbu8%40group.calendar.google.com";
SPECIAL_EVENTS_COLOR =  "4E5D6C";
WIND_ENSEMBLE_ID =      "ihghs2qsm5d0n4q3skufi7lmgo%40group.calendar.google.com";
WIND_ENSEMBLE_COLOR =   "4A716C";
DEPARTMENT_ID =         "n3kvlg32s84c4ug8srs5lr1lq8%40group.calendar.google.com";
DEPARTMENT_COLOR =      "8D6F47";

/* This is an array of Calendars available to the public, where concerts are listed.  */
PUBLIC_CALENDARS = [CHORAL_ID, FOM_ID, JAZZ_ID, MARCHING_BAND_ID, MUSICAL_THEATER_ID, PREP_ID, RECITAL_ID, SPECIAL_EVENTS_ID, WIND_ENSEMBLE_ID];

/* This function creates a Google Embedded Calendar of all public events beginning at startDate.
If startDate is passed in, the default view is by week, otherwise it's an Agenda view (a list)  */
function publicCalendar(startDate)
{
	document.write('<iframe src="http://www.google.com/calendar/embed?');
	if (startDate)
	{
		document.write('mode=WEEK&amp;dates='+ startDate +'%2F'+ startDate);
	}
	else
	{
		document.write('mode=AGENDA');
	}
	document.write('&amp;title=Shepherd%20University%20Department%20of%20Music&amp;height=600&amp;wkst=1&amp;bgcolor=%23d49923');
	document.write('&amp;src='+ CHORAL_ID          +'&amp;color=%23'+ CHORAL_COLOR);
	document.write('&amp;src='+ FOM_ID             +'&amp;color=%23'+ FOM_COLOR);
	document.write('&amp;src='+ JAZZ_ID            +'&amp;color=%23'+ JAZZ_COLOR);
	document.write('&amp;src='+ MARCHING_BAND_ID   +'&amp;color=%23'+ MARCHING_BAND_COLOR);
	document.write('&amp;src='+ MUSICAL_THEATER_ID +'&amp;color=%23'+ MUSICAL_THEATER_COLOR);
	document.write('&amp;src='+ PREP_ID            +'&amp;color=%23'+ PREP_COLOR);
	document.write('&amp;src='+ RECITAL_ID         +'&amp;color=%23'+ RECITAL_COLOR);
	document.write('&amp;src='+ SPECIAL_EVENTS_ID  +'&amp;color=%23'+ SPECIAL_EVENTS_COLOR);
	document.write('&amp;src='+ WIND_ENSEMBLE_ID   +'&amp;color=%23'+ WIND_ENSEMBLE_COLOR);
	document.write('&amp;ctz=America%2FNew_York" style=" border:solid 2px #d49923 " width="600" height="600" frameborder="0" scrolling="no"></iframe>');
}

/* This function creates a Google Embedded Calendar of all public events and departmental events.
Notice that unlike publicCalendar(), there is no option to change the starting date. */
function departmentCalendar()
{
	document.write('<iframe src="http://www.google.com/calendar/embed?mode=AGENDA&amp;title=Shepherd%20University%20Department%20of%20Music&amp;height=600&amp;wkst=1&amp;bgcolor=%23d49923');
	document.write('&amp;src='+ DEPARTMENT_ID      +'&amp;color=%23'+ DEPARTMENT_COLOR);
	document.write('&amp;src='+ CHORAL_ID          +'&amp;color=%23'+ CHORAL_COLOR);
	document.write('&amp;src='+ FOM_ID             +'&amp;color=%23'+ FOM_COLOR);
	document.write('&amp;src='+ JAZZ_ID            +'&amp;color=%23'+ JAZZ_COLOR);
	document.write('&amp;src='+ MARCHING_BAND_ID   +'&amp;color=%23'+ MARCHING_BAND_COLOR);
	document.write('&amp;src='+ MUSICAL_THEATER_ID +'&amp;color=%23'+ MUSICAL_THEATER_COLOR);
	document.write('&amp;src='+ PREP_ID            +'&amp;color=%23'+ PREP_COLOR);
	document.write('&amp;src='+ RECITAL_ID         +'&amp;color=%23'+ RECITAL_COLOR);
	document.write('&amp;src='+ SPECIAL_EVENTS_ID  +'&amp;color=%23'+ SPECIAL_EVENTS_COLOR);
	document.write('&amp;src='+ WIND_ENSEMBLE_ID   +'&amp;color=%23'+ WIND_ENSEMBLE_COLOR);
	document.write('&amp;ctz=America%2FNew_York" style=" border:solid 2px #d49923 " width="600" height="600" frameborder="0" scrolling="no"></iframe>');
}

/* This function is used to pull parameters from the URL string */
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

/* This function is necessary for some date work being done */
Date.prototype.setISO8601 = function (string) {
    var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
    var d = string.match(new RegExp(regexp));
    var offset = 0;
    var date = new Date(d[1], 0, 1);
    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[5]); }
    if (d[7]) { date.setHours(d[7]); }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
    if (d[14]) {
        offset = (Number(d[16]) * 60) + Number(d[17]);
        offset *= ((d[15] == '-') ? 1 : -1);
    }
    offset -= date.getTimezoneOffset();
    time = (Number(date) + (offset * 60 * 1000));
    this.setTime(Number(time));
}

/* A simple array of the months and days of the week */
var Months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var DaysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

/* This is a way to compare two calendar events and find out which one comes first */
function entrySort(a,b)
{
  var x = google.feeds.getElementsByTagNameNS(a, "http://schemas.google.com/g/2005", "when")[0].getAttribute('startTime');
  var y = google.feeds.getElementsByTagNameNS(b, "http://schemas.google.com/g/2005", "when")[0].getAttribute('startTime');
  return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

/*
Google Calendar Kluge for the home page calendar. This ONLY is for the home page.
This works around the fact that you can't call multiple calendars at once in Google.
It is a serious kluge. Once this problem gets solved, we should move from this instead of the current kluged calendar.
Issue being tracked here:
http://code.google.com/p/gdata-issues/issues/detail?id=421&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary
NOTE: This script is highly NON-INTUITIVE. If something looks like it doesn't make sense, LEAVE IT ALONE. Google's
functions are highly threaded and things happen out of order!
*/
function homePageCalendar()
{
	google.load("feeds", "1");
	google.setOnLoadCallback(initialize);

	var counter = 0;
	var allEntries = new Array();
	var calCounter = 0;

	function initialize() 
	{
	  var ul = document.createElement("ul");
	  var feedContainer = document.getElementById("feedhome");
	  var highlightContainer = document.getElementById("concert_mini");
	  for (var cal=0; cal < PUBLIC_CALENDARS.length; cal++)
	  {
	    var feed = new google.feeds.Feed("http://www.google.com/calendar/feeds/"+ PUBLIC_CALENDARS[cal] +"/public/full?orderby=starttime&sortorder=ascending&futureevents=true&max-results=500");
		feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	    feed.setNumEntries(5); // This is how many entries to get from each calendar category
	    feed.load(function(result) 
		{
	      calCounter++;
	      if (!result.error) 
		  {
	        var entries = google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://www.w3.org/2005/Atom", "entry");
	        for (var i = 0; i < entries.length; i++) 
			{
	          allEntries[counter++] = entries[i];
	        }
	      }
		  // If we've done the last calendar, now it's time to sort and print
		  if (calCounter == PUBLIC_CALENDARS.length)
		  {
			numberOfEntries = 5; // How many calendar entries in the text list do we want?
			numberOfHighlights = 9; // How many highlights do we want?
			highlightCounter = 0;
			allEntries.sort(entrySort);
			for (var i=0; i < allEntries.length; i++)
			{
			  var titleElement = google.feeds.getElementsByTagNameNS(allEntries[i], "http://www.w3.org/2005/Atom", "title")[0];
	          var title = titleElement.firstChild.nodeValue;
	          var whenElement = google.feeds.getElementsByTagNameNS(allEntries[i], "http://schemas.google.com/g/2005", "when")[0];
	          var starttime = whenElement.getAttribute('startTime');
			  var googleTime = starttime.substr(0,10).replace(/-/g,"");
	          var endtime = whenElement.getAttribute('endTime');
	          var startdate = new Date();
	          startdate.setISO8601(starttime);
	          var enddate = new Date();
	          enddate.setISO8601(endtime);
			  // This next line is there to get rid of all-day events
			  if (startdate.getDate() < enddate.getDate()) {numberOfEntries++; continue;}
	          var whenstring = (Months[startdate.getMonth()]) + ' ' + (startdate.getDate()) + ', ' + startdate.getFullYear() + ' ';
		  	  var minutes = startdate.getMinutes();
			  if (minutes < 10) { minutes = "0" + minutes; }
			  if (startdate.getHours() > 12)
				{whenstring = whenstring + (startdate.getHours()-12) + ':' + minutes + " p.m.";}
			  else 
				{whenstring = whenstring + (startdate.getHours()) + ':' + minutes + " a.m.";}
			  /* This block is what populates the text list of calendar entries, with an upper limit of numberOfEntries */
			  if (i < numberOfEntries)
			  {
		          //embed the event date in a span element with class="when"
		          var spanwhen = document.createElement("span");
		          spanwhen.setAttribute("class", "when");
		          spanwhen.appendChild(document.createTextNode(' > > '+ whenstring));
		          //each feed entry is embedded in an HTML li element
		          var li = document.createElement("li");
		          var a = document.createElement("a");
				  a.setAttribute("href", "http://www.shepherd.edu/musicweb/ConcertPage.html?eventDate="+ googleTime);
		          if (title.charAt(0) == '*') // Slice off the first asterisk
					{a.appendChild(document.createTextNode(title.substr(1) + ' '));}
				  else
					{a.appendChild(document.createTextNode(title + ' '));}
		          li.appendChild(a);
				  var br = document.createElement("br");
				  li.appendChild(br);
		          li.appendChild(spanwhen);
		          ul.appendChild(li);
			  }
			  /* This block populates the concert highlight pop-up DIV on the home page */
			  if (highlightCounter < numberOfHighlights && title.charAt(0) == '*')
			  {
				  highlightCounter++;
				  title = title.substr(1); // Slice off the first asterisk
				  var concertDiv = document.createElement("div");
					concertDiv.setAttribute("id", "concert_mini_"+ highlightCounter);
				  var a = document.createElement("a");
					a.setAttribute("id", "thumb"+ highlightCounter);
					a.setAttribute("href", "concerts/"+ googleTime +".jpg");
					a.setAttribute("class", "highslide");
					// a.setAttribute("onclick", "return hs.expand(this)"); // This doesn't work in IE, use the next one instead
					a.onclick = function(){return hs.expand(this);};
				  var img = document.createElement("img");
				    img.setAttribute("src", "concerts/"+ googleTime +"-mini.jpg");
					img.setAttribute("title", title +" (click to expand)");
					img.setAttribute("height", "90");
					img.setAttribute("width", "90");
				  a.appendChild(img);
				  var captionDiv = document.createElement("div");
				    captionDiv.setAttribute("class", "highslide-caption"); // Firefox
				    captionDiv.setAttribute("className", "highslide-caption"); // IE
					captionDiv.appendChild(document.createTextNode(title + '. '+ whenstring +' '));
				  var a2 = document.createElement("a");
					a2.setAttribute("href", "http://www.shepherd.edu/musicweb/ConcertPage.html?eventDate="+ googleTime);
					a2.appendChild(document.createTextNode("More Information"));
				  captionDiv.appendChild(a2);
				  concertDiv.appendChild(a);
				  concertDiv.appendChild(captionDiv);
				  highlightContainer.appendChild(concertDiv);
			  }
			}
		  }
	    }); // end feed load
	    feedContainer.appendChild(ul); // Add the entry list to the feed DIV
	  } // end calendar for loop
	} // end initialize()
}

/* This script pulls in a list of events in a SINGLE category and writes the information to the DIV with the id of "feed".
Unlike the one on the home page, this Google Calendar Feed pulls in only one category, If parseText is included, it will only
display events that have that text in the title. */
function startCalendarFeed(calendarID, parseText)
{
  google.load("feeds", "1");
  function initialize() 
  {
    var feed = new google.feeds.Feed("http://www.google.com/calendar/feeds/"+ calendarID +"/public/full?orderby=starttime&sortorder=ascending&futureevents=true&max-results=500");
 	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
    feed.setNumEntries(20);
    feed.load(function(result) 
	{
      var container = document.getElementById("feed");
      if (!result.error) 
	  {
        var whenstring = '';
        var entries = google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://www.w3.org/2005/Atom", "entry");
        var ul = document.createElement("ul");
        for (var i = 0; i < entries.length; i++) 
		{
		  var titleElement = google.feeds.getElementsByTagNameNS(entries[i], "http://www.w3.org/2005/Atom", "title")[0];
          var title = titleElement.firstChild.nodeValue;
		  /* Remove the initial asterisk if there is one */
		  if (title.charAt(0) == '*') {title = title.substr(1);}
		  /* Forget this event if parseText is not found. */
          if (parseText != null && parseText != "")
		  {
		    if (title.indexOf(parseText) == -1) { continue; }
		  }
          var whenElement = google.feeds.getElementsByTagNameNS(entries[i], "http://schemas.google.com/g/2005", "when")[0];
          var starttime = whenElement.getAttribute('startTime');
		  var googleTime = starttime.substr(0,10).replace(/-/g,"");
          var endtime = whenElement.getAttribute('endTime');
          var startdate = new Date();
          startdate.setISO8601(starttime, "-0500" );
          var enddate = new Date();
          enddate.setISO8601(starttime, "-0500" );
          var whenstring = ' - ' + (Months[startdate.getMonth()]) + ' ' + (startdate.getDate()) + ', ' + startdate.getFullYear() + ' ';
	  	  var minutes = startdate.getMinutes();
		  if (minutes < 10) { minutes = "0" + minutes; }
		  if (startdate.getHours() > 12)
		  {
	        whenstring = whenstring + (startdate.getHours()-12) + ':' + minutes + " p.m.";
		  }
		  else
		  {
		    whenstring = whenstring + (startdate.getHours()) + ':' + minutes + " a.m.";
		  }
          var spanwhen = document.createElement("span");
          spanwhen.setAttribute("class", "when");
          spanwhen.appendChild(document.createTextNode(whenstring));
          var li = document.createElement("li");
          var a = document.createElement("a");
		  a.setAttribute("href", "http://www.shepherd.edu/musicweb/ConcertPage.html?eventDate="+ googleTime);
          a.appendChild(document.createTextNode(title + ' '));
          li.appendChild(a);
          li.appendChild(spanwhen);
          ul.appendChild(li);
        } // end for
        container.appendChild(ul);
      } // end if error
    }); // end feed load
  } // end initialize()
  google.setOnLoadCallback(initialize);
} // end startCalendarFeed()

/* This script pulls in a SINGLE CALENDAR EVENT and writes the information to the DIV with the id of "concertInfo". 
You need the event date (YYYYMMDD) and the event category (i.e. CHORAL_ID). Right now, it CANNOT pull in the event
if the event category is not explicitly defined. This is a bug in Google because we can't search all categories. 
NOTE: THIS FUNCTION IS NOW DEPRECATED AND SHOULD BE DELETED. */
function getSingleCalendarEvent(eventDate, eventCategory)
{
  google.load("feeds", "1");
  function initialize() 
  {
    /* The date that we're getting is only eight digits, YYYYMMDD. We have to turn it into RFC 3339 format, like 2005-08-09T10:57:00-08:00. */
	var startMin = eventDate.substr(0,4) +"-"+ eventDate.substr(4,2) +"-"+ eventDate.substr(6,2) + "T00:00:00-05:00";
	var startMax = eventDate.substr(0,4) +"-"+ eventDate.substr(4,2) +"-"+ eventDate.substr(6,2) + "T23:59:59-05:00";
    var feed = new google.feeds.Feed("http://www.google.com/calendar/feeds/"+ eventCategory +"/public/full?orderby=starttime&sortorder=ascending&start-min="+ startMin +"&start-max="+ startMax);
 	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
    feed.setNumEntries(1);
    feed.load(function(result) 
	{
      var container = document.getElementById("concertInfo");
      if (!result.error) 
	  {
        var whenstring = '';
        var entries = google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://www.w3.org/2005/Atom", "entry");
        for (var i = 0; i < entries.length; i++) 
		{
		  var titleElement = google.feeds.getElementsByTagNameNS(entries[i], "http://www.w3.org/2005/Atom", "title")[0];
          var title = titleElement.firstChild.nodeValue;
		  /* Remove the initial asterisk if there is one */
		  if (title.charAt(0) == '*') {title = title.substr(1);}
		  /* Change the page title in HTML */
		  document.title="Shepherd University Department of Music: "+ title;
          var contentElement = google.feeds.getElementsByTagNameNS(entries[i], "http://www.w3.org/2005/Atom", "content")[0];
          var content = "";
		  if (contentElement && contentElement.firstChild) {content = contentElement.firstChild.nodeValue;}
		  /* Remove anything from "More details" onward */
		  var detailsIndex = content.indexOf("More details");
		  if (detailsIndex > -1) {content = content.substr(0, detailsIndex);}
          var whenElement = google.feeds.getElementsByTagNameNS(entries[i], "http://schemas.google.com/g/2005", "when")[0];
          var starttime = whenElement.getAttribute('startTime');
		  var googleTime = starttime.substr(0,10).replace(/-/g,"");
          var endtime = whenElement.getAttribute('endTime');
          var startdate = new Date();
          startdate.setISO8601(starttime, "-0500" );
          var enddate = new Date();
          enddate.setISO8601(starttime, "-0500" );
          var whenstring = (DaysOfWeek[startdate.getDay()] + ', ' + Months[startdate.getMonth()]) + ' ' + (startdate.getDate()) + ', ' + startdate.getFullYear() + ' ';
	  	  var minutes = startdate.getMinutes();
		  if (minutes < 10) { minutes = "0" + minutes; }
		  if (startdate.getHours() > 12)
		  {
	        whenstring = whenstring + (startdate.getHours()-12) + ':' + minutes + " p.m.";
		  }
		  else
		  {
		    whenstring = whenstring + (startdate.getHours()) + ':' + minutes + " a.m.";
		  }
		  var h1 = document.createElement("h1");
			h1.appendChild(document.createTextNode(title));
			container.appendChild(h1);
		  var h2 = document.createElement("h2");
			h2.appendChild(document.createTextNode(whenstring));
			container.appendChild(h2);
		  var img = document.createElement("img");
	  		img.setAttribute("src", "concerts/"+ googleTime +".jpg");
			img.setAttribute("title", title);
			container.appendChild(img);
		  var p = document.createElement("p");
			p.appendChild(document.createTextNode(content));
			container.appendChild(p);
        } // end for
      } // end if error
    }); // end feed load
  } // end initialize()
  google.setOnLoadCallback(initialize);
} // end startCalendarFeed()

/* Experimental script for calling in everything on a single day */
function getSingleCalendarDay()
{
	google.load("feeds", "1");
	google.setOnLoadCallback(initialize);

	var counter = 0;
	var allEntries = new Array();
	var calCounter = 0;

	function initialize() 
	{
	  eventDate = gup("eventDate");
	  /* The date that we're getting is only eight digits, YYYYMMDD. We have to turn it into RFC 3339 format, like 2005-08-09T10:57:00-08:00. */
	  var startMin = eventDate.substr(0,4) +"-"+ eventDate.substr(4,2) +"-"+ eventDate.substr(6,2) + "T00:00:00-05:00";
  	  var startMax = eventDate.substr(0,4) +"-"+ eventDate.substr(4,2) +"-"+ eventDate.substr(6,2) + "T23:59:59-05:00";
	  var ul = document.createElement("ul");
	  var container = document.getElementById("concertInfo");
	  for (var cal=0; cal < PUBLIC_CALENDARS.length; cal++)
	  {
		var feed = new google.feeds.Feed("http://www.google.com/calendar/feeds/"+ PUBLIC_CALENDARS[cal] +"/public/full?orderby=starttime&sortorder=ascending&start-min="+ startMin +"&start-max="+ startMax);
		feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	    feed.setNumEntries(2); // This is how many entries to get from each calendar category
	    feed.load(function(result) 
		{
	      calCounter++;
	      if (!result.error) 
		  {
	        var entries = google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://www.w3.org/2005/Atom", "entry");
	        for (var i = 0; i < entries.length; i++) 
			{
	          allEntries[counter++] = entries[i];
	        }
	      }
		  // If we've done the last calendar, now it's time to sort and print
		  if (calCounter == PUBLIC_CALENDARS.length)
		  {
			numberOfEntries = 5; // How many calendar entries in the text list do we want?
			allEntries.sort(entrySort);
			for (var i=0; i < allEntries.length; i++)
			{
			  var titleElement = google.feeds.getElementsByTagNameNS(allEntries[i], "http://www.w3.org/2005/Atom", "title")[0];
	          var title = titleElement.firstChild.nodeValue;
  /* Remove the initial asterisk if there is one */
  if (title.charAt(0) == '*') {title = title.substr(1);}
  /* Change the page title in HTML */
  document.title="Shepherd University Department of Music: "+ title;
  var contentElement = google.feeds.getElementsByTagNameNS(allEntries[i], "http://www.w3.org/2005/Atom", "content")[0];
  var content = "";
  if (contentElement && contentElement.firstChild) {content = contentElement.firstChild.nodeValue;}
	          var whenElement = google.feeds.getElementsByTagNameNS(allEntries[i], "http://schemas.google.com/g/2005", "when")[0];
	          var starttime = whenElement.getAttribute('startTime');
			  var googleTime = starttime.substr(0,10).replace(/-/g,"");
	          var endtime = whenElement.getAttribute('endTime');
	          var startdate = new Date();
	          startdate.setISO8601(starttime);
	          var enddate = new Date();
	          enddate.setISO8601(endtime);
			  // This next line is there to get rid of all-day events
			  if (startdate.getDate() < enddate.getDate()) {numberOfEntries++; continue;}
	          var whenstring = (Months[startdate.getMonth()]) + ' ' + (startdate.getDate()) + ', ' + startdate.getFullYear() + ' ';
		  	  var minutes = startdate.getMinutes();
			  if (minutes < 10) { minutes = "0" + minutes; }
			  if (startdate.getHours() > 12)
				{whenstring = whenstring + (startdate.getHours()-12) + ':' + minutes + " p.m.";}
			  else 
				{whenstring = whenstring + (startdate.getHours()) + ':' + minutes + " a.m.";}
			  /* This block is what populates the text list of calendar entries, with an upper limit of numberOfEntries */
			  if (i < numberOfEntries)
			  {
  var h1 = document.createElement("h1");
	h1.appendChild(document.createTextNode(title));
	container.appendChild(h1);
  var h2 = document.createElement("h2");
	h2.appendChild(document.createTextNode(whenstring));
	container.appendChild(h2);
  if (i == 0)
  {
	var img = document.createElement("img");
	img.setAttribute("src", "http://www.shepherd.edu/musicweb/concerts/"+ googleTime +".jpg");
	img.setAttribute("title", title);
	container.appendChild(img);
  }
  var p = document.createElement("p");
	p.appendChild(document.createTextNode(content));
	container.appendChild(p);
			  }
			}
		  }
	    }); // end feed load
	  } // end calendar for loop
	} // end initialize()
}


/* The header on every page */
function header()
{
	document.write('<div id="topbar">');
	document.write('	<div id="minilogo">');
	document.write('		<a href="http://www.shepherd.edu"><img src="http://www.shepherd.edu/musicweb/img/su.jpg" alt="Shepherd University" /></a>');
	document.write('	</div>');
	document.write('</div>');
	document.write('<div id="header">');
	document.write('	<h1><a href="/musicweb">Shepherd University Music</a> <font style="font-size:10pt; line-height:20pt; color:#d49923;">Fully Accredited by the National Association of Schools of Music</font></h1>');
	document.write('	<div id="toolkit">');
	document.write('		<form method="get" name="searchform" action="http://www.google.com/u/shep" id="search">');
	document.write('			<fieldset>');
	document.write('				<a href="http://www.shepherd.edu/webinfo/people.html">People Search</a>');
	document.write('		<input name="q" type="text" id="searchtxt" value="Search Shepherd" maxlength="255" onfocus="if(this.value==\'Search Shepherd\')this.value=\'\';" onblur="if(this.value==\'\')this.value=\'Search Shepherd\';" /> ');
	document.write('				<input type="image" name="go" src="/musicweb/img/go.gif" alt="GO" id="go" />');
	document.write('			</fieldset>');
	document.write('		</form>');
	document.write('	</div>');
	document.write('</div>');
}

/* The footer on every page */
function footer()
{
	document.write('<div id="footer">');
	document.write('	<hr />');
	document.write('	<div id="blocksu">');
	document.write('		<a href="http://www.shepherd.edu"><img src="/musicweb/img/su.gif" alt="SU" width="41" height="40" /></a>');
	document.write('	</div>');
	document.write('	<div id="statement">');
 	document.write('   	<a href="/musicweb/index.htm" tppabs="index.htm">Shepherd University Department of Music</a>, | Frank Arts Center | P.O. Box 5000<br />');
	document.write('		Shepherdstown, WV 25443-5000 | (304) 876-5555 | (800) 344-5231 ext. 5555<br />');
	document.write('		Web Design and Production by <A HREF="erik_jones.html">Dr. Erik Jones</A><br />');
	document.write('	</div>');
	document.write('</div>');
}

/* The left-side navigation menu on every page */
function nav(section)
{
	document.write('<div id="nav">');
	document.write('<ul>');
	document.write('    <li id="prospective_nav"><a href="/musicweb/prospective.html">Prospective Students</a>');
	if (section=="prospective") {document.write('		<ul style="display: block;">');} else {document.write('<ul>');}
	document.write('	        <li><a href="/musicweb/questions_to_ask.html">Questions to Ask a School</a></li>');
	document.write('	        <li><a href="/musicweb/schedule_an_audition.html">Schedule an Audition</a></li>');
	document.write('	        <li><a href="/musicweb/information_request.html">Request Further Information</a></li>');
	document.write('	        <li><a href="/musicweb/audition_requirements.html">Audition Information</a></li>');
	document.write('	        <li><a href="/musicweb/success.html">Success Stories and Testimonials</a></li>');
	document.write('		</ul>');
	document.write('	</li>');
	document.write('    <li id="calendar_nav"><a href="/musicweb/concerts.html">Calendar of Concerts</a>');
	document.write('	</li>');	
	document.write('    <li id="news_nav"><a href="/musicweb/news.html">Latest News</a>');
	document.write('	</li>');	
	document.write('    <li id="ensembles_nav"><a href="/musicweb/ensembles.html">Ensembles and Productions</a>');
	if (section=="ensembles") {document.write('		<ul style="display: block;">');} else {document.write('<ul>');}
    document.write('        	<LI><A HREF="/musicweb/chamber_singers.html">Chamber Singers</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/gamelan.html">Gamelan</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/jazz_ensemble.html">Jazz Ensemble</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/marching_band.html">Marching Band</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/masterworks_chorale.html">Masterworks Chorale</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/mens_choir.html">Men&apos;s Choir</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/musical_theater.html">Musical Theater</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/opera_workshop.html">Opera Workshop</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/percussion_ensemble.html">Percussion Ensemble</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/piano_ensemble.html">Piano Ensemble</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/prep_orchestra.html">Preparatory Orchestra</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/two_rivers.html">Two Rivers Chamber Orchestra</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/wind_ensemble.html">Wind Ensemble</A></LI>');
    document.write('        	<LI><A HREF="/musicweb/womens_camerata.html">Women&apos;s Camerata</A></LI>');
	document.write('		</ul>');
	document.write('	</li>');	
 	document.write('   <li id="preparatory_nav"><a href="/musicweb/preparatory.html">Preparatory Program</a>');
	if (section=="preparatory") {document.write('		<ul style="display: block;">');} else {document.write('<ul>');}
	document.write('	        <li><a href="/musicweb/prep_orchestra.html">Preparatory Orchestra</a></li>');
	document.write('	        <li><a href="/musicweb/prep_chorus.html">Preparatory Chorus</a></li>');
	document.write('	        <li><a href="/musicweb/applied_lessons.html">Applied Music Lessons</a></li>');
	document.write('	        <li><a href="/musicweb/early_childhood.html">Early Childhood Music Program</a></li>');
	document.write('		</ul>');
	document.write('	</li>');
  	document.write('  <li id="current_nav"><a href="/musicweb/current.html">Current Students</a>');
	document.write('	</li>');
	document.write('    <li id="faculty_nav"><a href="/musicweb/faculty.html">Faculty</a>');
	document.write('	</li>');
 	document.write('   <li id="fom_nav"><a href="http://www.sufom.org">Friends of Music</a>');
	document.write('	</li>');
 	document.write('   <li id="preparatory_nav"><a href="/musicweb/masters.html">Masters in Music Education</a>');
	if (section=="masters") {document.write('		<ul style="display: block;">');} else {document.write('<ul>');}
	document.write('	        <li><a href="/musicweb/masters_requirements.html">Requirements</a></li>');
	document.write('	        <li><a href="/musicweb/masters_curriculum.html">Curriculum</a></li>');
	document.write('	        <li><a href="/musicweb/masters_apply.html">Apply</a></li>');
	document.write('	        <li><a href="/musicweb/masters_staff.html">Staff</a></li>');
	document.write('	        <li><a href="/musicweb/masters_testimonials.html">Testimonials</a></li>');
	document.write('		</ul>');
	document.write('	</li>');
 	document.write('   <li id="aboutus_nav"><a href="/musicweb/about.html">About Us</a>');
	document.write('	</li>');
 	document.write('   <li id="contactus_nav"><a href="/musicweb/contact.html">Contact Us / Stay in Touch</a>');
	document.write('	</li>');
	document.write('</ul>');
	document.write('</div>');
    if (section!="home") {document.write('<A HREF="http://travel.nytimes.com/2005/06/03/travel/escapes/03hour.html"><img src="/musicweb/img/nytimes.png" alt="A vibrant, cultural scene..." style="border-width: 0px; padding-top: 10px; margin-bottom: -50px;"/></A>');}
}

