Cufon.replace("h1, h2, h3, h4, #footer-nav li a, footer aside p, a.twit-link, header #enter, .freeform .cufonify, #buttons button", { fontFamily: 'Agenda-BoldCondensed' });
Cufon.replace("#nav li a", { fontFamily: 'Agenda-BoldCondensed' });
Cufon.replace("#quick-links li a", { fontFamily: 'Agenda-BoldCondensed' });
Cufon.replace("h5, legend", { fontFamily: 'Agenda-LightItalic' });
Cufon.replace("header li, div.archive ol li a", { fontFamily: 'Agenda' });

$(document).ready(function () {

    $("#nav li a").mouseenter(refreshNavIn);
    $("#nav li a").mouseleave(refreshNavOut);
    $("#quick-links li a").mouseenter(refreshLinksIn);
    $("#quick-links li a").mouseleave(refreshLinksOut);

    $(window).resize(setFooterHeight());

    var resizeTimer;
    $(window).resize(function () {
        clearTimeout(resizeTimer);
        resizeTimer = setFooterHeight();
    });

//    $(".tweets li").each(function () {
//        var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
//        var tweet = $(this).html().replace(exp, "<a href='$1'>$1</a>");
//        var replace = tweet.replace(/(^|\s)@(\w+)/g, '$1<a href="http://www.twitter.com/$2">@$2</a>');
//        $(this).html(replace.replace(/(^|\s)#(\w+)/g, '$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>'));
//    });

//    $('#twitter').jcarousel({
//        vertical: true,
//        scroll: 1,
//        animation: 'slow',
//        auto: 20,
//        visible: 3,
//        buttonNextHTML: null,
//        buttonPrevHTML: null
//    });

    $(".sponsor-slider").each(function () {

        if ($("ul", this).children().length > 1) {
            $(this).jCarouselLite({
                auto: 4000,
                circular: true,
                speed: 2000,
                scroll: 1,
                visible: 1,
                fade: true,
                beforeStart: function (obj) {
                    $('#jcarousel-item-' + obj.attr('rel')).removeClass('current');
                },
                afterEnd: function (obj) {
                    $('#jcarousel-item-' + obj.attr('rel')).addClass('current');
                }
            });
        }
    });

    $('#slider-container').jcarousel({
        scroll: 1,
        animation: 'slow',
        auto: 5,
        visible: 1,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

    $(".checkbox").each(function () {

        $(this).css("display", "none");

        if ($(this).is(":checked")) {
            $(this).next("label").addClass("selected");
        } else {
            $(this).next("label").removeClass("selected");
        }
    });

    $(".checkbox").change(function () {
        if ($(this).is(":checked")) {
            $(this).next("label").addClass("selected");
        } else {
            $(this).next("label").removeClass("selected");
        }
    });

    $(".flagbox").each(function () {

        $(this).css("display", "none");

        if ($(this).is(":checked")) {
            $(this).prev("label").addClass("selected");
        } else {
            $(this).prev("label").removeClass("selected");
        }
    });

    $(".flagbox").change(function () {
        if ($(this).is(":checked")) {
            $(this).prev("label").addClass("selected");
        } else {
            $(this).prev("label").removeClass("selected");
        }
    });

    if ($.browser.msie && parseInt($.browser.version) < 9) {
        $(".label_check").click(function () {
            var checkbox = $(this).siblings("input");
            checkbox.attr("checked", !checkbox.is(":checked"));
            checkbox.trigger("change");
        });
    } 

    $("#chk4556").change(function () {
        if ($(this).is(":checked")) {
            $("#chk4552,#chk4553,#chk4554,#chk4555").removeAttr("checked");
            $("#chk4552,#chk4553,#chk4554,#chk4555").next("label").removeClass("selected");
        }
    });

    $("#chk4552,#chk4553,#chk4554,#chk4555").change(function () {
        if ($(this).is(":checked")) {
            $("#chk4556").removeAttr("checked");
            $("#chk4556").next("label").removeClass("selected");
        }
    });

});

function refreshNavIn() {
    Cufon.refresh("#nav li a");
}

function refreshNavOut() {
    setTimeout(refreshNavOutDelay, 1);
}

function refreshNavOutDelay() {
    Cufon.refresh("#nav li a");
};

function refreshLinksIn() {
    Cufon.refresh("#quick-links li a");
}

function refreshLinksOut() {
    setTimeout(refreshLinksOutDelay, 1);
}

function refreshLinksOutDelay() {
    Cufon.refresh("#quick-links li a");
};

function setFooterHeight() {
    setTimeout(setFooterHeightDelay, 1);
}

function setFooterHeightDelay() {
    var footerHeight = ($(window).height() - $(".footer").offset().top) > 150 ? ($(window).height() - $(".footer").offset().top) : 150;
    $(".footer").css("height", footerHeight);
}

function mycarousel_initCallback(carousel) {

    $('#slider-next').bind('click', function () {
        carousel.next();
        return false;
    });

    $('#slider-back').bind('click', function () {
        carousel.prev();
        return false;
    });

    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });

};
