function gCalEvent(xmlEvent) {

	var SHORT_MONTH_NAMES = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var SHORT_DAY_NAMES = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

	this.parseXmlEvent = function() {
		var today = new Date();

		if (xmlEvent) {
			this.eventId = xmlEvent.getElementsByTagName("eventId")[0].childNodes[0].data;
			this.startDate = this.setDate(xmlEvent.getElementsByTagName("startDate")[0].childNodes[0].data);
			if (xmlEvent.getElementsByTagName("startTime")[0].childNodes.length > 0)
				this.startTime = xmlEvent.getElementsByTagName("startTime")[0].childNodes[0].data;
			this.endDate = this.setDate(xmlEvent.getElementsByTagName("endDate")[0].childNodes[0].data);
			if (xmlEvent.getElementsByTagName("endTime")[0].childNodes.length > 0)
				this.endTime = xmlEvent.getElementsByTagName("endTime")[0].childNodes[0].data;
			this.allDay = xmlEvent.getElementsByTagName("allDay")[0].childNodes[0].data;
			this.title = xmlEvent.getElementsByTagName("title")[0].childNodes[0].data;
			this.where = xmlEvent.getElementsByTagName("location")[0].childNodes[0].data;
			this.calendar = xmlEvent.getElementsByTagName("calendar")[0].childNodes[0].data;
			this.yearly = xmlEvent.getElementsByTagName("yearly")[0].childNodes[0].data;
			if (xmlEvent.getElementsByTagName("firstOccuranceYear")[0].childNodes.length > 0)
				this.firstOccuranceYear = xmlEvent.getElementsByTagName("firstOccuranceYear")[0].childNodes[0].data;
			if (xmlEvent.getElementsByTagName("details")[0].childNodes.length > 0)
				this.details = xmlEvent.getElementsByTagName("details")[0].childNodes[0].data;
			if (this.startDate.getDate() == today.getDate() && this.startDate.getMonth() == today.getMonth() && this.startDate.getFullYear() == today.getFullYear())
				this.isTodayEvent = true;
			//this.debug();
		}
	}

	this.setDate = function(timeValue) {
		var year = timeValue.substring(0,4);
		var month = timeValue.substring(5,7);
		var day = timeValue.substring(8,10);
		var dateObj = new Date ( year, month-1, day);

		return dateObj;
	}

	this.debug = function() {
		alert("eventId: " + this.eventId + "\n" + 
			"startDate: " + this.startDate + "\n" + 
			"startTime: " + this.startTime + "\n" + 
			"endDate: " + this.endDate + "\n" + 
			"endTime: " + this.endTime + "\n" +
			"allDay: " + this.allDay + "\n" +
			"title: " + this.title + "\n" + 
			"where: " + this.where + "\n" + 
			"calendar: " + this.calendar + "\n" + 
			"yearly: " + this.yearly + "\n" + 
			"firstOccuranceYear: " + this.firstOccuranceYear + "\n" + 
			"details: " + this.details + "\n");
	}

	this.getShortDisplayTime = function(d) {
		var hours = d.substring(0,2);
		var minutes = d.substring(3,5);
		var hourText;
		var minuteText = "";
		var ampmText = "a";
		var displayTime = "";

		if (this.allDay == "Y")
			return "";

		if (minutes != 0)
			minuteText = ":" + minutes;

		if (hours == 0)
			hourText = "12";
		else if (hours == 12) {
			hourText = "12";
			ampmText = "p";
		}
		else if (hours > 12) {
			hourText = (hours - 12) + "";
			ampmText = "p"
		}
		else
			hourText = hours + "";

		if (hourText.length == 2 && hourText.substring(0,1) == "0")
			hourText = hourText.substring(1,2);

		return hourText + minuteText + ampmText + " ";
	}

	this.getLongDisplayTime = function(d) {
		var hours = d.substring(0,2);
		var minutes = d.substring(3,5);
		var hourText;
		var minuteText = "";
		var ampmText = "am";
		var displayTime = "";

		if (this.allDay == "Y")
			return "";

		minuteText = ":" + minutes;

		if (hours == 0)
			hourText = "12";
		else if (hours == 12) {
			hourText = "12";
			ampmText = "pm";
		}
		else if (hours > 12) {
			hourText = (hours - 12) + "";
			ampmText = "pm"
		}
		else
			hourText = hours + "";

		if (hourText.length == 2 && hourText.substring(0,1) == "0")
			hourText = hourText.substring(1,2);

		return hourText + minuteText + ampmText;
	}

	this.getShortStartDate = function() {
		return this.getShortDisplayTime(this.startTime);
	}

	this.buildStartWhenText = function(includeEndText) {
		var whenText = "";

		whenText = SHORT_DAY_NAMES[this.startDate.getDay()] + " " + SHORT_MONTH_NAMES[this.startDate.getMonth()] + " " + this.startDate.getDate() + " ";
		if (this.startTime.length > 0)
			whenText += this.getLongDisplayTime(this.startTime);
		whenText += " to ";
		if (includeEndText) 
			whenText += this.getLongDisplayTime(this.endTime);

		return whenText;
	}

	this.buildEndWhenText = function() {
		var whenText = "";

		whenText = SHORT_DAY_NAMES[this.endDate.getDay()] + " " + SHORT_MONTH_NAMES[this.endDate.getMonth()] + " " + this.endDate.getDate() + " ";
		if (this.endTime.length > 0)
			whenText += this.getLongDisplayTime(this.endTime);

		return whenText;
	}

	this.buildHoverDiv = function(calObjLongName, eventId, hoverTextStyle, calObjShortLabel) {
		var hoverDiv = document.createElement("div");
		var headerP = document.createElement("p");
		var headerText = document.createTextNode(calObjLongName);
		var startEndSameDay = (this.startDate.getDay() == this.endDate.getDay());

		hoverDiv.className = "leightbox";
		//hoverDiv.className = "hoverDiv";
		hoverDiv.id = "lightbox" + eventId;
		headerP.className = hoverTextStyle;
		headerP.appendChild(headerText);
		hoverDiv.appendChild(headerP);
		
		var whatP =  document.createElement("p");
		var whatText = document.createTextNode("What: " + this.title);
		whatP.className = "hoverp";
		whatP.appendChild(whatText);
		hoverDiv.appendChild(whatP);

		var startWhenP =  document.createElement("p");
		var startWhenText = document.createTextNode("When: " + this.buildStartWhenText(startEndSameDay));
		startWhenP.className = "hoverp";
		startWhenP.appendChild(startWhenText);
		hoverDiv.appendChild(startWhenP);

		if (!startEndSameDay) { 
			var endWhenP =  document.createElement("p");
			var endWhenText = document.createTextNode(this.buildEndWhenText());
			endWhenP.className = "hoverp2";
			endWhenP.appendChild(endWhenText);
			hoverDiv.appendChild(endWhenP);
		}

		if (this.where != "") {
			var whereP =  document.createElement("p");
			var whereText = document.createTextNode("Where: " + this.where);
			whereP.className = "hoverp";
			whereP.appendChild(whereText);
			hoverDiv.appendChild(whereP);
		}
		
		if (this.details != "") {
			var descP =  document.createElement("p");
			var descText = document.createTextNode("Description: " + this.details);
			descP.className = "hoverp";
			descP.appendChild(descText);
			hoverDiv.appendChild(descP);
		}

		var closeButtonP =  document.createElement("p");
		closeButtonP.className = "hoverImgP";

		var closeButtonAnchor = document.createElement("a");
		closeButtonAnchor.className = "lbAction";
		closeButtonAnchor.href = "#";
		closeButtonAnchor.rel = "deactivate";
		closeButtonAnchor.title = "Close";

		var closeButtonImg = document.createElement("img");
		closeButtonImg.src = "images/close" + calObjShortLabel + ".gif";
		closeButtonImg.border = "0";

		var afterButtonBR = document.createElement("br");
		var afterButtonBR2 = document.createElement("br");

		closeButtonAnchor.appendChild(closeButtonImg);

		// Add the anchor to the paragraph and the paragraph to the div
		closeButtonP.appendChild(closeButtonAnchor);
		closeButtonP.appendChild(afterButtonBR);
		closeButtonP.appendChild(afterButtonBR2);
		hoverDiv.appendChild(closeButtonP);

		//<a href="#" class="lbAction" rel="deactivate"><IMG SRC="closeKids.gif" WIDTH="44" HEIGHT="18" BORDER="0" ALT=""></a>

		return hoverDiv;
	}

	this.writeUpcomingEvent = function(eventsDiv) {

		// Write the time of the event
		var dateText = document.createTextNode(getShortDate(this.startDate, true) + " - " + this.getLongDisplayTime(this.startTime) + " to " + this.getLongDisplayTime(this.endTime));
		var dateTextBR = document.createElement("br");
		eventsDiv.appendChild(dateText);
		eventsDiv.appendChild(dateTextBR);

		// Create the div for this event
		var upcomingEventDiv = document.createElement("div");
		upcomingEventDiv.className = "upcomingEventDiv";

		/****** Create the category, title and orange arrow ******/
		// Create the paragraph
		var categoryTitleP = document.createElement("p");

		// Create the anchor (ie. link)
		var categoryTitleAnchor = document.createElement("a");
		categoryTitleAnchor.id = "anchor_" + this.eventId;
		categoryTitleAnchor.href = "javascript:showHideEventDetails(" + this.eventId + ");";
		categoryTitleAnchor.title = "Show event detail";

		// Create the category, br and title
		var category = document.createTextNode(this.calendar + " Event");
		var categoryTitleAnchorBR = document.createElement("br");
		var title = document.createTextNode(this.title + " ");

		// Create the arrow image
		var arrowImg = document.createElement("img");
		arrowImg.src = "images/right-arrow.gif";
		arrowImg.border = "0";

		// Add the category, title and br, and arrow image to the anchor
		categoryTitleAnchor.appendChild(category);
		categoryTitleAnchor.appendChild(categoryTitleAnchorBR);
		categoryTitleAnchor.appendChild(title);
		categoryTitleAnchor.appendChild(arrowImg);

		// Add the anchor to the paragraph
		categoryTitleP.appendChild(categoryTitleAnchor);

		// Add the paragraph to the div
		upcomingEventDiv.appendChild(categoryTitleP);

		// Add the div to the eventDiv
		eventsDiv.appendChild(upcomingEventDiv);

		/****** Done creating the category, title and orange arrow ******/

		/****** Create the div for displaying the 'where' and the 'details'******/
		var upcomingEventDetailDiv = document.createElement("div");
		upcomingEventDetailDiv.className = "upcomingEventDetailDiv";
		upcomingEventDetailDiv.id = "details_" + this.eventId;
		upcomingEventDetailDiv.style.display = "none";
		upcomingEventDetailDiv.style.visibility = "hidden";

		// Create the 'where'
		if (this.where.length > 0) {
			var whereP = document.createElement("p");
			var whereText = document.createTextNode("Where: " + this.where);
			whereP.appendChild(whereText);
			upcomingEventDetailDiv.appendChild(whereP);

			var whereBR = document.createElement("br");
			whereBR.className = "shortBr";
			upcomingEventDetailDiv.appendChild(whereBR);
		}

		// Create the details
		if (this.details.length > 0) {
			var detailsP = document.createElement("p");
			var detailsLabel = document.createTextNode("Details:");
			var detailsBR = document.createElement("br");
			var detailsText = document.createTextNode(this.details);
			detailsP.appendChild(detailsLabel);
			detailsP.appendChild(detailsBR);
			detailsP.appendChild(detailsText);

			upcomingEventDetailDiv.appendChild(detailsP);
		}

		// See if there is no 'where' or details
		if (this.where.length == 0 && this.details.length == 0) {
			var noDetailsText = document.createTextNode("No details for this event");
			upcomingEventDetailDiv.appendChild(noDetailsText);
		}

		eventsDiv.appendChild(upcomingEventDetailDiv);

		/****** Done creating the div for displaying the 'where' and the 'details'******/

		// Add a seperator
		var seperatortDiv = document.createElement("div");
		seperatortDiv.className = "separator";
		eventsDiv.appendChild(seperatortDiv);		
	}

	this.writeListViewDetail = function(listViewDetailDiv, calShortLabel) {
		var bulletDiv = document.createElement("div");
		bulletDiv.className = "listViewDetailBullet";
		var bulletImg = document.createElement("img");
		bulletImg.src = "images/bullet" + calShortLabel + ".gif";
		bulletImg.width = "6";
		bulletImg.height = "12";
		bulletImg.border = "0";
		bulletDiv.appendChild(bulletImg);
		listViewDetailDiv.appendChild(bulletDiv);

		var textDiv = document.createElement("div");
		textDiv.className = "listViewDetailText";

		var headerText = document.createTextNode(this.getLongDisplayTime(this.startTime) + " to " + this.getLongDisplayTime(this.endTime) + " - " + this.title + " (" + this.calendar + " Event)");
		textDiv.appendChild(headerText);

		// Create the 'where'
		if (this.where.length > 0) {
			var whereP = document.createElement("p");
			var whereText = document.createTextNode("Where: " + this.where);
			whereP.appendChild(whereText);
			textDiv.appendChild(whereP);
		}

		// Create the details
		if (this.details.length > 0) {
			var detailsP = document.createElement("p");
			var detailsText = document.createTextNode("Details: " + this.details);
			detailsP.appendChild(detailsText);
			textDiv.appendChild(detailsP);
		}
		listViewDetailDiv.appendChild(textDiv);

		var clearDiv = document.createElement("div");
		clearDiv.className = "clearDiv";
		listViewDetailDiv.appendChild(clearDiv);
	}

	this.eventId = "";
	this.startDate = "";
	this.startTime = "";
	this.endDate = "";
	this.endTime = "";
	this.allDay = "";
	this.title = "";
	this.where = "";
	this.calendar = "";
	this.yearly = "";
	this.firstOccuranceYear = "";
	this.details = "";
	this.isTodayEvent = false;

	this.parseXmlEvent();
} 