﻿$(document).ready(function () {

    $("#topmenu li img").mouseenter(function () {
        $(this).stop().animate({ marginTop: -8 }, { queue: false, duration: 400 });
    }).mouseout(function () {
        $(this).stop().animate({ marginTop: 0 }, { queue: false, duration: 600, easing: 'easeOutBounce' });
    });
    selectTopMenu(window.location.pathname);

    $("#servicemenu li img").fadeTo(0, 0.7, function () {
        $m = $("#servicemenu li a[href$='" + window.location.pathname + window.location.search + "'] img")
        if ($m.length == 0) $m = $("#servicemenu li a[href$='" + window.location.pathname + "'] img")

        $m.fadeTo("slow", 1).addClass("current");
    });
    $("#servicemenu li img:not(.current)").hover(function () { $(this).stop().fadeTo("fast", 1) }, function () { $(this).stop().fadeTo(1000, 0.5) });

    SetupSearch();
});

function selectTopMenu(page) {

    var $m = $("#topmenu a[href$='" + page + "'] img");
    $m.attr("src", $m.attr("selected"));

}
function SetupSearch() {
    $(".searchbox input").keyup(function () {
        Find();
    });
    $(".searchbox span").click(Find);
}
function Find() {
    var $in = $(".searchbox input");
    if ($in.val().length < 2) return;
    $.ajax({ url: "/macro.aspx?macro=GETSEARCHRESULTS&query=" + $in.val() + "&rnd=" + Math.random(),
        success: function (data) {
            var $d = $("#searchresult");
            if (data == "") { $d.fadeOut(); return false; }

            if ($d.length == 0) {
                $d = $("<div id='searchresult'></div>");
                $d.hide();
                $("#header").append($d);
            }
            var offset = $in.offset();
            $d.css({ top: offset.top + $in[0].offsetHeight });
            $d.empty().append(data).fadeIn();
            $("body").click(function () { $d.fadeOut(); });

        }
    });
}
