/*
---
script      : Fx.Set.js

provides    : Fx.Set
description : Fx subclass for setting any arbitrary property like text
requires    : core/1.2:Fx

author      : Thomas Aylott
site        : SubtleGradient.com
copyright   : Copyright (c) 2010 Thomas Aylott
license     : MIT-style license
...
*/
Fx.Set = new Class({
	
	Extends: Fx,
	
	options: {
		set:'set',
		property: 'text',
		transformer: function(value){ return value; }
	},
	
	initialize: function(subject, options){
		this.subject = subject;
		this.addEvent('complete', function(){ this.tmpOptions = {} }.bind(this), true);
		this.parent(options);
	},
	
	setOptions: function(options, resetOnComplete){
		this.tmpOptions = {};
		if (resetOnComplete === true){
			this.tmpOptions = options;
			return this;
		}
		Options.prototype.setOptions.apply(this, arguments);
		return this;
	},
	
	set: function(property, to, options){
		if (to === void+0){
			to = property;
			property = null;
		}
		property      = (options && options.property   ) || property || (this.tmpOptions && this.tmpOptions.property   ) || this.options.property;
		var transform = (options && options.transformer) ||             (this.tmpOptions && this.tmpOptions.transformer) || this.options.transformer;
		var set       = (options && options.set        ) ||             (this.tmpOptions && this.tmpOptions.set        ) || this.options.set;
		
		this.subject[set](property, transform.call(this, to));
		this.value = to;
		return this;
	},
	
	start: function(property, from, to, options){
		if (options == to == from == null){
			to = property;
			from = null;
			property = null;
		}
		if (options == to == null){
			to = from;
			from = null;
		}
		
		if (!options) options = {};
		if (property && !options.property) options.property = property;
		this.value = null;
		this.setOptions(options, true);
		from = $pick(from, this.value, 0);
		
		return this.parent(from, to);
	}
	
});

