window.ntwrk = window.ntwrk || {};
window.ntwrk.bounds = window.ntwrk.bounds || {};

jQuery.extend(ntwrk.bounds, {
    Bounds: function (b, d, c, a) {
        this.x = b;
        this.y = d;
        this.width = c;
        this.height = a
    }
});
jQuery.extend(ntwrk.bounds.Bounds.prototype, {
    encloses: function (a, b) {
        return a > this.x && a < this.x + this.width && b > this.y && b < this.y + this.height
    },
    toString: function () {
        return "(" + this.x + "," + this.y + ") " + this.width + "x" + this.height
    }
});
(function (a) {
    a.fn.extend({
        bounds: function () {
            var c = this.eq(0);
            var b = c.offset();
			if (!b) return false;
            return new ntwrk.bounds.Bounds(b.left, b.top, c.outerWidth(), c.outerHeight())
        }
    })
})(jQuery); 
 
(function (A) {
    A.extend(window, {
        NetworkTip: {
            parseIntDefault: function (B, D) {
                D = D || 0;
                var C = parseInt(B);
                return isNaN(C) ? D : C
            },
            clearBounds: function () {
                this.data("bounds", [])
            },
            addToBounds: function (B) {
                if (!this.data("bounds")) {
                    this.data("bounds", [])
                }
                this.data("bounds").push(B)
            },
            enclosing: function (B, D) {
                if (!this.data("bounds")) {
                    this.data("bounds", [])
                }
                var C = false;
                A.each(this.data("bounds"), function (F, E) {
                    if (E.encloses(B, D)) {
                        C = true
                    }
                });
                return C
            },
            clearScrollInterval: function () {
                clearInterval(this.data("interval"))
            },
            setScrollInterval: function (B) {
                if (this.data("interval")) {
                    this.clearScrollInterval()
                }
                this.data("interval", setInterval(B, 15))
            },
            duplicateContent: function (B) {
                var C = 0;
                B.children().each(function () {
                    C += A(this).outerWidth(true);
                    B.append(A(this).clone())
                });
                B.css({
                    zoom: 1,
                    width: (2 * C) + "px"
                });
                return C
            },
            initScroller: function () {
                var C = this;
                var E = this.duplicateContent(C);
                var B = NetworkTip.parseIntDefault(C.css("left"), 0);
                var D = function () {
                    B = (B % E) - 1;
                    C.css({
                        left: B
                    })
                };
                C.bind("networkEnter", function () {
                    C.clearScrollInterval()
                }).bind("networkLeave", function () {
                    C.setScrollInterval(D)
                }).trigger("networkLeave")
            }
        }
    });
    A.extend(A.fn, {
        networkTip: function () {
            var B = false;
            var C = A(this);
            A.extend(C, NetworkTip);
            C.initScroller();
            C.find("li a").each(function () {
                var D = A(this).closest("li");
                var E = {
                    mouseenter: function (G) {
                        var F = A(this);
                        A("#networks-scroller-content .inner").trigger("networkLeave");
                        if (C.oldCapturedNetwork) {
                            C.oldCapturedNetwork.trigger("networkLeave")
                        }
                        C.oldCapturedNetwork = F;
                        C.addToBounds(F.bounds());
                        if (C.enclosing(G.pageX, G.pageY)) {
                            A("#networks-scroller-content .inner").trigger("networkEnter");
                            F.trigger("networkEnter");
                            var H = function (I) {
                                if (!C.enclosing(I.pageX, I.pageY)) {
                                    A("#networks-scroller-content .inner").trigger("networkLeave");
                                    F.trigger("networkLeave")
                                }
                            };
                            A(document).bind("mousemove", H);
                            F.bind("networkLeave", function (I) {
                                C.clearBounds();
                                A(document).unbind("mousemove", H)
                            })
                        }
                    },
                    networkleave: function (G) {
                        clearTimeout(B);
                    }
                };
                A(this).mouseenter(E.mouseenter).bind("networkEnter", E.networkenter).bind("networkLeave", E.networkleave)
            });
            return this
        }
    })
})(jQuery);


function FrontPage() {
    return jQuery.extend(this, {
        $networks: jQuery("#networks-scroller-content"),

    })
}


jQuery.extend(FrontPage.prototype, {
	init: function () {
        this.initNetworkHover();
    },
    initNetworkHover: function () {
        var A = this;
        jQuery("#networks-scroller-content ul").networkTip()
    }
});
(jQuery);
