(function (k) {
    if (window.fancyScroll && typeof window.fancyScroll == 'function') return;
    fancyScroll = function (s) {
        this.map = new Array();
        this.scrollTimer = 0;
        this.settings = {
            easingRate: 15,
            easingTime: 1000,
            easingFunc: 'easeInOutCubic',
            goTop: false,
            goTopText: 'top',
            goTopClass: 'fancyscroll-gotop',
            goTopShowAfter: '899px'
        };
        if (s && typeof s == 'object') {
            for (var f in this.settings) {
                if (s[f] != k) this.settings[f] = s[f]
            }
        }
        var g = document.getElementsByTagName('div');
        for (var i = 0; i < g.length; i++) {
            if (/fancyscroll-background/.test(g[i].className)) {
                this.map.push({
                    'self': g[i],
                    'top': this.getAbsolutePosition(g[i])[1],
                    'height': g[i].offsetHeight,
                    'offset': parseInt(g[i].getAttribute('offset')),
                    'position': this.getBackgroundPosition(g[i])
                })
            }
        }
        if (this.settings.goTop) {
            this.goTop = document.createElement('div');
            this.goTop.setAttribute('id', this.settings.goTopClass);
            this.goTop.appendChild(document.createTextNode(this.settings.goTopText));
            this.addScroll(this.goTop, this.map[0].self);
            document.body.appendChild(this.goTop);
            this.goTop.style.visibility = 'hidden'
        }
		
        var h = function (e) {
                for (var i = 0; i < this.map.length; i++) {
                    var a = this.map[i];
                    var b = window.innerHeight || document.documentElement.offsetHeight;
                    var c = window.pageYOffset || document.documentElement.scrollTop;
                    var d = a.position.x + 'px ' + (a.position.y + a.offset * (c - a.top) / a.height) + 'px';
                    a.self.style.backgroundPosition = d
                }
                if (this.goTop) {
                    this.goTop.style.visibility = 'hidden';
                    if (c > parseInt(this.settings.goTopShowAfter)) this.goTop.style.visibility = 'visible' 
                }
				if (c == 0) {
					document.getElementById('link1').setAttribute('class', 'selected');
					document.getElementById('link2').setAttribute('class', '');
					document.getElementById('link3').setAttribute('class', '');
					document.getElementById('saelens').setAttribute('class', '');
				}
				if (c > 899 && c < 1700) {
					document.getElementById('link1').setAttribute('class', '');
					document.getElementById('link2').setAttribute('class', 'selected');
					document.getElementById('link3').setAttribute('class', '');
					document.getElementById(this.settings.goTopClass).setAttribute('class', 'postula');
					document.getElementById('saelens').setAttribute('class', 'postula');
				}
				if (c > 1701) {
					document.getElementById('link1').setAttribute('class', '');
					document.getElementById('link2').setAttribute('class', '');
					document.getElementById('link3').setAttribute('class', 'selected');
					document.getElementById(this.settings.goTopClass).setAttribute('class', 'proyectos');
					document.getElementById('saelens').setAttribute('class', 'proyectos');
				}
            };
        if (window.addEventListener) {
            window.addEventListener('scroll', this.setScope(h), false)
        } else if (window.attachEvent) {
            window.attachEvent('onscroll', this.setScope(h))
        }
        var j = function (e) {
                clearInterval(this.scrollTimer)
            };
        if (window.addEventListener && /firefox/i.test(navigator.userAgent)) {
            window.addEventListener('DOMMouseScroll', this.setScope(j), false)
        } else {
            window.onmousewheel = this.setScope(j)
        }
    };
    var l = fancyScroll.prototype;
    l.scroll = function (a) {
        if (typeof a == 'string') {
            a = document.getElementById(a)
        }
        var b = window.pageYOffset || document.documentElement.scrollTop;
        var c = this.getAbsolutePosition(a)[1];
        var d = 0;
        var e = this.settings.easingFunc;
        if (typeof e == 'string') e = fancyScroll.easeFX[this.settings.easingFunc] || fancyScroll.easeFX.easeOutCubic;
        var f = function () {
                if (d < this.settings.easingTime) {
                    d += this.settings.easingRate;
                    window.scroll(0, e(d, b, c - b, this.settings.easingTime))
                } else {
                    clearInterval(this.scrollTimer)
                }
            };
        clearInterval(this.scrollTimer);
        this.scrollTimer = setInterval(this.setScope(f), this.settings.easingRate);
        return void(0)
    };
    l.addScroll = function (a, b) {
        if (arguments.length != 2) throw 'bindScroll() requires 2 arguments';
        if (typeof a == 'string') a = document.getElementById(a);
        var c = function (e) {
                if (e.preventDefault) {
                    e.preventDefault()
                }
                e.returnValue = false;
                this.scroll(b)
            };
        if (a.addEventListener) a.addEventListener('click', this.setScope(c), false);
        else if (a.attachEvent) a.attachEvent('onclick', this.setScope(c))
    };
    l.setScope = function (b) {
        var a = this;
        return function (e) {
            b.call(a, e)
        }
    };
    l.getAbsolutePosition = function (t) {
        if (t == null) {
            return [0, 0]
        } else {
            var a = t.offsetLeft;
            var b = t.offsetTop;
            var c = arguments.callee(t.offsetParent);
            return [a + c[0], b + c[1]]
        }
    };
    l.getBackgroundPosition = function (e) {
        if (typeof e == 'string') e = document.getElementById(e);
        var a = '0px 0px';
        if (window.getComputedStyle) {
            a = window.getComputedStyle(e, null).backgroundPosition
        } else if (e.currentStyle) {
            if (e.currentStyle.backgroundPosition) a = e.currentStyle.backgroundPosition;
            else if (e.currentStyle.backgroundPositionX) {
                a = e.currentStyle.backgroundPositionX + ' ' + e.currentStyle.backgroundPositionY
            }
        }
        return {
            x: parseInt(a.split(' ')[0]),
            y: parseInt(a.split(' ')[1])
        }
    };
    fancyScroll.easeFX = {
        easeInElastic: function (t, b, c, d) {
            var s = 1.70158;
            var p = 0;
            var a = c;
            if (t == 0) return b;
            if ((t /= d) == 1) return b + c;
            if (!p) p = d * .3;
            if (a < Math.abs(c)) {
                a = c;
                var s = p / 4
            } else var s = p / (2 * Math.PI) * Math.asin(c / a);
            return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
        },
        easeOutElastic: function (t, b, c, d) {
            var s = 1.70158;
            var p = 0;
            var a = c;
            if (t == 0) return b;
            if ((t /= d) == 1) return b + c;
            if (!p) p = d * .3;
            if (a < Math.abs(c)) {
                a = c;
                var s = p / 4
            } else var s = p / (2 * Math.PI) * Math.asin(c / a);
            return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b
        },
        easeInOutElastic: function (t, b, c, d) {
            var s = 1.70158;
            var p = 0;
            var a = c;
            if (t == 0) return b;
            if ((t /= d / 2) == 2) return b + c;
            if (!p) p = d * (.3 * 1.5);
            if (a < Math.abs(c)) {
                a = c;
                var s = p / 4
            } else var s = p / (2 * Math.PI) * Math.asin(c / a);
            if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
            return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b
        },
        easeInBack: function (t, b, c, d, s) {
            if (s == k) s = 1.70158;
            return c * (t /= d) * t * ((s + 1) * t - s) + b
        },
        easeOutBack: function (t, b, c, d, s) {
            if (s == k) s = 1.70158;
            return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b
        },
        easeInOutBack: function (x, t, b, c, d, s) {
            if (s == k) s = 1.70158;
            if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
            return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b
        },
        easeInQuint: function (t, b, c, d) {
            return c * (t /= d) * t * t * t * t + b
        },
        easeOutQuint: function (t, b, c, d) {
            return c * ((t = t / d - 1) * t * t * t * t + 1) + b
        },
        easeInOutQuint: function (t, b, c, d) {
            if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
            return c / 2 * ((t -= 2) * t * t * t * t + 2) + b
        },
        easeInCubic: function (t, b, c, d) {
            t /= d;
            return c * t * t * t + b
        },
        easeOutCubic: function (t, b, c, d) {
            t /= d;
            t--;
            return c * (t * t * t + 1) + b
        },
        easeInOutCubic: function (t, b, c, d) {
            t /= d / 2;
            if (t < 1) return c / 2 * t * t * t + b;
            t -= 2;
            return c / 2 * (t * t * t + 2) + b
        },
        linear: function (t, b, c, d) {
            return c * t / d + b
        }
    }
})();
