var InputMask = new Class(
{	
	MaskColor : '#AAAAAA',
	MaskType : 'text',
	
	initialize : function(aElement,aMaskText)
	{
		var _Proceed = false;
		this.Masked = false;
		this.Element = aElement;
		
		if ( $defined(aMaskText) )
		{
			this.MaskText = aMaskText;
			_Proceed = true;
		}
		else
		{		
			aElement.getProperty("class").split(' ').each(function(eClass)
			{	if ( eClass.match(/^mask(\[.+\])$/) )
				{	var info = eval(eClass.match(/^mask(\[.+\])$/)[1]);
					if ( info.length >= 1 )
					{	
						this.MaskText = info[0];
						_Proceed = true;
					}
				}			
			},this);
		}
		
		if ( _Proceed )
		{
			this.TextColor = aElement.style.color;
			this.InputType = aElement.type;
			
			aElement.type = this.MaskType;
			aElement.value = this.MaskText;
			aElement.style.color = this.MaskColor;
			
			aElement.addEvent('focus',function(event)
			{	var field = event.target;
				if (field.value == this.MaskText)
				{	field.type = this.InputType;
					field.value = '';					
					field.style.color = this.TextColor;
				}				
			}.bindWithEvent(this));			
			aElement.addEvent('blur',function(event)
			{	var field = event.target;
				if (field.value == '')
				{	field.type = this.MaskType;
					field.value = this.MaskText;
					field.style.color = this.MaskColor;
				}
			}.bindWithEvent(this));
			
			this.Masked = true;
		}
		
		aElement.Mask = this;
	},
	
	Value : function()
	{	if ( this.Masked )
		{	if ( this.Element.value != this.MaskText )
				return this.Element.value;
			else
				return '';
		}
		return this.Element.value;
	}	
});

InputMask.Init = function()
{
	$$("*[class*=mask]").each(function(element)
	{ new InputMask(element); },this);
}

var BoxSlider = new Class(
{
	initialize : function(folioId,cols,rows,width,height)
	{	this._Columns = cols;
		this._Rows = rows;
		this._Width = width;
		this._Height = height;
		
		this._CurrentCol = 0;
		this._CurrentRow = 0;
		this._FolioChange = new Fx.Tween(folioId,{duration:500});	
	},
	
	goUp : function()
	{	if (this._CurrentRow > 0)
		{	this._CurrentRow -= 1;
			var y = (this._CurrentRow * (-1 * this._Height));
			this._FolioChange.start('top',y);
		}		
	},
	
	goDown : function()
	{	if (this._CurrentRow < this._Rows - 1)
		{	this._CurrentRow += 1;
			var y = (this._CurrentRow * (-1 * this._Height));
			this._FolioChange.start('top',y);	
		}		
	},
	
	goLeft : function()
	{	if(this._CurrentCol > 0)
		{	this._CurrentCol -= 1;
            var x = (this._CurrentCol * (-1 * this._Width));
            this._FolioChange.start('left',x);
        }
	},
	
	goRight : function()
	{	if(this._CurrentCol < this._Columns - 1)
		{	this._CurrentCol += 1;
            var x = (this._CurrentCol * (-1 * this._Width));
            this._FolioChange.start('left',x);
        }		
	},
});

var LinkAction = new Class(
{	Implements : Events,
	initialize : function(idName)
	{	$$("*[rel*=" + idName + "]").each(function(aElement)
		{	aElement.addEvent('click',function(event)
			{	event.stop();
				aElement.getProperty('rel').split(' ').each(function(aRel)
				{	var re = new RegExp(idName + "(\\[.+\\])");
					if ( aRel.match(re) )
					{	var info = eval(aRel.match(re)[1]);
						if ( info.length >= 1 )
							this.fireEvent('execute',[info[0],event.target]);
					}
				},this);
			}.bindWithEvent(this));
		},this);		
	}
});

/* Element Implementations */
Element.implement(
{
	Mask : function(aMaskedText)
	{ new InputMask(this,aMaskedText); }
});
