/**
* AFW module Fader
* 
*/
afw.module.fader = 
{
    fade : function(aElements, sFadeDir, iOpacityEnd, iOpacityStep, iOpacityStart)
    {
        if(aElements == undefined || !aElements || sFadeDir == undefined || iOpacityEnd == undefined)
            return false;
        sFadeDir = sFadeDir.toUpperCase();
        if(sFadeDir != 'IN' && sFadeDir != 'OUT')
            return false;
        if(iOpacityStep == undefined)
            iOpacityStep = 3;
        if(!afw.common.functions.isArray(aElements))
        {
            aElements = [aElements];
        }

        var iOpacity = (iOpacityStart != undefined) ? iOpacityStart : afw.common.functions.getPrototypeValue(aElements[0], 'Opacity');
        if(iOpacity === false)
            return false;

        var intervalReference = afw.common.functions.getPrototypeValue(aElements[0], 'ElementFade');
        if(intervalReference)
            clearInterval(intervalReference);

        afw.common.functions.setPrototype(aElements[0], 'ElementFade', setInterval(function()
        {
            if(sFadeDir == 'IN')
                iOpacity = (iOpacity + iOpacityStep > iOpacityEnd) ? iOpacityEnd : iOpacity + iOpacityStep;
            else
                iOpacity = (iOpacity - iOpacityStep < iOpacityEnd) ? iOpacityEnd : iOpacity - iOpacityStep;

            for(var i = 0, m = aElements.length; i < m; ++i)
            {
                afw.common.functions.setOpacity(aElements[i], iOpacity);
                if(iOpacity == iOpacityEnd)
                {
                    aElements[i].style.filter = '';
                }
            }
            if(iOpacity == iOpacityEnd)
            {
                clearInterval(afw.common.functions.getPrototypeValue(aElements[0], 'ElementFade'));
                afw.common.functions.setPrototype(aElements[0], 'ElementFade', false);
            }
        }, 30));
    }
};
