﻿
function class_FadeEffect(a_arr, a_start, a_end, a_millisec, a_callback) 
{
    this.class_BaseEffect();
    this.vp_arr = a_arr;
    this.vp_start = a_start;
    this.vp_end = a_end;
    this.vp_millisec = a_millisec;
    this.vp_callback = a_callback;
    this.vp_curOpicity = a_start;
    this.vp_opicityJump = 0;



    this.f_init = function() 
    {
        // calculate opcity jump
        var v_rounds = this.vp_millisec / m_app.vp_EffectsManager.vp_frameRate;
        if (a_start > a_end) 
        {
            this.vp_opicityJump = ((a_start - a_end) / v_rounds) * -1;

        }
        else 
        {
            this.vp_opicityJump = (a_end-a_start) / v_rounds;
        }
        this.f_changeOpac(this.vp_start);
    };


    this.f_run = function() 
    {
        this.vp_curOpicity = this.vp_curOpicity+this.vp_opicityJump;
        if ((a_start > a_end && this.vp_curOpicity<=this.vp_end) || (a_start < a_end && this.vp_curOpicity>=this.vp_end))
        {
            this.f_changeOpac(this.vp_end);
            return false;
        }
        else
        {
            this.f_changeOpac(this.vp_curOpicity);
            return true;
        }
        
    };


    this.f_changeOpac = function(a_opacity) 
    {
        for (var v_i = 0; v_i < this.vp_arr.length; v_i++) 
        {
            var v_obj = document.getElementById(this.vp_arr[v_i]);
            if (v_obj != null) 
            {
                v_obj = v_obj.style;
                if (a_opacity > 95) 
                {
                    v_obj.opacity = "";
                    v_obj.MozOpacity = "";
                    v_obj.KhtmlOpacity = "";
                    v_obj.filter = "";
                }
                else 
                {
                    v_obj.opacity = (a_opacity / 100);
                    v_obj.MozOpacity = (a_opacity / 100);
                    v_obj.KhtmlOpacity = (a_opacity / 100);
                    v_obj.filter = "alpha(opacity=" + a_opacity + ")";
                }
                
            }
        }
    };

    this.f_cleanUp = function() {
        if(this.vp_callback) this.vp_callback();
    };

};
f_copyPrototype(class_FadeEffect, class_BaseEffect);

