/* Javascript Document
 *
 * Created by fire.crow@firecrow.com 2009
 */

(function(){
    var path = window.com.firecrow;

    var alert = function(message)
    {
        if(path.alert) path.alert(message);
        else window.alert(message);
    } 
    
    /**
     * @params
     *  node            - html element
     *  prop            - name of style property to change
     *  endColor        - [r,g,b] 
     */
    function ColorAnim(node,prop,endColor)
    {
        this.map = {r:0,g:1,b:2}; 
        this.node = node;
        this.prop = prop;

        this.currentColor = new path.Color(this.node.style[prop]);
        this.startColor = this.currentColor.values.get(); 
        this.endColor = endColor; 
        this._currentValue = 0; 
        this._timeout = null;
        this._increment = null;
    }
    var members  =  {
        setColor: function(value){
           var newRGB = path.Color.getTransform(this.startColor, this.endColor, value); 
           this.currentColor.setRGB(newRGB);
           this.node.style[this.prop] = this.currentColor.toString(); 
        }, 
        _setValue: function(value)
        {
            if(value > 100) value = 100;
            this.setColor(value); 
        },
        toString: function(){
            return '[object ColorAnim{from:' + this.startColor + ' to:' +  this.endColor +'} ]'; 
        }, 
       start : function(duration,increment) 
       {
           if(this._animInProcess) return;
           this._startValue = 0;
           this._endValue = 100;
           this._duration = duration;
           this._increment = increment;
           this._currentValue = this._startValue;
           this._animInProcess = true;
           this._animSetup();
           this._animIncrement();
       } 
    } 
    
    var parentMembers = path.BasicAnim.prototype;
    for(s in parentMembers)
        ColorAnim.prototype[s] = parentMembers[s];

    for(s in members)
        ColorAnim.prototype[s] = members[s];

    path['ColorAnim'] = ColorAnim;
})();
