window.addEvent('domready', function() {

	myCal = new Calendar({ Calendar: 'd.m.Y', date: 'd.m.Y' },{ direction: 1, navigation: 2 });
	
	if($('joinevent')) {
		var e = $E('a','joinevent');
		e.onclick = function() {
			var id = e.getProperty('rel');
			var typ = e.getProperty('class');
			new Ajax('/ajax.php?function=event&action='+typ+'&id='+id, {
				onComplete: function(response) {
					if(response == "true") {
						if(typ == "join") {
							e.removeClass('join');
							e.addClass('leave');
							e.setText('Du nimmst teil!');
						} else {
							e.removeClass('leave');
							e.addClass('join');
							e.setText('Ich will dabei sein!');
						}
					} else {
						alert('Fehler!\nEvent kann nicht beigetreten werden.');
					}
				}
			}).request();
		}
	}
	
	// fullsize picture
	new MultiBox('mb', {
		showNumbers: false,
		descClassName:'BoxDesc'
	});
	
	// delete event
	if($('btn:delevent')) {
		$('btn:delevent').onclick = function() {
			var id = this.getProperty('rel');
			if(confirm('Event wirklich löschen?\n\nACHTUNG!\nEs werden alle dazugehörigen Kommentare und Bilder gelöscht.')) {
				window.location.href = '/event.php?function=delevent&id='+id;
			}
		}	
	}
	
	// delete comment
	if($ES('a.delcomment')) {
		$ES('a.delcomment').each(function(a) {
			a.onclick = function() {
				var id = this.getProperty('name');
				var commentid = this.getProperty('rel');
				if(confirm('Kommentar wirklich löschen?')) {
					window.location.href = '/'+script+'?id='+id+'&function=delcomment&commentid='+commentid;
				}
				return false;
			}
		});	
	}
	
	// delete image
	if($ES('a.delpic')) {
		$ES('a.delpic').each(function(a) {
			a.onclick = function() {
				var id = this.getProperty('rel');
				var picid = this.getProperty('name');
				if(confirm('Bild wirklich löschen?')) {
					window.location.href = '/gallery.php?function=delpic&id='+id+'&picid='+picid;
				}
				return false;
			}
		});	
	}
	

	// bb editor
	nawte = new nawte('comment', 'toolbar');
	
	nawte.addFunction('Bold', function() {
	  selection = this.getSelection();
	  this.replaceSelection('[b]' + selection + '[/b]');
	}, {'id': 'bold_button'});
	
	nawte.addFunction('Italic', function() {
	  selection = this.getSelection();
	  this.replaceSelection('[i]' + selection + '[/i]');
	}, {'id': 'italic_button'});
	
	nawte.addFunction('Underline', function() {
	  selection = this.getSelection();
	  this.replaceSelection('[u]' + selection + '[/u]');
	}, {'id': 'underline_button'});
	
/*
	nawte.addFunction('Insert Link', function() {
	  var selection = this.getSelection();  
	  var response = prompt('Enter Link URL','');  
	  if(response == null)  
		   return;  
	  this.replaceSelection('[url=' +  (response == '' ? 'http://link_url/' : response) + ']' + (selection == '' ? 'Link Text' : selection) + '[/url]');
	}, {'id': 'link_button'});
	*/
	
});