﻿
(function (jQuery) {
    $(".top-nav li").mouseenter(function () {
        $(this).find(".sub-nav").show();
    }).mouseleave(function () {
        $(this).find(".sub-nav").hide();
    });

    function paginate(ind, el) {
        return "<li><a href='#'>" + $("#hero-panels").children(".hero:eq(" + ind + ")").find(".hero-title").text() + "</a></li>";
    }

    var $hero = $("#hero-panels");
    if ($hero.length) {
        $("#hero-nav").empty();
        $hero.cycle({ fx: "scrollLeft", delay: -1000, timeout: 8000, pager: "#hero-nav", pagerAnchorBuilder: paginate, activePagerClass: "on", manualTrump: false, pause: true, pauseOnPagerHover: true, height: 340 });
    }

    var $tabs = $(".tabs");
    if ($tabs.length) {
        $tabs.tabs();
    }

    var $accordion = $(".accordion");
    if ($accordion.length) {
        $accordion.accordion();
    }

    $(".prefilled").each(function () {
        $(this).data("initial", $(this).val());
    }).focus(function () {
        if ($(this).val() == $(this).data("initial")) {
            $(this).val("");
        }
    }).blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).data("initial"));
        }
    });

    $(window).load(function () {
        $(".equalize").each(function () {
            var maxHeight = 0, $children = $(this).children().not(".clear");
            $children.each(function () {
                if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
            });
            $children.height(maxHeight);
        });
    });

    var $light = $(".lightbox");
    if ($light.length) {
        $light.lightBox();
    }

})($);
