jQuery.extend($.easing, {eIOQ: function (b, c, a, d, e) {
    return (c /= e / 2) < 1 ? d / 2 * c * c + a : -d / 2 * ((c -= 1) * (c - 2) - 1) + a; 
}}); // add one of Robert Penner's easing equations

(function ($) {
    var ticker1 = $('#ticker > li > ul').eq(0),
        ticker2 = $('#ticker > li > ul').eq(1),
        t1 = new Ticker(ticker1, 3),
        t2 = new Ticker(ticker2, 2),
        tick = setInterval(function () {
            t1.tick();
            t2.tick();
        }, 31);
    
// nsf slideme function for toggle boxes
    function slideme(a, b, c) { 
        var el, dur, ease;
        el = a.data("r") ? a : a.parent("ul").children("li:last");
        dur = c || 333;
        ease = b || "swing";
        
        el.data('r') || el.data('r', true).animate({
            top: el.height()
        }, dur, ease, function () { 
            $.data(this, 'r', false);
        });
    }

    function Ticker(list, spd) {
        this.ticker = list;
        this.spd = spd;
        this.lnkl = this.ticker.children('li').length;
        this.wol = 0;
        this.ml = 0;
        this.ani = true;

        this.tick = function () {
            if (this.ani) {
                this.ml > -this.wol ? this.ml -= this.spd : this.ml = 0;
                this.ticker.css('marginLeft', this.ml);
            }
        };

        while (this.lnkl--) {
            this.wol += this.ticker.children('li').eq(this.lnkl).width();
        }

        this.ticker.css({
            width: this.wol * 2,
            visibility: 'visible',
            marginLeft: 0
        });
        
        this.ticker.children('li').clone().appendTo(this.ticker);
    }

    
    // nsf toggle boxes bind event listener
    $('#promos').click(function (e) {
        if (e.target.offsetParent.nodeName.toLowerCase() !== 'p') {
            slideme($(e.target).closest('li'), 'eIOQ');
        }
        if (e.target.offsetParent.nodeName.toLowerCase() === 'h2') {
            e.preventDefault();
        }
    });

    ticker1.bind('mouseenter mouseleave', function () {
        t1.ani = t1.ani ? false : true;
    });
    ticker2.bind('mouseenter mouseleave', function () {
        t2.ani = t2.ani ? false : true;
    });

// no practical value but I hate seeing those divs in firebug
$(function () { $('.bcms-searchable > *').unwrap()});

// 1 sec. delayed reveal on first promo as click invite
setTimeout(function () {$('#promos > ul:first-child > li:first-child').click()}, 1E3);

// inject page curl markup
$('body').prepend('<div id="nsf-pageflip"><a href="/cs/about_ian/spread_the_word_about_ian_overview"><img src="/site/images-project/pageFlipSplash.png" alt="Support" /></a><div id="nsf-msgblock"></div></div>'); 


var pf = $('#nsf-pageflip img'),
    ms = $('#nsf-msgblock');
    
pf.newH = 222;
pf.newW = 207;
pf.origH = parseInt(pf.css('height'));
pf.origW = parseInt(pf.css('width'));

ms.newH = 213;
ms.newW = 200;
ms.origH =  parseInt(ms.css('height'));
ms.origW = parseInt(ms.css('width'));

    pf.bind('mouseenter', function () {
        pf.stop().animate({height: pf.newH, width: pf.newW}, 300, 'eIOQ');
        ms.stop().animate({height: ms.newH, width: ms.newW}, 320, 'eIOQ' );
    }).bind('mouseleave click', function () {
        pf.stop().animate({height: pf.origH, width: pf.origW}, 220, 'eIOQ');
        ms.stop().animate({height: ms.origH, width: ms.origW}, 200, 'eIOQ');
    });


}(jQuery));

