if (!window.currentScript) window.currentScript = function () { var s = document.getElementsByTagName('script'); return s[s.length - 1]; };
function $(e) { return (typeof e == 'string') ? document.getElementById(e) : e; }
window.isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]' }
window.multicast = function (f) { return isArray(f) ? function() { for (var i = 0; i < f.length; i++) f[i].apply(this, arguments); } : f; }
window.__defineGetter__("width",function(){return window.innerWidth||(document.documentElement||document.body).clientWidth});
window.__defineGetter__("height",function(){return window.innerHeight||(document.documentElement||document.body).clientHeight});
window.isScrolledTo = function(e,offset){e=$(e);var d=window.height-(offset||0);do {d-=e.offsetTop-e.scrollTop;if(d>=0)return true}while(e=e.offsetParent)return false;}

window.updateScroll = {}; window.onscroll = function() { window.updateScroll = {}; };
window.updateResize = {}; window.onresize = function() { window.updateResize = {}; };

window._scrollList = [];
window._startWaitForScroll = function() {
    if (!window._startWaitForScrollSI) window._startWaitForScrollSI = setInterval(
        function() {
            if (!(updateScroll.waitForScroll && updateResize.waitForScroll)) {
                updateScroll.waitForScroll = true; updateResize.waitForScroll = true;
                for (var i = 0; i < _scrollList.length; i ++) {var s = _scrollList[i];
                    if (isScrolledTo(s.elem, s.offset)) { _scrollList.splice(i,1); s.callback(); }
                }
            }
            if (_scrollList.length == 0) { clearInterval(_startWaitForScrollSI); delete _startWaitForScrollSI; }
        }, 250);
}

window.waitForScroll = function(elem, offset, callback) { if (isScrolledTo(elem, offset)) callback(); else { _scrollList.push({elem: elem, offset: offset, callback: callback}); delete updateScroll.waitForScroll; _startWaitForScroll(); } }

window.Animation = function (e) {e=e||{}
    var v = 0, si, sttr = multicast(e.setter);
    var time = e.time, frequency = e.frequency || 100, inc = 1 / (time * frequency);

    var me = {
        get time() { return time; },
        set time(t) { time = t; inc = 1 / (time * frequency); },
        get frequency() { return frequency; },
        set frequency(f) { frequency = f; inc = 1 / (time * frequency); },
        callback: e.callback,

        start: function (callback) {
            if (callback) me.callback = callback;
            v = 0;
            if (si) clearInterval(si);
            si = setInterval(function() {
                v += inc;
                if (v < 1) {
                    sttr(v);
                } else {
                    sttr(1);
                    if (me.callback) me.callback();
                    clearInterval(si);
                    si = null;
                }
            }, 1000 / me.frequency); },

        stop: function () {if (si) clearInterval(si); },
        get value() { return v; },
        set value(x) { v = x; sttr(v); },
        get setter() { return sttr; },
        set setter(s) { sttr = multicast(s); }
    };   
    
    return me;
}

window.interpolators = {
    linear: function (x) { return x },
    sine: function (x) { return 0.5 * (1 - Math.cos(x * Math.PI)) },
    sineend: function (x) { return Math.sin(x * Math.PI * 0.5) },
    sinebegin: function (x) { return 1 - Math.cos(x * Math.PI * 0.5) }
}

window.setters = {
    opacity: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.opacity = v; el.style.filter = 'alpha(opacity=' + 100 * v + ')'; }
    },

    left: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.left = v + 'px'; }
    },
    top: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.top = v + 'px'; }
    },
    right: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.right = v + 'px'; }
    },
    bottom: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.bottom = v + 'px'; }
    },
    width: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.width = v + 'px'; }
    },
    height: function (el, a, b, int) {el=$(el); int=int||interpolators.linear;
        return function (v) { v = a + int(v) * (b - a); el.style.height = v + 'px'; }
    }
}
