Date.prototype.getMonthName = function(){
		var m = ['January','February','March','April','May','June','July', 'August','September','October','November','December'];
		return m[this.getMonth()];
	}
	
Date.prototype.getAMPMHour = function(){
	var hour = this.getHours();
	if(hour < 12){
		return ((hour == 0)?'12':hour) + ' AM';
	} else {
		return ((hour == 12)?hour:hour - 12) + ' PM';
	}
}
	
	function Calendar(){
		this.id;
		this.month;
		this.year;
		this.startDay;
		this.daysInMonth;
		this.startDate;
		this.events;
		this.dayStyles;
		this.dayHours;
		this.requiresMore = false;
		this.openMonth;
		this.openDay;
		this.closeMonth;
		this.closeDay;
		
		this.loadData = function(json){
			//Purpose of this function is to quick load data into the calendar...
			if(json.month !== undefined)
				this.month = json.month 
			if(json.year !== undefined)
				this.year = json.year;
			if(json.events !== undefined)
				this.events = json.events;
			else
				this.events = Array();
			if(json.dayStyles !== undefined)
				this.dayStyles = json.dayStyles;
			else
				this.dayStyles = Array();
			if(json.openHours !== undefined)
				this.dayHours = json.openHours;
			else
				this.dayHours = Array();
			if(json.openDay !== undefined){
				openDate = new Date(json.openDay);
				this.openMonth = openDate.getMonth();
				this.openDay = openDate.getDate();
			} else {
				this.openMonth = 8;
				this.openDay = 1;
			}
			if(json.closeDay !== undefined){
				closeDate = new Date(json.closeDay);
				this.closeMonth = closeDate.getMonth();
				this.closeDay = closeDate.getDate();
			} else {
				this.closeMonth = 10;
				this.closeDay = 30;
			}
		}
		
		this.render = function(){
			//Check that all of our values are defined:
			if(this.month === undefined){
				this.month = new Date().getMonth();
			}
			if(this.year === undefined){
				this.year = new Date().getFullYear();
			}
			
			this.daysInMonth = 32 - new Date(this.year, this.month, 32).getDate();
			this.startDay = new Date(this.year, this.month, 1).getDay();
						
			strHTML = this.renderHeader() + this.renderCalendar();
			if(this.requiresMore){
				strHTML += this.renderMoreBox();
			}
			return strHTML;
			
		}
		
		this.renderHeader = function(){
			var strHTML = '';
			strHTML += '<div id="monthHeader">';
				strHTML += '<span class="currentMonth">' + new Date(this.year, this.month, 1).getMonthName() + ' ' + this.year + '</span>';
				//Limits are september -> december.
				if(this.month -1 >= this.openMonth) {
					strHTML += '<a class="prevMonth" href="javascript:void(0);">&lt;&lt; ' + new Date(this.year, this.month - 1, 1).getMonthName() + '</a>';
				}
				if(this.month + 1 <= this.closeMonth)
					strHTML += '<a class="nextMonth" href="javascript:void(0);">' + new Date(this.year, this.month + 1, 1).getMonthName() + ' &gt;&gt;</a>';
			strHTML += '</div>';
			
			return strHTML;
		}
		
		this.renderCalendar = function(){
			//Array of dates:
			var daysOfWeek = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
			//our opening tag:
			var strHTML = '<table' + ((this.id !== undefined)?' id="' + this.id:'') + '>';
			//The calendar header:
			strHTML += '<thead>';
			strHTML += '<tr>';
			for(day in daysOfWeek){
				//Why aren't these table headers?
				strHTML += '<td class="columnHeading">' + daysOfWeek[day] + '</td>';
			}
			strHTML += '</tr>';
			//Now build the actual calendar:
			strHTML += '<tbody>';
				//Build our first row:
				strHTML += '<tr>';
				for(spaces = 0; spaces < this.startDay; spaces++){
						strHTML += '<td></td>';
				}
				for(today = 1; today <= this.daysInMonth; today++){
					if((today + this.startDay) % 7 == 1){
						strHTML += '</tr><tr>';
					}
					strHTML += '<td' + (((this.dayStyles[(today + this.startDay) % 7] !== undefined) && !((this.openMonth == this.month && this.openDay > today) || (this.closeMonth == this.month && this.closeDay < today)))?' class="' + this.dayStyles[(today + this.startDay) % 7] + '"': '') + '><div id="'  + today + '" class="monthViewCell ' + ((this.events[today] === undefined)?'no_events':'has_events') + '"><ul><li class="day">' + today + '</li>'
					if((this.dayHours[(today + this.startDay) % 7] !== undefined) && !((this.openMonth == this.month && this.openDay > today) || (this.closeMonth == this.month && this.closeDay < today))){
						strHTML += '<li>' + this.dayHours[(today + this.startDay) % 7]['open'] + ' - ' + this.dayHours[(today + this.startDay) % 7]['close'] + '</li>';
					}
					if(this.events[today] !== undefined){
						for(var event in this.events[today]){
							if(event == 4 && this.events[today].length > 4){
								strHTML += '<li><a id="more' + today + '" href="javascript:void(0);" class="more">More...</a></li>';
								this.requiresMore = true;
								break;
							}
							eventDate = new Date(this.events[today][event].eventDate);
							strHTML += '<li><a id="event' + this.events[today][event].id + '" class="event" href="javascript:void(0);">' + eventDate.getAMPMHour() + ' ' + this.events[today][event].title + '</a></li>';
						}
					}
					strHTML += '</ul></td>';
				}
				strHTML += '</tr>';
				
			strHTML += '</tbody>';
			strHTML += '</table>';
			return strHTML;
		}
		
		this.renderMoreBox = function(){
			strHTML = '<div id="calMore" class="moreBox" style="display:none;"><h4 class="title">Reservations</h4><a href="javascript:void(0);" class="close">X</a><ul id="eventList"></ul></div>';
			return strHTML;
		}
		
	}
