var Amie = window.Amie || {};

Amie.Ads =
  (function() {
    /* private internals ******************************************************************/
    var _adMutex = false;
    var _adTimeout = 1; // we want to just rotate on all song changes currently, but let's leave in this mechanism

    /* start ad switch counter */
    setTimeout( function() {
        _adMutex = true;
        }, _adTimeout);

    /* Switch Advertising */
    function _switchAdvertising() {
        if( _adMutex ) {
            var ct = _getCurrentTime();

            if( $("#side-ad-content").length > 0 ) {
                $("#side-ad-content").attr("src", "/advertising/external/side?time=" + ct);
                /*
                enable analytics event tracking here?
                var ad = new Object;
                ad.location = 'side';
                Songza.util.Event.trigger('songza.ad_impression', [ad]);
                */
            }

            _adMutex = false;
            setTimeout( function() {
               _adMutex = true;
            }, _adTimeout );
        }
    }

    /* Get current time: used in forceful cache refreshes */
    function _getCurrentTime() {
        var currentTime = new Date();
        var currentSeconds = currentTime.getTime();

        return currentSeconds;
    }
 
    /* public exports ******************************************************************/
    return {
        rotateAds: function() {
            _switchAdvertising();
        }
    }

    })();
