var JUVO = JUVO || {};
var SDVS = SDVS || {};

JUVO.colorThrobber = function(elementId, fromColor, toColor, duration) {
    var _self = this;
    duration = duration || 2500;

    _self.$element = $('#' + elementId);

    if (!_self.$element) {
        return;
    }

    _self.animate = function() {
        _self.$element.animate({ backgroundColor: toColor }, duration);
        _self.$element.animate({ backgroundColor: fromColor }, duration, _self.animate);
    };
    _self.stop = function() {
        _self.$element.stop(true);
    };
    _self.animate();
};

SDVS.animateBanner = function($item) {
    var _self = this;
    $item = $item || $('#safetyHopeEmpowerBanner a:first');
    var $next = $item.nextAll('a:first');

    $item.animate({ color: 'rgb(117,59,143)' }, 750);
    $item.animate({ color: 'rgb(153,153,153)' }, $next.length ? 1000 : 3000, false, function() {
        if ($next.length) {
            _self.animateBanner($next);
        }
    });
};

SDVS.randomEscapeBtn = function(btnId) {
    var urls = [
        'http://www.google.com/#hl=en&sugexp=ldymls&xhr=t&q=gifts+for+him',
        'http://www.google.com/#hl=en&sugexp=ldymls&xhr=t&q=make+him+happy',
        'http://www.google.com/#hl=en&sugexp=ldymls&xhr=t&q=diets+that+work'
    ];

    $('#' + btnId).click(function() {
        window.location = urls[Math.round(Math.random() * urls.length) % urls.length];
    })
}

$(function() {
    SDVS.randomEscapeBtn('exitbtn');
    SDVS.animateBanner();
    var exitAnim = new JUVO.colorThrobber('exitbtn', 'rgb(117,59,143)', 'rgb(170,0,0)', 2500);
});

