(function (a) {
    a.fn.descriptions = function (b) {
        var g = a.extend({
            search_container_class: "searchbox-container",
            search_field_class: "searchbox",
            description_class: "input-desc"
        }, b);

        function f(i) {
            if (i.val() == i.attr("alt")) {
                i.val("");
                i.removeClass(g.description_class)
            }
        }
        function d(i) {
            if (i.val() == "" || i.val() == i.attr("alt")) {
                i.addClass(g.description_class);
                i.val(i.attr("alt"))
            }
        }
        function c(i) {
            if (i.val() !== "" && i.val() !== i.attr("alt") && a("." + g.search_container_class + " a.cancel-icon").length === 0) {
                i.parent().append('<a href="javascript:void(0);" class="cancel-icon" title="Clear Search Text">Clear Search Text</a>');
                cancel_icon = a("." + g.search_container_class + " a.cancel-icon");
                cancel_icon.click(function () {
                    searchbox = a(this).parent().find("." + g.search_field_class);
                    searchbox.val("");
                    d(searchbox);
                    a(this).remove()
                })
            } else {
                if (i.val() === "") {
                    a("." + g.search_container_class + " a.cancel-icon").remove()
                }
            }
        }
        function h(j) {
            var i = "";
            if (j.attr("alt") !== "") {
                i = ' title="' + j.attr("alt") + '"'
            }
            j.wrap('<div class="' + g.search_container_class + '"></div>');
            container = j.parent();
            container.prepend('<a class="search-icon" href="javascript:void(0);"' + i + ">Search</a>");
            c(j);
            j.keypress(function () {
                c(a(this))
            });
            a("." + g.search_container_class + " a.search-icon").click(function () {
                a(this).parents("form:first").submit()
            })
        }
        function e(i) {
            return i.each(function () {
                var j = a(this);
                if ((j.attr("alt") != "" && j.val() == "") || (j.val() == j.attr("alt"))) {
                    d(j);
                    j.blur(function () {
                        d(j)
                    });
                    j.focus(function () {
                        f(j)
                    })
                }
                if (j.hasClass(g.search_field_class)) {
                    h(j)
                }
            })
        }
        return e(this)
    }
})(jQuery);
(function (a) {
    a.fn.image_fader = function (d) {
        if (a.browser.msie && a.browser.version < 7) {
            return
        }
        var e = this;
        var f = a.extend({}, a.fn.image_fader.defaults, d);

        function c(g) {
            g = a(g);
            span = g.append('<span class="' + f.span_class_name + '" />');
            span.css("cursor", "pointer");
            if (a.browser.msie && a.browser.version >= 7 && f.has_transparent_png_image === true) {
                span.show()
            } else {
                span = g.find("span").css("opacity", 0).css("cursor", "pointer");
                span.stop().fadeTo(f.fade_in_speed, f.fade_in_opacity)
            }
        }
        function b(g) {
            g = a(g);
            span = g.find("span");
            span.stop().fadeTo(f.fade_out_speed, f.fade_out_opacity);
            span.remove("*")
        }
        return this.each(function () {
            elem = a(this);
            elem.hover(function () {
                c(this)
            }, function () {
                b(this)
            })
        })
    };
    a.fn.image_fader.defaults = {
        span_class_name: "image-fader",
        fade_in_speed: 200,
        fade_out_speed: "slow",
        fade_in_opacity: 1,
        fade_out_opacity: 0,
        has_transparent_png_image: true
    }
})(jQuery);
(function (a) {
    a.fn.external_links = function (b) {
        var e = a.extend({
            add_rel: true,
            new_window: true,
            add_class: true,
            add_title: true,
            hostname: location.hostname,
            external_title: "This link opens in a new window",
            class_name: "external",
            local_domain_arr: [],
            new_window_callback: c
        }, b);

        function c() {
            window.open(this.href);
            return false
        }
        function d(f) {
            re = /^(https?:\/\/)([^\/]+).*\/?$/i;
            a(e.local_domain_arr).each(function (h, g) {
                e.local_domain_arr[h] = g.replace(re, "$2")
            });
            return f.each(function () {
                var i = a(this);
                var g = false;
                var h = false;
                if (typeof i.not("[href^=javascript]")[0] !== "undefined") {
                    h = true
                }
                if (h === true) {
                    if (i.attr("rel") === "external") {
                        g = true
                    }
                    if (g === false && i[0].hostname !== e.hostname) {
                        if (e.local_domain_arr.length > 0) {
                            if (a.inArray(i[0].hostname, e.local_domain_arr) === -1) {
                                g = true
                            }
                        } else {
                            g = true
                        }
                    }
                    if (g === true) {
                        if (e.add_rel === true) {
                            i.attr("rel", "external")
                        }
                        if (e.add_class === true) {
                            i.addClass(e.class_name)
                        }
                        if (e.add_title === true) {
                            i.attr("title", e.external_title)
                        }
                        if (e.new_window === true) {
                            i.click(e.new_window_callback)
                        }
                    }
                }
            })
        }
        return d(this)
    }
})(jQuery);
$(function () {
    $("#main-nav ul li ul").mouseenter(function () {
        li = $(this).parent();
        li.addClass("active")
    });
    $("#main-nav ul li ul").mouseleave(function () {
        li = $(this).parent();
        li.removeClass("active")
    });
    $("#main-nav > ul > li").hover(function () {
        $(this).find("ul:first").hide().slideDown();
        $(this).addClass("hover").css("curser", "pointer")
    }, function () {
        ul_length = $(this).find("ul:first").length;
        if (ul_length === 0) {
            $(this).removeClass("hover")
        } else {
            $(this).find("ul:first").slideUp(function () {
                $(this).parent().removeClass("hover")
            })
        }
    });
    $("#logo a").image_fader({
        fade_in_speed: "slow",
        fade_in_opacity: 0.3,
        has_transparent_png_image: false
    });
    $("#donate-btn a").image_fader({
        fade_in_speed: "slow",
        fade_in_opacity: 0.2,
        has_transparent_png_image: false
    });
    $("#programs dd li a").image_fader();
    $("#programs dd li").hover(function () {
        $(this).addClass("hover")
    }, function () {
        $(this).removeClass("hover")
    });
    $("#ciy-social-site-links li a").image_fader();
    (function (l) {
        l.timeago = function (b) {
            if (b instanceof Date) {
                return h(b)
            } else {
                if (typeof b == "string") {
                    return h(l.timeago.parse(b))
                } else {
                    return h(l.timeago.datetime(b))
                }
            }
        };
        var j = l.timeago;
        l.extend(l.timeago, {
            settings: {
                refreshMillis: 60000,
                allowFuture: false,
                strings: {
                    prefixAgo: null,
                    prefixFromNow: null,
                    suffixAgo: "ago",
                    suffixFromNow: "from now",
                    ago: null,
                    fromNow: null,
                    seconds: "less than a minute",
                    minute: "about a minute",
                    minutes: "%d minutes",
                    hour: "about an hour",
                    hours: "about %d hours",
                    day: "a day",
                    days: "%d days",
                    month: "about a month",
                    months: "%d months",
                    year: "about a year",
                    years: "%d years"
                }
            },
            inWords: function (g) {
                var f = this.settings.strings;
                var t = f.prefixAgo;
                var b = f.suffixAgo || f.ago;
                if (this.settings.allowFuture) {
                    if (g < 0) {
                        t = f.prefixFromNow;
                        b = f.suffixFromNow || f.fromNow
                    }
                    g = Math.abs(g)
                }
                var d = g / 1000;
                var u = d / 60;
                var e = u / 60;
                var c = e / 24;
                var s = c / 365;
                var r = d < 45 && i(f.seconds, Math.round(d)) || d < 90 && i(f.minute, 1) || u < 45 && i(f.minutes, Math.round(u)) || u < 90 && i(f.hour, 1) || e < 24 && i(f.hours, Math.round(e)) || e < 48 && i(f.day, 1) || c < 30 && i(f.days, Math.floor(c)) || c < 60 && i(f.month, 1) || c < 365 && i(f.months, Math.floor(c / 30)) || s < 2 && i(f.year, 1) || i(f.years, Math.floor(s));
                return l.trim([t, r, b].join(" "))
            },
            parse: function (b) {
                var c = l.trim(b);
                c = c.replace(/-/, "/").replace(/-/, "/");
                c = c.replace(/T/, " ").replace(/Z/, " UTC");
                c = c.replace(/([\+-]\d\d)\:?(\d\d)/, " $1$2");
                return new Date(c)
            },
            datetime: function (c) {
                var b = l(c).get(0).tagName.toLowerCase() == "time";
                var d = b ? l(c).attr("datetime") : l(c).attr("title");
                return j.parse(d)
            }
        });
        l.fn.timeago = function () {
            var b = this;
            b.each(m);
            var c = j.settings;
            if (c.refreshMillis > 0) {
                setInterval(function () {
                    b.each(m)
                }, c.refreshMillis)
            }
            return b
        };

        function m() {
            var b = n(this);
            if (!isNaN(b.datetime)) {
                l(this).text(h(b.datetime))
            }
            return this
        }
        function n(c) {
            c = l(c);
            if (c.data("timeago") === undefined) {
                c.data("timeago", {
                    datetime: j.datetime(c)
                });
                var b = l.trim(c.text());
                if (b.length > 0) {
                    c.attr("title", b)
                }
            }
            return c.data("timeago")
        }
        function h(b) {
            return j.inWords(k(b))
        }
        function k(b) {
            return (new Date().getTime() - b.getTime())
        }
        function i(d, b) {
            var c = l.isFunction(d) ? d(b) : d;
            return c.replace(/%d/i, b)
        }
        document.createElement("abbr");
        document.createElement("time")
    })(jQuery);
    $(".timestamp").timeago();
    $("input[type=text]").descriptions();
    var a = (window.location.host.search("local") !== -1) ? "http://local.media.ciy.com/" : "http://media.ciy.com/";
    $("a").external_links({
        local_domain_arr: [a]
    })
});
