Event.observe(document, 'dom:loaded', function() {
	Main.init()
	if(	$('text_edit')) Form.init()
	if ($('anntext')) Result.init()
})
var Main = {
	init: function(){
		setTimeout(function(){Main.heightFix()}, 10)
		Event.observe(window, 'resize', this.heightFix)
	},
	heightFix: function(){
		if ($('text_edit')) $('text_edit').setStyle('height:'+ ($('body').getHeight() - (100 + 383)) + 'px;')
		$('widget_container').setStyle('height:'+ ($('body').getHeight() - (100 + 215)) + 'px;')
		if ($('anntext')) $('anntext').setStyle('height:'+ ($('body').getHeight() - (150 + 445)) + 'px;')
  }
}
var Form = {
	init: function(){
		this.textareaControl()
	},
	textareaControl: function(){
			$('text_edit').observe('blur', function(){
				if (this.value == '') {
					this.value = 'Введите текст для обработки';
					this.setStyle('color: #6d6e71;');
				}
			})
			$('text_edit').observe('focus', function(){
			  this.setStyle('color: #000;');
				if (this.value == 'Введите текст для обработки') {
          this.value = '';
				}
			})

	}
}
var Result = {
	init: function(){
	  this.hideOverlay()
		this.switchElements()
		this.hideCrap()
		this.colorizeChecked()
	},
	hideOverlay: function(){
		$('overlay').hide()
	},
	switchElements: function(){
		var content = $('anntext').innerHTML
		$('anntext').remove()
		$('hide-concepts').insert('<div class="legendRight"></div>')
		$('hide-concepts').insert({after: '<div id="anntext">' + content + '</div>'})
	},
	hideCrap: function(){
		$$('#hide-concepts .linkimg').each(function(span){
			span.remove()
		})
		$$('#hide-concepts span.hide-concept').each(function(span){
			var buf = span.down('span').innerHTML
			var text_fix = span.innerHTML.stripTags()
			text_fix = text_fix.gsub('_', ' ')
			text_fix = text_fix.capitalize()
			span.innerHTML = '<span class="hidden">' + buf + '</span>' + text_fix + '<span class="rightBg"></span>'
			span.observe('click', function(){
				inp = this.down('input')
				if (inp.checked){
					this.addClassName('checked')
				}else{
					this.removeClassName('checked')
				}
			})
		})
	},
	colorizeChecked: function(){
    $$('#hide-concepts span.hide-concept span.hidden input').each(function(inp){
			if (inp.checked){
				inp.up('span.hide-concept').addClassName('checked')
			}
		})
	}
}
