function calendarEvent(){
  this.speaker = '';
  this.startTime = '';
  this.bookingLink = '';
  this.setStartDate = function(theDate){this.startDate = new Date(theDate)};
  this.getStartDate = function(){return(this.startDate.getDayName() + ' ' + this.startDate.getDate() + ' ' + this.startDate.getMonthName() + ' ' + this.startDate.getFullYear())};
  //this.getIsoDate = function(theDate){return(theDate.getFullYear() + '-' + theDate.getMonth() + '-' + theDate.getDate())};
  this.setTitle = function(title){this.title = title};   
  this.setDescription = function(description){this.description = description};
  this.setClass = function(className){this.className = className};
  this.setUrl = function(url){this.url = url};
  this.setStartTime = setStartTime;
  this.setBookingLink = function(bookingLink){this.bookingLink = bookingLink};
  this.setEndTime = function(endTime){this.endTime = endTime};
  this.getStartTime = function(){return this.startTime};
  this.getEndTime = function(){return this.endTime};  
  this.getTime = getTime
  this.setSpeaker = function(speaker){this.speaker = speaker};
  this.getSpeaker = function(){return this.speaker};
  this.getBookingLink = function(){return this.bookingLink};
  this.isToday = isToday;
  this.show = showEvent;
  this.isThisType = isThisType;
  this.showSpeaker = showSpeaker;
  
  this.img = '';
  this.setImage = function(i){
    this.img = i;
    //console.log(i);
    }    
  this.getImage = getImage;
  this.setField = setField;
  
  }
  
function setStartTime(startTime){
  if(startTime != ''){
    this.startTime = startTime;
	}
  else{
	this.startTime = '';
	}
  }

function getTime(){
	if(this.getStartTime() != ''){
	  return ', '+ this.startTime;
	  }
	else{
	  return '';
	  }
	}
  
function getImage(){
  if(this.img != ''){
    return('<div class="eventImage" style="display: none;"><img src="' + this.img + '" /></div>');
    }
  else{
    return('<div class="eventImagePlaceholder" style="display: none;"></div>');
    }
  }
  
function setField(){
  var theUrl = this.url.toUpperCase();
 	//if(theUrl.indexOf('MUSIC') > -1 || theUrl.indexOf('SYS_FOLDERID=35172') > -1){
		if(theUrl.indexOf('MUSIC') > -1 || theUrl.indexOf('SYS_FOLDERID=35172') > -1 || theUrl.indexOf('SYS_FOLDERID=33465') > -1 ){
	// if(theUrl.indexOf('MUSIC') > -1){
    this.className += ' music';
    }
  else if(theUrl.indexOf('DANCE') > -1 || theUrl.indexOf('SYS_FOLDERID=35278') > -1 || theUrl.indexOf('SYS_FOLDERID=33467') > -1){
    this.className += ' dance';
    }
  else if(theUrl.indexOf('FILM') > -1 || theUrl.indexOf('SYS_FOLDERID=36056') > -1 || theUrl.indexOf('SYS_FOLDERID=33471') > -1){
    this.className += ' film';
    }
  else if(theUrl.indexOf('THEATRE') > -1 || theUrl.indexOf('SYS_FOLDERID=36037') > -1){
    this.className += ' theatre';
    }
  else if(theUrl.indexOf('LITERATURE') > -1 || theUrl.indexOf('SYS_FOLDERID=36075') > -1){
    this.className += ' literature';
    }
	else if(theUrl.indexOf('VISUAL') > -1 || theUrl.indexOf('SYS_FOLDERID=33475') > -1 || theUrl.indexOf('SYS_FOLDERID=36095') > -1){
    this.className += ' visual';
    }
  //console.log(this.className);  
  }

  
function isToday(theDate){
  if(theDate != ''){
    theDate = new Date(theDate);
    return(justDate(theDate) == justDate(this.startDate));
	}  
  }
  
function showSpeaker(){
  if(this.getSpeaker() != ''){
    return '<p class="keynoteSpeaker" style="margin-bottom: 0.4em;"><strong>Speaker:</strong> '+this.getSpeaker()+'</p>';
    }
  else{
	return '';
    }
  }

function showEvent(element){
  var eventElement = $('#'+element);    
	
  if(dateShowing == undefined || dateShowing == '' || dateShowing != this.getStartDate()){
	eventElement.append('<h2>' + this.getStartDate() +  '</h2>');
	dateShowing = this.getStartDate();
    }  
	
   // Code for event booking link added 30 August 2011
   var bookingLink = '';
   if(this.getBookingLink() != ''){
     bookingLink = '<span class="bookingLink" style="display: none;"><a href="'+this.getBookingLink()+ '">Buy tickets</a></span>';
	 }

   
  
   // Updated version, added 30 August 2011
   eventElement.append('<div class="vevent ' + this.className + '">' + this.getImage() + '<h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr><span class="eventTime">'+ this.getTime() + '</span></p>' + this.showSpeaker() + '<p class="eventDescription description">'+this.description+'</p><p class="highlightMore" style="display:none;"><span class="moreLink"><a  href="'+ this.url + '">More</a> <span style="font-size: 9px;">&#9658;</span></span>' + bookingLink + '</p></div>');
  
  //eventElement.append('<div class="vevent ' + this.className + '">' + this.getImage() + '<h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr><span class="eventTime">'+ this.getTime() + '</span></p>' + this.showSpeaker() + '<p class="eventDescription description">'+this.description+'</p><p class="highlightMore" style="display:none;"><a  href="'+ this.url + '">More</a> <span style="font-size: 9px;">&#9658;</span></p></div>');
  
 //eventElement.append('<div class="vevent ' + this.className + '">' + this.getImage() + '<h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr></p>' + this.showSpeaker() + '<p class="eventDescription description">'+this.description+'</p><p class="highlightMore" style="display:none;"><a  href="'+ this.url + '">More</a> <span style="font-size: 9px;">&#9658;</span></p></div>');
  
  
   
 // eventElement.append('<div class="vevent ' + this.className + '">' + this.getImage() + '<h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr></p>' + this.showSpeaker() + '<p class="eventDescription description">'+this.description+'</p></div>');
  
  //eventElement.append('<div style="clear: both; min-height: 100px;" class="vevent ' + this.className + '"><div class="eventImage" style="float: left; margin-right: 10px;"><img src="' + this.img + '" /></div><h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr></p>' + this.showSpeaker() + '<p class="eventDescription description">'+this.description+'</p></div>');
  //eventElement.append('<div class="vevent ' + this.className + '"><h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr></p>' + this.showSpeaker() + '<p class="eventDescription description">'+this.description+'</p></div>');
  //eventElement.append('<div class="vevent ' + this.className + '"><h3 class="summary"><a href="'+ this.url + '">' + this.title + '</a></h3><p class="startDate"><abbr class="dtstart" title="' + this.startDate.getIsoDate() + '">' + this.getStartDate() + '</abbr></p><p class="eventDescription description">'+this.description+'</p></div>');
  //eventElement.append('<div class="vevent ' + this.className + '"><h3><a href="'+ this.url + '">' + this.title + '</a></h3><p class="eventDescription">'+this.description+'</p></div>');

  
  
  
  //var eventElement = document.createElement('div');
  
  /*eventElement.setAttribute('class', this.className); */
  //addHeading(eventElement, 3, this.title);
  
  
  
  /*
  var eventLink = document.createElement('a');
  eventLink.setAttribute('href', this.url);
  var theTitle = document.createTextNode(this.title);
  eventLink.appendChild(theTitle);
  var titleElement = document.createElement('h3');
  titleElement.appendChild(eventLink);
  eventElement.appendChild(titleElement);  
  */
  
  //addParagraph(eventElement, this.getStartDate());  
  //addParagraph(eventElement, this.description);
  //document.getElementById(element).appendChild(eventElement);
  }


function isThisType(typeString){
  if(typeString != ''){
    typeString = typeString.substring(0,eventTypeQuery.length-1);
    var typeArray = typeString.split(',');
	for(var i=0; i< typeArray.length; i++){
	  if(this.className.indexOf(typeArray[i]) > -1)return true;
	  }
	return false;
    }
  }





















function addHeading(parent, level, text){
  var headingLevel = 'h' + level;
  var heading = document.createElement(headingLevel);
  var headingText = document.createTextNode(text);
  heading.appendChild(headingText);
  parent.appendChild(heading);
  }

function addParagraph(parent, text){
  var para = document.createElement('p');
  var paraText = document.createTextNode(text);
  para.appendChild(paraText);
  parent.appendChild(para);
  }





Date.prototype.getMonthName = function(month){
  var monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');    
  return monthNames[this.getMonth()];
  }

Date.prototype.getDayName = function(day){
  var dayNames = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  return dayNames[this.getDay()];
  }

Date.prototype.getIsoDate = function(theDate){
  var theMonth = this.getMonth() + 1;
  theMonth = theMonth.toString();
  if(theMonth.length < 2) theMonth = '0' + theMonth;  
  var theDay = this.getDate().toString();
  if(theDay.length < 2) theDay = '0' + theDay;
  return this.getFullYear() + '-' + theMonth + '-' + theDay;
  }

Date.prototype.getFullDate = function(theDate){
	return this.getDayName() + ' ' + this.getDate() + ' ' + this.getMonthName() + ' ' + this.getFullYear();
    }


    
function justDate(dateObject){
  return dateObject.getFullYear()+ '' + dateObject.getMonth()+ '' + dateObject.getDate();
  }
  
 
 
