function Slideshow(id, moveMode, moveTime) {
	var object = this;
	this.id = id;
	this.layer = document.getElementById('slideshow'+id);
	
	this.elements = new Array();
	
	this.inFront = 0;
	
	this.maxWidth = 0;
	this.maxHeight = 0;
	
	
	this.moveMode = (typeof moveMode != 'undefined') ? moveMode.split('.') : new Array('top', 'top');
	this.moveTime = (typeof moveTime != 'undefined') ? moveTime : 1000;
	this.toolbarMargin = 20;
	this.imageMargin = 6;
	
	var links = this.layer.getElementsByTagName('a');
	for (var i = 0; i < links.length; i++) {
		var element = new Object();
		element.link = links[i];
		element.image = links[i].firstChild;
		
		element.imageWidth = parseInt(element.image.getAttribute('width'));
		element.imageHeight = parseInt(element.image.getAttribute('height'));

		if (element.imageWidth > this.maxWidth)
			this.maxWidth = element.imageWidth;
		if (element.imageHeight > this.maxHeight)
			this.maxHeight = element.imageHeight;
		
		element.image.style.display = 'block';
		
		element.link.style.display = 'block';
		element.link.style.cssFloat = 'left';
		element.link.style.marginRight = this.imageMargin + 'px';
		
		this.elements.push(element);
	}
	
	this.linkPrev = document.createElement('a');
	this.linkPrev.className = 'link-prev';
	this.linkPrev.style.visibility = 'hidden';
	this.linkPrev.style.opacity = 0.0;
	this.linkPrev.style.marginRight = this.toolbarMargin + 'px';
	this.linkPrev.onclick = function (e) {
		if (object.inFront <= 0) return;
		object.initMove(object.inFront, --object.inFront);
	}
	
	this.linkNext = document.createElement('a');
	this.linkNext.className = 'link-next';
	this.linkNext.onclick = function (e) {
		if (object.inFront >= object.elements.length - 1) return;
		object.initMove(object.inFront, ++object.inFront);
	}

	this.layer.insertBefore(this.linkPrev, this.layer.firstChild);
	this.layer.appendChild(this.linkNext);
	
	this.slideWidth = 2*this.maxWidth;
	
	this.layer.style.overflow = 'hidden';
	this.layer.style.height = this.maxHeight + 'px';
	this.layer.style.width = (2*this.linkNext.offsetWidth + this.slideWidth + 2*this.toolbarMargin + 2*this.imageMargin) + 'px';

	var linkMarginTop = Math.round((this.layer.offsetHeight - this.linkNext.offsetHeight) / 2);
	
	this.linkNext.style.marginTop = linkMarginTop + 'px';
	this.linkPrev.style.marginTop = linkMarginTop + 'px';
	
	for (var i = 0; i < this.elements.length; i++)
		this.setPosition(i, this.calculatePosition(i, this.inFront));

	
	this.layer.onmouseover = function () { window.clearInterval(object.interval); object.interval = null; }
	this.layer.onmouseout = function () { object.startAutoMove(); }
	
	this.startAutoMove();
}

Slideshow.prototype.startAutoMove = function () {
	var object = this;

	var autoMove = function () {
		if(object.inFront < object.elements.length - 1) {
			object.initMove(object.inFront, ++object.inFront);
		} else {
			object.initMove(object.inFront, object.inFront = 0);
		}
	}
	
	this.interval = window.setInterval(autoMove, 10 * this.moveTime);
}

Slideshow.prototype.initMove = function (inFront, toFront) {
	if (toFront == 0) {
		new Motion(this.linkPrev, 'opacity', '', false, 1.0, 0.0, this.moveTime, 0, 'linear');
		new Motion(this.linkPrev, 'visibility', '', false, 'visible', 'hidden', this.moveTime);
	} else if (toFront == this.elements.length - 1) {
		new Motion(this.linkNext, 'opacity', '', false, 1.0, 0.0, this.moveTime, 0, 'linear');
		new Motion(this.linkNext, 'visibility', '', false, 'visible', 'hidden', this.moveTime);
	}

	
	if (inFront == 0) {
		new Motion(this.linkPrev, 'opacity', '', false, 0.0, 1.0, this.moveTime, 0, 'linear');
		this.linkPrev.style.visibility = 'visible';
	} else if (inFront == this.elements.length - 1) {
		new Motion(this.linkNext, 'opacity', '', false, 0.0, 1.0, this.moveTime, 0, 'linear');
		this.linkNext.style.visibility = 'visible';
	}
	
	var backwards = (toFront < inFront);
	
	for (var i = (backwards) ? this.elements.length - 1 : 0; (backwards) ? i >= 0 : i < this.elements.length; (backwards) ? i-- : i++) {
		var startPos = this.calculatePosition(i, inFront);
		var endPos = this.calculatePosition(i, toFront);
		
		if (startPos.width != endPos.width)
			new Motion(this.elements[i].image, 'width', 'px', true, startPos.width, endPos.width, this.moveTime);
			
		if (startPos.height != endPos.height)
			new Motion(this.elements[i].image, 'height', 'px', true, startPos.height, endPos.height, this.moveTime);
			
		if (startPos.marginTop != endPos.marginTop)
			new Motion(this.elements[i].link, 'marginTop', 'px', true, startPos.marginTop, endPos.marginTop, this.moveTime);
			
		if (startPos.marginLeft != endPos.marginLeft)
			new Motion(this.elements[i].link, 'marginLeft', 'px', true, startPos.marginLeft, endPos.marginLeft, this.moveTime);
			
		if ((endPos.width == 0 || endPos.height == 0) && startPos.width != endPos.width)
			new Motion(this.elements[i].link, 'display', null, false, 'block', 'none', this.moveTime);
		
		if (endPos.width > 0 && endPos.height > 0)
			this.elements[i].link.style.display = 'block';
			
		if (startPos.opacity != endPos.opacity)
			new Motion(this.elements[i].link, 'opacity', '', false, startPos.opacity, endPos.opacity, this.moveTime, 0, 'linear');
	}
}

Slideshow.prototype.setPosition = function (index, position) {
	this.elements[index].image.style.width = position.width + 'px';
	this.elements[index].image.style.height = position.height + 'px';
	this.elements[index].link.style.display = (position.width > 0 && position.height > 0) ? 'block' : 'none';
	this.elements[index].link.style.marginTop = position.marginTop + 'px';
	this.elements[index].link.style.marginLeft = position.marginLeft + 'px';
	this.elements[index].link.style.opacity = position.opacity;
}

Slideshow.prototype.calculatePosition = function (index, inFront) {
	var position = new Object();
	position.marginLeft = 0;
	position.opacity = 1.0;
	if (index == inFront) {
		position.width = this.elements[index].imageWidth;
		position.height = this.elements[index].imageHeight;
	} else if (index == inFront - 1 || index == inFront + 1) {
		position.width = Math.round( (this.slideWidth - this.elements[inFront].imageWidth) / 2);
		position.height = Math.round((this.elements[index].imageHeight / this.elements[index].imageWidth) * position.width);
		position.opacity = 0.2;
	} else {
		position.width = 0;
		position.height = 0;
		position.opacity = 0.0;
	}
	
	
	if (index != inFront) {
		var side = (index < inFront) ? 0 : 1;
		if (this.moveMode[side] == 'top')
			position.marginTop = 0;
		else if (this.moveMode[side] == 'center')
			position.marginTop = Math.round((this.layer.offsetHeight - position.height) / 2 );
		else
			position.marginTop = this.layer.offsetHeight - position.height;
	} else
		position.marginTop = 0;
	
	
	if (index == 0 && inFront == 0) {
		var ratio = this.elements[1].imageWidth / this.elements[1].imageHeight;
		var width1 = Math.round(this.calculatePosition(1, 0).height * ratio);
		position.marginLeft = this.slideWidth - width1 - this.elements[0].imageWidth;
	}
	
	return position;
}







Motionobjects = new Array();

function Motion(obj, property, unit, round, startValue, endValue, duration, startDelay, computation) {
	this.obj = obj;	
	this.property = property;
	this.startValue = startValue;
	this.endValue = endValue;
	this.duration = duration;
	this.unit = (typeof unit == 'string') ? unit : '';
	this.round = round;
	this.lastValue = this.startValue;
	this.timeouts = new Array();
	
	for (var i = 0; i < Motionobjects.length; i++) {
		if (Motionobjects[i] != null && Motionobjects[i].obj == this.obj && Motionobjects[i].property == this.property) {
			for (var j = 0; j < Motionobjects[i].timeouts.length; j++) {
				window.clearTimeout(Motionobjects[i].timeouts[j]);
			}
			this.startValue = Motionobjects[i].lastValue;
			Motionobjects[i] = null;
			break;
		}
	}
	
	
	this.startDelay = (typeof startDelay != 'undefined') ? startDelay : 0;

	this.id = Motionobjects.push(this) - 1;

	if (typeof startValue == 'string') {
		this.obj.style[this.property] = startValue;
		window.setTimeout('Motionobjects['+this.id+'].obj.style[\''+this.property+'\'] = \''+endValue+'\';', this.duration + this.startDelay);
		return;
	}	
	
	this.computation = (typeof computation != 'undefined') ? computation : 'cubic';
	
	switch (this.computation) {
		case 'cubic':
			this.a = -(2*(-this.startValue+this.endValue))/Math.pow(this.duration,3);
			this.b = (3*(-this.startValue+this.endValue))/Math.pow(this.duration,2);
			this.d = this.startValue;
			break;
		case 'linear':
			this.a = (this.endValue-this.startValue)/this.duration;
			this.b = this.startValue;
			break;
	}
	
	this.start();
}

Motion.prototype.value = function (t) {
	switch (this.computation) {
		case 'cubic':
			return (t < this.duration) ? this.a*Math.pow(t,3) + this.b*Math.pow(t,2) + this.d : this.endValue;
		case 'linear':
			return (t < this.duration) ? this.a*t + this.b : this.endValue;
	}
}

Motion.prototype.start = function (t) {
	for (var t = 0; t <= this.duration; t += 10) {
		var value = (this.round) ? Math.round(this.value(t)) : this.value(t);
		this.timeouts.push( window.setTimeout('Motionobjects['+this.id+'].set('+value+');', t + this.startDelay) );
	}
}

Motion.prototype.set = function (value) {
	this.lastValue = value;
	this.obj.style[this.property] = value+this.unit;
}






var fade = new function () {

	this.contentlayer;
	this.shadowlayer;
	this.moveTime = 500;
	this.fadeTime = 200;
	
	
	this.scrollpos = 0;
	this.scrollsteps = 60;
	this.scrollTime = 400;
	
	this.innerscroll; this.outerscroll;


	this.init = function (pageId) {
	
		// FORWARD TO FRAMESET IF NECESSARY
		if(top.frames.length == 0)
			document.location.href = '/?p='+pageId;
			
		top.navigation_url = document.location.href;
	
	
		this.contentlayer = document.getElementById('content');
		this.shadowlayer = document.getElementById('shadow');
		this.innerscroll = document.getElementById('inner_scroll');
		this.outerscroll = document.getElementById('outer_scroll');
		this.holeframe = document.getElementById('holeframe');
	
		window.setTimeout('top.navigation.overlay(false);', 100);
	
		// LINKS UMLENKEN
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			if ((links[i].target == '' || links[i].target == '_self') && (typeof links[i].onclick == 'undefined' || links[i].onclick == null) && links[i].href.length > 0 && links[i].rel.length == 0)
				this.handleLink(links[i]);
		}
		
		
		
		
		// MOTION
		var from_position = this.getPosition(top.navigation_move.from);
		var to_position = {
				top:		60,  //this.contentlayer.offsetTop,
				left:		80,  //this.contentlayer.offsetLeft,
				width:		620, //this.contentlayer.offsetWidth,
				height:		364, //this.contentlayer.offsetHeight,
				opacity:	0.3
			};
		
	/*	for (var i in to_position)
			alert(i + ': ' + to_position[i]);
		*/	
			
		for (var i in from_position) {
			if (from_position[i] != to_position[i]) {
				if (i == 'opacity')
					new Motion(this.shadowlayer, i, null, false, from_position[i], to_position[i], this.moveTime, 0, 'linear');
				else
					new Motion(this.shadowlayer, i, 'px', true, from_position[i], to_position[i], this.moveTime);
			}
		} 
		
		
		
		
		this.contentlayer.style.opacity = 0.0;
		this.contentlayer.style.display = 'none';
		new Motion(this.contentlayer, 'opacity', null, false, 0, 1, this.fadeTime, this.moveTime, 'linear');
		new Motion(this.contentlayer, 'display', null, false, 'none', 'block', this.moveTime);
		
		
		this.scrollinit();
		
		this.checkUrl();
	}
	
	this.getPosition = function (mode) {
		switch (mode) {
			case 'back':	return { top: Math.round(this.holeframe.offsetHeight / 2), left: Math.round(this.holeframe.offsetWidth / 2), width:	0, height:	0, opacity:	0.0 };
			case 'front':	return { top: -100, left: -100, width: this.holeframe.offsetWidth + 200, height: this.holeframe.offsetHeight + 200, opacity:	0.0 };
			case 'left':	return { top: Math.round(this.holeframe.offsetHeight / 2), left: -100, width: 0, height: 0 };
			case 'right':	return { top: Math.round(this.holeframe.offsetHeight / 2), left: this.holeframe.offsetWidth + 100, width: 0, height: 0 };
			case 'bottom':	return { top: this.holeframe.offsetHeight + 100, left: Math.round(this.holeframe.offsetWidth / 2), width: 0, height: 0 };
			case 'top':		return { top: -100, left: Math.round(this.holeframe.offsetWidth / 2), width: 0, height: 0 };
		}
	}
	

	
	this.handleLink = function (link) {
		link.onclick = function (e) {
			var next_depth = this.href.split('/').length;
			var last_depth = (typeof top.navigation_url != 'undefined') ? top.navigation_url.split('/').length : 0;
			
			top.navigation_url = this.href;
			top.navigation_move = (last_depth < next_depth) ? {from: 'back', to: 'front'} : {from: 'front', to: 'back'};
			
			return false;
		}
	}
	
	this.out = function () {
		if (typeof this.scrolllayer != 'undefined')
			new Motion(this.scrolllayer, 'width', 'px', true, this.scrolllayer.offsetWidth, 0, this.fadeTime);
		new Motion(this.contentlayer, 'opacity', null, false, 1, 0, this.fadeTime, 0, 'linear');
		new Motion(this.contentlayer, 'display', null, false, 'block', 'none', this.fadeTime);
		
		
		
		// MOTION
		var to_position = this.getPosition(top.navigation_move.to);
		var from_position = {
				top:		this.contentlayer.offsetTop,
				left:		this.contentlayer.offsetLeft,
				width:		this.contentlayer.offsetWidth,
				height:		this.contentlayer.offsetHeight,
				opacity:	0.3
			};
			
			
		for (var i in to_position) {
			if (from_position[i] != to_position[i]) {
				if (i == 'opacity')
					new Motion(this.shadowlayer, i, null, false, from_position[i], to_position[i], this.moveTime, this.fadeTime, 'linear');
				else
					new Motion(this.shadowlayer, i, 'px', true, from_position[i], to_position[i], this.moveTime, this.fadeTime);
			}
		}
		

		
	
		
		window.setTimeout('top.navigation.overlay(true); document.location.href = \''+top.navigation_url+'\';', this.moveTime + this.fadeTime);
	}
	
	this.checkUrl = function () {
		if (typeof top.navigation_url != 'undefined' && top.navigation_url != null && top.navigation_url != document.location.href) {
			this.out();
		} else
			window.setTimeout('fade.checkUrl();', 50);
	}
	
	this.scrollinit = function () {
		if (this.innerscroll.offsetHeight == 0) {
			window.setTimeout('fade.scrollinit();', 50);
			return;
		} else if (this.innerscroll.offsetHeight <= this.outerscroll.offsetHeight)
			return;
	
		this.scrolllayer = document.createElement('div');
		this.scrolllayer.className = 'scroll';
		
		var scrollUp = document.createElement('div');
		scrollUp.className = 'up';
		scrollUp.onclick = function (e) {
			if (fade.scrollpos > 0)
				fade.makescroll(fade.scrollpos, --fade.scrollpos);
		}
		var scrollDown = document.createElement('div');
		scrollDown.className = 'down';
		scrollDown.onclick = function (e) {
			if (fade.scrollpos < fade.scrollmax)
				fade.makescroll(fade.scrollpos, ++fade.scrollpos);
		}
		
		var scrollBar = document.createElement('div');
		scrollBar.className = 'scrollbar';
		
		this.scrollmax = parseInt((this.innerscroll.offsetHeight - this.outerscroll.offsetHeight) / this.scrollsteps) + 1;
		
		
		this.scrolllayer.appendChild(scrollUp);
		this.scrolllayer.appendChild(scrollBar);
		this.scrolllayer.appendChild(scrollDown);
		
		document.body.appendChild(this.scrolllayer);
		
		document.onmousewheel = function (e) {
			if (typeof e != 'undefined' && typeof e.wheelDelta != 'undefined') {
				if (e.wheelDelta > 0 && fade.scrollpos > 0)
					fade.makescroll(fade.scrollpos, --fade.scrollpos);
				else if(e.wheelDelta < 0 && fade.scrollpos < fade.scrollmax)
					fade.makescroll(fade.scrollpos, ++fade.scrollpos);
			}
		}

		new Motion(this.scrolllayer, 'width', 'px', true, 0, 29, this.fadeTime, this.moveTime);
		this.scrolllayer.style.width = '0px';
	}
	
	this.makescroll = function (from, to) {
		new Motion(this.innerscroll, 'marginTop', 'px', true, -1*from*this.scrollsteps, -1*to*this.scrollsteps, this.scrollTime);
	}
		
}



var calendar = new function() {

	this.layer = null;
	this.body = null;
	this.locked = false;
	this.month;
	this.now = new Date();
	this.yy = null;
	this.mm = null;
	this.dayname = ['Mo','Di','Mi','Do','Fr','Sa','So'];
	this.monthname = ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
	this.movetime = 600;
	this.events = new Array();
	this.eventlayer = null;
	this.highlightDate = null;
	this.pid = 8;

	this.init = function (hyear, hmonth, hday) {
		document.write('<div id="calendar"></div>');
		
	
		this.body = document.createElement('ul');
		this.body.className = 'body';
		
		this.eventlayer = document.createElement('div');
		this.eventlayer.className = 'event';
		
		
		this.layer = document.getElementById('calendar');
		this.layer.appendChild(this.createCalendarHeader());
		this.layer.appendChild(this.body);
		this.layer.appendChild(this.eventlayer);
		
		if (typeof hday != 'undefined') {
			this.highlightDate = new Array(hyear, hmonth, hday);
			this.yy = hyear;
			this.mm = hmonth;
		} else {
			this.yy = this.now.getFullYear();
			this.mm = this.now.getMonth();
		}
		
		
		
		var yymm = this.yymm(this.yy, this.mm);
		var query = '/ajax/?calendar&yymm='+yymm+'&pid='+this.pid;
		window.setTimeout("http('GET', '"+query+"', calendar.recieve);", 0);
		
		this.open(this.yy, this.mm); 
	};
	
	this.open = function (year,month) {
		this.yy = year;
		this.mm = month;
		this.month.innerHTML = this.monthname[this.mm] + ' ' + this.yy;
		this.createCalendarBody();
	}
	
	this.yymm = function (year,month) {
		var out = year+'-';
		month++;
		if(month < 10)
			out += '0';
		out += month;
		return out;
	}
	
	this.makeMove = function (startTime, duration, startPos, endPos, direction) {
		
		
		var left, t;
		var a = (direction == 'out') ? (endPos - startPos) / Math.pow(duration,2) : (startPos - endPos) / Math.pow(duration,2);
		var b = (direction == 'out') ? startPos : endPos;
		var t_off = (direction == 'out') ? startTime : startTime + duration;
		for(t = startTime; t <= startTime + duration; t = t + 10) {
			left = Math.round(a * Math.pow(t - t_off, 2) + b);
			window.setTimeout('calendar.body.style.marginLeft = \''+left+'px\';', t);
		}
		
	}
	
	this.recieve = function (data) {
		calendar.events[data['key']] = data[data['key']];
	}
	
	this.createCalendarHeader = function () {
		var header = document.createElement('ul');
		header.className = 'header';
		
		var prevMonth = document.createElement('li');
		prevMonth.className = 'prevMonth';
		prevMonth.onclick = function (e) {
			if (calendar.locked) return;
			calendar.locked = true;
			
			var year = (calendar.mm == 0) ? calendar.yy - 1 : calendar.yy;
			var month = (calendar.mm == 0) ? 11 : calendar.mm - 1;
			var yymm = calendar.yymm(year,month);
			
			if(year < 2007) return;
			
			if(typeof calendar.events[yymm] == 'undefined') {
				var query = '/ajax/?calendar&yymm='+yymm+'&pid='+calendar.pid;
				http('GET', query, calendar.recieve);
			}
			
			calendar.makeMove(0, calendar.movetime, 0, 200, 'out');
			
		
			window.setTimeout('calendar.open('+year+','+month+');', calendar.movetime);
			
			calendar.makeMove(calendar.movetime, calendar.movetime, -200, 0, 'in');
			
			window.setTimeout('calendar.locked = false;', 2 * calendar.movetime);
		}
		var nextMonth = document.createElement('li');
		nextMonth.className = 'nextMonth';
		
		nextMonth.onclick = function (e) {
			if (calendar.locked) return;
			calendar.locked = true;
			
			var year = (calendar.mm == 11) ? calendar.yy + 1 : calendar.yy;
			var month = (calendar.mm == 11) ? 0 : calendar.mm + 1;
			var yymm = calendar.yymm(year,month);
			
			if(year > calendar.now.getFullYear() + 1) return;
			
			if(typeof calendar.events[yymm] == 'undefined') {
				var query = '/ajax/?calendar&yymm='+yymm+'&pid='+calendar.pid;
				http('GET', query, calendar.recieve);
			}
			
			calendar.makeMove(0, calendar.movetime, 0, -200, 'out');
			
			
			window.setTimeout('calendar.open('+year+','+month+');', calendar.movetime);
			
			calendar.makeMove(calendar.movetime, calendar.movetime, 200, 0, 'in');
			
			window.setTimeout('calendar.locked = false;', 2 * calendar.movetime);
		}
		
		this.month = document.createElement('li');
		this.month.className = 'month';
		
		header.appendChild(prevMonth);
		header.appendChild(this.month);
		header.appendChild(nextMonth);
		
		
		for(var i = 0; i <= 6; i++) {
			var day = document.createElement('li');
			day.className = 'day';
			day.appendChild(document.createTextNode(this.dayname[i]));
			header.appendChild(day);
		}
		
		return header;
	}
	
	this.highlightEvents = function (year, month) {
		var yymm = this.yymm(year, month);
		if (typeof this.events[yymm] != 'undefined' && this.yy == year && this.mm == month) {
			for (var i =  0; i < this.body.childNodes.length; i++) {
				if (this.body.childNodes[i].className != 'othermonth' && typeof this.events[yymm][this.body.childNodes[i].innerHTML] != 'undefined') {
					if (this.highlightDate != null
							&& year == this.highlightDate[0]
							&& month == this.highlightDate[1]
							&& parseInt(this.body.childNodes[i].innerHTML) == this.highlightDate[2]) {
							
						this.body.childNodes[i].className += ' highlight';	
					}
					var link = document.createElement('a');
					link.href = this.events[yymm][this.body.childNodes[i].innerHTML]['url'];
					link.title = this.events[yymm][this.body.childNodes[i].innerHTML]['title'];
					
					fade.handleLink(link);
					
					link.appendChild(document.createTextNode(this.body.childNodes[i].innerHTML));
					link.onmouseover = function (e) { calendar.eventlayer.innerHTML = this.title; }
					link.onmouseout  = function (e) { calendar.eventlayer.innerHTML = ''; }
					this.body.childNodes[i].innerHTML = '';
					this.body.childNodes[i].appendChild(link);
					
				}
			}
		} else if (this.yy == year && this.mm == month)
			window.setTimeout('calendar.highlightEvents('+year+','+month+');',100);
	}
	
	this.createCalendarBody = function () {
		
		for (var i = this.body.childNodes.length - 1; i >= 0; i--) {
			this.body.removeChild(this.body.childNodes[i]);
		}
			
	
		var dayspermonth = [31,28,31,30,31,30,31,31,30,31,30,31];
		
		if ((this.yy%4==0) && ((this.yy%100!=0) || (this.yy%400==0)))
			dayspermonth[1] = 29;
		
		var begin = new Date(this.yy, this.mm, 1);
		var end = new Date(this.yy, this.mm, dayspermonth[this.mm]);
		var lastday = end.getDay() - 1;
		lastday = (lastday < 0) ? 6 : lastday;
		var firstday = begin.getDay() - 1;
		firstday = (firstday < 0) ? 6 : firstday;

		
		
		
			
		var prevMonth = (this.mm == 0) ? 11 : this.mm - 1;
		var nextMonth = (this.mm + 1) % 12;
		
		
		var calstart = (firstday == 0) ? dayspermonth[prevMonth] + 1 : dayspermonth[prevMonth] + 1 - firstday;
		var calend = (lastday == 6) ? 0 : 6 - lastday;
		
		
		var appendDay = function (day, className) {
			var li;
			li = document.createElement('li');
			li.appendChild(document.createTextNode(day));
			li.className = className;
			calendar.body.appendChild(li);
		}
		
		
		for(var i = calstart; i <= dayspermonth[prevMonth]; i++) {
			appendDay(i, 'othermonth');
		}
		
		
		for(var i = 1; i <= dayspermonth[this.mm]; i++) {
			appendDay(i, (i == this.now.getDate() && this.mm == this.now.getMonth() && this.yy == this.now.getFullYear()) ? 'today' : '');
		}
		
		for(var i = 1; i <= calend; i++) {
			appendDay(i, 'othermonth');
		}
		
		this.highlightEvents(this.yy, this.mm);
		
	};
}
