/*jslint devel: false, browser: true, undef: true, unparam: true, sloppy: true, vars: true, white: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
/*global $, Effect, Store, Tx */

var SSFav = {};

/*
 * Effect run after an item is added to the stylebook.
 */
SSFav._isRunningFavoriteEffect = false;
SSFav.addFavsShouldRefresh = false;
SSFav.updateBrandsShouldRefresh = false;

SSFav.pulseFavorites = function(linkName)
{
    var link = $(linkName);
    if (!SSFav._isRunningFavoriteEffect && link !== null) {
        SSFav._isRunningFavoriteEffect = true;

        Effect.Pulsate(linkName, {

            beforeStart : function() {
            },

            afterFinish : function() {
                var elt = link;
                elt.setStyle({color: '', zoom: ''});
                SSFav._isRunningFavoriteEffect = false;
            }
        });
    }
};

SSFav.addFavoriteEffect = function()
{
    Store.haveAddedFavorites = true;
    SSFav.pulseFavorites('mystylebooklink');
    if (SSFav.addFavsShouldRefresh) {
        Tx.windowRefresh(true);
    }
};

SSFav.removeFavoriteOnStylebookEffect = function()
{
    $('favoritesBrowser').mcontext.discardAndReload();
    SSFav.pulseFavorites('mystylebooklink');
};

SSFav.updateMyBrandsEffect = function()
{
    SSFav.pulseFavorites('mybrandslink');
    if (SSFav.updateBrandsShouldRefresh) {
        Tx.windowRefresh(true);
    }
};

SSFav.flashLink = function(link)
{
    Effect.Pulsate(link, { duration:0.4, pulses:2 });
};

