function Task_Variant_4(config)
{
	Task_Variant_4.superclass.constructor.call(this);
	
	var sRussianLetters = "аеиоуыэя";
	
	this._baseElement = Rup.create("span");
	
	this._baseElement.innerHTML = config.text.replace(/(.)/gi, '<span class="Task_Variant_4_Letter">$1</span>');
	
	this._letters = [];
	
	var aSpans = this._baseElement.getElementsByTagName('span');
	
	for( var i = aSpans.length - 1; 0 <= i; i-- )
	{
		if( aSpans[i].className == 'Task_Variant_4_Letter' )
		{
			var oLetter;
			if( "аеёиоуыэюяАЕЁИОУЫЭЮЯ".indexOf(aSpans[i].innerHTML) != -1 )
			{
				oLetter = new Task_Variant_4_Letter_Vowel({text: aSpans[i].innerHTML});
			}
			else
			{
				oLetter = new Task_Variant_4_Letter({text: aSpans[i].innerHTML});
			}
			this._letters.unshift(oLetter);
			this._baseElement.replaceChild(oLetter.dom(), aSpans[i]);
			
			var instance = this;
			
			if( oLetter instanceof Task_Variant_4_Letter_Vowel )
			{
				oLetter._baseElement.onclick = function(){
					for( var j = 0; j < instance._letters.length; j++ )
					{
						if( instance._letters[j] != this.element )
						{
							instance._letters[j].deactivate();
						}
					}
					if( this.element.active )
					{
						this.element.deactivate();
					}
					else
					{
						this.element.activate();
					}
					
					if( instance._handler )
					{
						instance._handler();
					}
				}
			}
		}
	}
	
	this._handler = null;
}

Rup.extend(Task_Variant_4, Task_Variant_Abstract);

Task_Variant_4.prototype.setValue = function(value)
{
	for( var i = 0; i < this._letters.length; i++ )
	{
		this._letters[i].deactivate();
	}
	if(  0 < value && value <= this._letters.length )
	{
		this._letters[value - 1].activate();
	}
}

Task_Variant_4.prototype.getValue = function()
{
	var value = 0;
	
	for( var i = 0; i < this._letters.length; i++ )
	{
		if( this._letters[i].active )
		{
			value = i + 1;
		}
	}
	
	return value;
}

Task_Variant_4.prototype.setDisabled = function()
{
	for( var i = 0; i < this._letters.length; i++ )
	{
		this._letters[i].disable();
	}
}

Task_Variant_4.prototype.setHandler = function(handler, scope, num)
{
	this._handler = function(){ handler.call(scope, num);};
}

// ======================================================

function Task_Variant_4_Letter(config)
{
	Task_Variant_4_Letter.superclass.constructor.call(this);
	
	this._baseElement = Rup.create("span");
	this._baseElement.element = this;
	this._baseElement.innerHTML = config.text;
	this._baseElement.className = "letter";
	
	this.active = false;
	this.disabled = false;
}

Rup.extend(Task_Variant_4_Letter, Element_Abstract);


Task_Variant_4_Letter.prototype.activate = function(){}

Task_Variant_4_Letter.prototype.deactivate = function(){}

Task_Variant_4_Letter.prototype.disable = function(){}

// ======================================================

function Task_Variant_4_Letter_Vowel(config)
{
	Task_Variant_4_Letter_Vowel.superclass.constructor.call(this, config);
	
	var instance = this;
	
	this._baseElement.onmouseover = function() { instance._baseElement.className = "letter active"; }
	this._baseElement.onmouseout = function() { instance._baseElement.className = "letter"; }
	
	var oSpan = Rup.create("span");
	oSpan.innerHTML = "'";
	
	this._baseElement.appendChild(oSpan);
	
	this.active = false;
	this.disabled = false;
}

Rup.extend(Task_Variant_4_Letter_Vowel, Task_Variant_4_Letter);


Task_Variant_4_Letter.prototype.activate = function()
{
	this._baseElement.className = "letter active";
	this._baseElement.onmouseover = null;
    this._baseElement.onmouseout = null;
    this.active = true;
}

Task_Variant_4_Letter_Vowel.prototype.deactivate = function()
{
	this._baseElement.className = "letter";
	
	var instance = this;
	
	if( !this.disabled )
	{
		this._baseElement.onmouseover = function() { instance._baseElement.className = "letter active"; }
		this._baseElement.onmouseout = function() { instance._baseElement.className = "letter"; }
	}
	this.active = false;
}

Task_Variant_4_Letter_Vowel.prototype.disable = function()
{
	this._baseElement.onmouseover = null;
	this._baseElement.onmouseout = null;
	this._baseElement.onclick = null;
	this.disabled = true;
}