
var YearOverview = function(el, year, stopAt, direction, url, months) {
	this.el = document.getElementById(el);
	this.year = year;
	if (stopAt != null) {
		var stops = stopAt.split("-");
		this.stopAt = {
			year: parseInt(stops[0]),
			month: parseInt(stops[1])
		};
	}
	this.direction = direction;
	this.url = url;
	
	this.months = months || ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	
	if (this.stopAt == null || (this.direction == 1 && this.stopAt.year <= year) || (this.direction == -1 && this.stopAt.year >= year)){
		this.initializeDom();
	}
}

YearOverview.prototype.initializeDom = function() {
	var anchor = document.createElement("a");
	anchor.href = "#";
	anchor.innerHTML = "<img src=\"/images/calendar/event_calendar_months.gif\" title=\"All months\" alt=\"All months\"/>";
	anchor.className = "months";
	anchor.onclick = function() {
		// show list, return false
		
		var el = document.getElementById('event-calendar-month-list');
		
		if (el.style.display == "none") {
			el.style.display = "block";
			this.className = "months-active";
		} else {
			el.style.display = "none";
			this.className = "months"
		}
		
		return false;
	};
	
	var monthsList = document.createElement("ul");
	monthsList.id = "event-calendar-month-list";
	monthsList.style.display = "none";
	
	for (var i = 0; i < this.months.length; i++) {
		if (this.stopAt != null && this.direction != 0) {
			if (this.direction == -1) { // hide future
				if ((this.year == this.stopAt.year) && ((i+1) >= this.stopAt.month) || (this.year > this.stopAt.year)) continue;
			} else if (this.direction == 1) { // hide past
				if ((this.year == this.stopAt.year) && ((i) < this.stopAt.month) || (this.year < this.stopAt.year)) continue;
			}
		}
		
		var li = document.createElement("li");
		
		var liA = document.createElement("a");
		liA.href = this.url + "&calendar=" + this.year + "-" + (i < 9 ? "0" : "") + (i + 1);
		liA.innerHTML = this.months[i] + " " + this.year;
		
		li.appendChild(liA);
		monthsList.appendChild(li);
	}
	
	this.el.appendChild(anchor);
	this.el.appendChild(monthsList);
}

