$(function () {
    Cufon.replace(".nivo-info strong", {
        color: "-linear-gradient(#f6e77c, #ab6c06, #f6e77c, #ab6c06)",
        textShadow: "#000 1px 1px 1px",
        fontSize: "110px"
    });
    Cufon.replace("#top-info h1, #top-info h2, #top-info h3, #top-info h4", {
        fontSize: "23px"
    });
    $("#top-info h1, #top-info h2, #top-info h3, #top-info h4").css("letter-spacing", "-1px");
    Cufon.replace(".info-box h2", {
        fontSize: "30px"
    });
    $(".info-box h2").css({
        lineHeight: "1em",
        fontSize: "20px"
    });
    Cufon.now();

    function fixLineHeight($replaced, lineHeight, clearFloat) {
        $replaced.each(function () {
            var $current = $(this);
            if (clearFloat == null) {
                clearFloat = false
            }
            var clearFloatClassname = "fltbox";
            var $cufonWords = $current.children("cufon");
            var $cufonSiblings = $current.children(":not(cufon)");
            if ($(this).css("display") == "inline") {
                $cufonWords.css("display", "inline-block")
            } else {
                $cufonWords.css("float", "left");
                $cufonWords.css("display", "inline");
                $cufonSiblings.each(function () {
                    $sib = $(this);
                    if (!($sib.css("float") == "left" || $sib.css("float") == "right")) {
                        $sib.css("float", "left");
                        $sib.css("display", "inline")
                    }
                });
                if (clearFloat && !$current.hasClass(clearFloatClassname)) {
                    $current.addClass(clearFloatClassname)
                }
            }
            $current.css("line-height", lineHeight);
            $cufonWords.css("height", lineHeight)
        })
    }
    if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
        $(".info-box h2").css({
            lineHeight: "37px"
        })
    } else {
        fixLineHeight($(".info-box h2"), "37px")
    }
    $(".info-content:first").show();
    var nSlider = $(".slider-container").nivoSlider({
        effect: "fade",
        slices: 1,
        animSpeed: 500,
        pauseTime: 8000,
        startSlide: 0,
        directionNav: true,
        directionNavHide: false,
        controlNav: false,
        controlNavThumbs: false,
        controlNavThumbsFromRel: false,
        controlNavThumbsSearch: ".jpg",
        controlNavThumbsReplace: "_thumb.jpg",
        keyboardNav: true,
        pauseOnHover: true,
        manualAdvance: false,
        captionOpacity: 1,
        beforeChange: function () {
            var oldSlide = $(".slider-container img").index(nSlider.data("nivo:vars").currentImage);
            $(".info-content:eq(" + oldSlide + ")").fadeOut(500)
        },
        afterChange: function () {
            var newSlide = $(".slider-container img").index(nSlider.data("nivo:vars").currentImage);
            var imageParentTag = $(".slider-container img:eq(" + newSlide + ")").parent().get(0).tagName;
            if (imageParentTag == "A") {
                var href = $(".slider-container img:eq(" + newSlide + ")").parent().attr("href");
                $(".whole-link").attr("href", href)
            } else {
                $(".whole-link").hide()
            }
        },
        slideshowEnd: function () {}
    });
    $("a[href$='.jpg'], a[href$='.png'], a[href$='.gif']").attr("rel", "prettyPhoto");
    $(".gallery").each(function (i) {
        $("a[href$='.jpg'], a[href$='.png'], a[href$='.gif']", this).attr("rel", "prettyPhoto[" + i + "]")
    });
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: "light_rounded"
    })
});
