var ddDescriptionResizer = new Class({
	
	initialize: function(descriptionId) {
		this.description = $(descriptionId);
		this.maxLength = 600;
		this.fullHeight = this.description.getSize().y;
		this.fullText = this.description.get('html');
		this.length = this.description.get('text').length;
		this.open = false;
		this.slide = false;
		
		if (this.length > this.maxLength) {
			
			this.moreLink = new Element('a', {
				'href' : 'javascript:void(0);',
				'class': 'eventDescriptionMoreLink',
				'text' : 'weiterlesen'
			});			

			this.subText = this.subWordSave(this.fullText, this.maxLength);
			this.description.set('html', this.subText);
			this.moreLink.inject(this.description);
			this.subHeight = this.description.getSize().y;
			
			this.moreLink.addEvent('click', function() {
				if (!this.slide) {
					if (this.open) {
						this.closeDescription();
					}
					else {
						this.openDescription();						
					}
				}	
			}.bind(this));
			
			this.fullHeight += this.moreLink.getSize().y+10;
		}
		
		
	},
	
	openDescription: function() {
		this.slide = new Fx.Tween(this.description);
		this.slide.addEvent('complete',  function() {
			this.slide = false;
		}.bind(this));	
			
		this.slide.start('height', this.fullHeight);
		this.description.set('html', this.fullText);
		this.moreLink.inject(this.description);	
		this.moreLink.set('text','zuklappen');	
		this.open = true;		
	},
	
	closeDescription: function() {
		this.slide = new Fx.Tween(this.description);
		this.slide.addEvent('complete',  function() {
			this.slide = false;
		}.bind(this));	
			
		this.slide.start('height', this.subHeight);
		this.description.set('html', this.subText);
		this.moreLink.inject(this.description);	
		this.moreLink.set('text','weiterlesen');	
		this.open = false;
		var slideBack = new Fx.Scroll(window).toElement(this.description);		
	},	
	
	subWordSave: function(text, maxLength) {
		subText = '';
		words = text.split(' ');
		for (c=0; c<words.length; c++) {
			if (subText.length < maxLength) {
				subText += (subText?' ':'') + words[c];
			}
			else {
				break;
			}
		}
		return subText + ' ...';
	}
});


var ddCommentForm = new Class({
	
	initialize: function(nameId, textId, firstViewId) {

		this.firstView = $(firstViewId);
		if (this.firstView.value!='0') {
			this.nameInput = $(nameId);
			this.textInput = $(textId);
			
			this.nameDefaultValue = this.nameInput.value;
			this.textDefaultValue = this.textInput.value;
			
			this.nameInput.addEvent('focus', function() {
				if (this.nameInput.value==this.nameDefaultValue) {
					this.nameInput.value = '';
				}
			}.bind(this));
			
			this.nameInput.addEvent('blur', function() {
				if (this.nameInput.value=='') {
					this.nameInput.value = this.nameDefaultValue;
				}
			}.bind(this));
			
			this.textInput.addEvent('focus', function() {
				if (this.textInput.value==this.textDefaultValue) {
					this.textInput.value = '';
				}
			}.bind(this));
			
			this.textInput.addEvent('blur', function() {
				if (this.textInput.value=='') {
					this.textInput.value = this.textDefaultValue;
				}
			}.bind(this));			
		}
				
		
	}

		
	
});

window.addEvent('domready', initActorView);
function initActorView() {
	
	
	descriptionResizer = new ddDescriptionResizer('actorDescription');
	commentForm = new ddCommentForm('commentFormNameInput', 'commentFormTextInput', 'commentFormFirstView');
	
}
