
jQuery.fn.exists = function () {
    return jQuery(this).length > 0
};
var setWindowLocation = function (a) {
    window.location.hash = a
};
$(document).ready(function () {
    $("a").css("outline", "none");
    $(".clearable").focus(function () {
        var el = $(this);
        if (el.val() == el.attr("title")) {
            el.val("")
        }
    });
    $(".clearable").blur(function () {
        var el = $(this);
        if (el.val() === "") {
            el.val(el.attr("title"))
        }
    });
    $('input[type="hidden"]').css({
        position: "absolute",
        top: "0",
        left: "-9999em"
    });
    $(".pagination a").live("click", function () {
        $(".pagination").html("Loading content...");
        $.get(this.href, null, null, "script");
        return false
    });
    $("#aboutduck-slides").cycle({
        timeout: 0,
        speed: 1000,
        easing: "easeInOutQuad",
        pager: ".menu",
        next: ".next",
        pagerAnchorBuilder: function (idx, slide) {
            idxNUM = idx + 1;
            return '<a href="#">' + idxNUM + "</a>"
        }
    });
    /*$(".tweet").tweet({
        username: "crushlovely",
        join_text: "auto",
        avatar_size: 0,
        count: 1,
        auto_join_text_default: "we said,",
        auto_join_text_ed: "we",
        auto_join_text_ing: "we were",
        auto_join_text_reply: "we replied to",
        auto_join_text_url: "we were checking out",
        loading_text: "loading tweets..."
    }).bind("empty", function () {
        $("#latest-tweet").hide()
    });*/
    $("#lovelies li:nth-child(2n)").addClass("last");
    $("#client-list li:nth-child(3n)").addClass("last");
    $("#client-list li:nth-child(2n)").addClass("");
    $("#follow-link").click(function (e) {
        $("#follow").slideToggle("slow");
        e.preventDefault()
    });
    $(".full-capabilities").hide();
    $("#view-full-capabilities").click(function (e) {
        $(".full-capabilities").slideToggle("slow");
        e.preventDefault()
    });

});
var amountVisible = function (c) {
    var a = $(window).scrollTop();
    var b = a + $(window).height();
    var e = c.offset().top;
    var d = e + c.height();
    if (d > a && d < b) {
        return d - a
    } else {
        return b - e
    }
};
var fetchMatchingNavItem = function (a) {
    return $("#" + $(a).attr("id") + "-link").parent()
};
var setCurrentClass = function (a) {
    a.addClass("current");
    a.siblings("#mainmenu li").removeClass("current")
};
var determineCurrentNodeAndSetNav = function () {
    var a = null;
    var b = $(".scroll-item:in-viewport");
    if (b.get(0).id == "header") {
        a = b.get(0)
    } else {
        b.each(function (c) {
            var d = $(this);
            if (a == null || amountVisible(d) >= amountVisible(a)) {
                a = d
            }
        })
    }
    current_index = $(".scroll-item").index(a);
    if (a && a.id == "header") {
        $("#duckimage #mainmenu ol li").removeClass("current")
    } else {
        setCurrentClass(fetchMatchingNavItem(a))
    }
};
$(document).ready(function () {
    var c = $(".scroll-item");
    var b = 0;
    var a;
    $(window).scroll(function () {
        determineCurrentNodeAndSetNav()
    });
    $("#duckimage #mainmenu #logo, #coda #pop-back-up").click(function (d) {
        $.scrollTo("#header", 800);
        a = $("#header");
        b = c.index(a);
        d.preventDefault()
    });
    $("#duckimage #mainmenu ol li").click(function (f) {
        var d = $(this).children("a").get(0).href.split("#")[1];
        $.scrollTo("#" + d, 800);
        a = $("#" + d);
        b = c.index(a);
        f.preventDefault()
    });
    $("#duckimage .scroll-link").click(function (g) {
        var d = $(this);
        var f = d.attr("href").split("#")[1];
        var h = $($("#" + f + "-link").parent());
        $.scrollTo("#" + f, 800);
        a = $("#" + f);
        b = c.index(a);
        g.preventDefault()
    });
    $(document).keydown(function (d) {
        switch (d.keyCode) {
        case 39:
            a = c[++b];
            if (a) {
                $.scrollTo(a, 800)
            } else {
                b = c.length - 1
            }
            break;
        case 37:
            a = c[--b];
            if (a) {
                $.scrollTo(a, 800)
            } else {
                b = 0
            }
            break
        }
    })
});
$(document).ready(function () {
    $(".expansion").hide();
    $(".read-more li").click(function (d) {
        var a = $(this);
        var b = a.children().get(0).href.split("#")[1];
        var c = $("#" + b);
        if (c.is(":visible")) {
            a.removeClass("current");
            c.hide()
        } else {
            a.siblings().removeClass("current");
            a.addClass("current");
            c.siblings(".expansion").hide();
            c.show();
            $.scrollTo("#read-more", 800)
        }
        determineCurrentNodeAndSetNav();
        d.preventDefault()
    })
});
