
/**
 * All event objects should have three properties: date, speaker, and title. All three properties should be strings.
 * The date property should be a human-readable string like "April 19". You can abbreviate months. Including the year is optional.
 * 
 * Here is a sample declaration of an array of event objects:
 *
 * var eventArray = new Array(
 *   {
 *     date: 'October 31',
 *     speaker: 'Pinnochio',
 *     title: 'Anti-realism About Boyhood'
 *   },
 *   {
 *     date: 'Nov 6',
 *     speaker: 'Bilbo Baggins',
 *     title: 'TBA'
 *   }
 * );
 *
 * Be sure to punctuate everything correctly, as shown above. 
 * In particular, don't add a comma after the title property, or Internet Explorer won't like it.
 *
 */
var colloquia = new Array(
  {
    date: 'Sep 3',
    speaker: '<a href="http://web.gc.cuny.edu/philosophy/people/artemov.html">Sergei Artemov</a> (CUNY Graduate Center)',
    title: 'The Logic of Justification'
  },
  {
    date: 'Sep 10',
    speaker: '<a href="http://www.columbia.edu/cu/philosophy/fac-bios/cohen/faculty.html">Gerald Cohen</a> (Oxford; visiting at Columbia)',
    title: 'Rescuing Conservatism: A Defense of Existing Value'
  },
  {
    date: 'Sep 17',
    speaker: '<a href="http://philosophy.fas.nyu.edu/object/peterunger">Peter Unger</a> (NYU)',
    title: 'Beyond Inanity: Making Mainstream Philosophy Relevant to Concrete Reality'
  },
  {
    date: 'Sep 24',
    speaker: '<a href="http://philosophy.fas.nyu.edu/object/sharonstreet">Sharon Street</a> (NYU)',
    title: 'In Defense of Future Tuesday Indifference'
  },
  {
    date: 'Oct 1',
    speaker: 'No Colloquium',
    title: ''
  },
  {
    date: 'Oct 8',
    speaker: 'No Colloquium',
    title: ''
  },
  {
    date: 'Oct 15',
    speaker: 'Jeffrey Smith (St. John\'s)',
    title: 'Rousseau on Desire'
  },
  {
    date: 'Oct 22',
    speaker: '<a href="http://web.princeton.edu/sites/philosph/bios/rosen.htm">Gideon Rosen</a> (Princeton)',
    title: 'Metaphysical Dependence'
  },
  {
    date: 'Oct 29',
    speaker: '<a href="http://www.columbia.edu/cu/philosophy/fac-bios/danto/faculty.html">Arthur Danto</a> (Columbia)',
    title: 'From Photography to Philosophy: Two Moments of Post-Traditional Art'
  },
  {
    date: 'Nov 5',
    speaker: '<a href="http://philosophy.fas.nyu.edu/object/mattevans">Matthew Evans</a> (NYU)',
    title: 'Plato\'s Metaphysics of Meaning'
  },
  {
    date: 'Nov 12',
    speaker: '<a href="http://www.columbia.edu/cu/philosophy/fac-bios/rovane/faculty.html">Carol Rovane</a> (Columbia)',
    title: 'TBA'
  },
  {
    date: 'Nov 19',
    speaker: '<a href="http://web.princeton.edu/sites/philosph/bios/harman.htm">Gilbert Harman</a> (Princeton)',
    title: 'Naturalism in Moral Philosophy'
  },
  {
    date: 'Nov 26',
    speaker: 'No Colloquium',
    title: ''
  },
  {
    date: 'Dec 3',
    speaker: '<a href="http://philosophy.fas.nyu.edu/object/samuelscheffler">Samuel Scheffler</a> (NYU)',
    title: 'TBA'
  },
  {
    date: 'Dec 10',
    speaker: '<b>Dean Kolitch Lecture</b><br><a href="http://web.gc.cuny.edu/philosophy/people/orenstein.html">Alex Orenstein</a> (CUNY Graduate Center)',
    title: 'Quine versus Quine'
  }
  );
  
var studentEvents = new Array(
  {
    date: 'April 19, 1981',
    speaker: 'Felicia Morrow',
    title: 'It\'s a boy!'
  }
);

/**
 * getUpcomingEvents
 *
 * Find all events within a specified time frame in an array of events (e.g., all colloquia in the next three weeks).
 *
 * Sample usage: var upcomingEvents = getUpcomingEvents(colloquia,3)
 * This will create an array called upcomingEvents. The array will contain all events in the
 * colloquia array within three weeks of the current date. You can then use that array to
 * print details for all of those events.
 *
 * @param eventArray
 *   An array containing event objects with the following properties: date (String), speaker (String), title (String)
 * @param weeks
 *   A number; the function searches for events within this many weeks.
 *
 * @return
 *   An array of the event objects (date, speaker, title) less than the specified number of weeks from now.
 */
function getUpcomingEvents(eventArray,weeks) {

  var outputArray = new Array();
  var today = new Date();
  var todayTime = today.getTime();
  var oneWeek = 1000*60*60*24*7;
  for (i=0; i<eventArray.length; i++) {
    dateString = ( (eventArray[i].date.match(',')) ? eventArray[i].date : eventArray[i].date +', '+ today.getFullYear());
    eventArray[i].date = new Date(dateString);
    dateTime = eventArray[i].date.getTime();
    if ( (dateTime>todayTime) && ((dateTime - todayTime) < (oneWeek*weeks)) ) {
      outputArray.push(eventArray[i]);
    }
  }
  
  return outputArray;
}


function printUpcomingEventList(upcomingArray,listTitle) {
  if (upcomingArray.length<1) {
    return;
  }
  else {
	var output = '<h5>'+ listTitle +'<\/h5><ul id="upcomingColloquiumList">';
	for (n in upcomingArray) {
	  var event = upcomingArray[n];
	  if (event.title!='TBA' && event.title!='') {
	    event.title = '"'+ event.title.replace('"','\'') +'"';
	  }
	  output +='<li class="upcomingColloquiumListing">';
	  output +='<div class="upcomingColloquiumDate">'+ event.date.toString().substr(4,6) +'<\/div>';
	  output +='<div class="upcomingColloquiumSpeaker">'+ event.speaker +'<\/div>';
	  output +='<div class="upcomingColloquiumTitle">'+ event.title +'<\/div>';
	  output +='<\/li>';
	}
	output +='<\/ul>';
	
	return output;
  }
}