(function($) {

	$.fullCalendar.bwCalFeed = function(feedUrl) {
		return function(start, end, callback) {
			var params = {
				'start-min': $.fullCalendar.formatDate(start, 'u'),
				'start-max': $.fullCalendar.formatDate(end, 'u'),
				'singleevents': true,
				'max-results': 9999
			};
			
			$.ajax({
				type: "GET",
				url: feedUrl,
				dataType: "xml",
				success: function(data){
					var events = [];
					$(data).find("entry").each(function(){
						var start = $.fullCalendar.parseISO8601($(this).find("startTime").text(), true),
							end = $.fullCalendar.parseISO8601($(this).find("endTime").text(), true),
							allDay = $(this).find("startTime").text().indexOf('T') == -1,
							url = $(this).find("url").text(),
							id = $(this).find("id").text(),
							title = $(this).find("title").text(),
							location = $(this).find("location").text(),
							description = $(this).find("description").text();
						if (allDay) {
							$.fullCalendar.addDays(end, -1); // make inclusive
						}
						events.push({
							id: id,
							title: title,
							url: url,
							start: start,
							end: end,
							allDay: allDay,
							location: location,
							description: description
						});							 
					});
					callback(events);
				}
			  });
		}
		
	}

})(jQuery);
