$(document).ready(function() {
    // top menu
    $("#nav").each(function() {
        var current = $("ul li[class=active]", this);
        var timer = null;
        $("ul li", this).hover(function() {
            $("li", $(this).parent()).removeClass("active");
            $(this).addClass("active");
            if (timer) {
                window.clearTimeout(timer);
            }
        }, function() {
            var t = this;
            timer = window.setTimeout(function() {
                $("li", $(t).parent()).removeClass("active");
                if (current) {
                    current.addClass("active");
                }
            }, 3000);
        });
    });

    $(".menu .menu-items ul li").hover(function() {
        $("li", $(this).parent()).removeClass("hover");
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });

    $(".top-news ul li").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });
    
    // search
    $(".search-box").each(function() {
        var t = this;
        var submit = function() {
            var jkw = $(".kw input[name='kw']", t);
            if (jkw.val() != "") {
                var url = $("input[name='search_url']", t).val() + escape(jkw.val());
                window.location.href = url;
            } else {
                jkw.focus();
            }
        }
        $(".btn", this).click(submit);
        $(".kw", this).keypress(function(e) {
            if (e.which == 13) {
                submit();
            }
        });
    });
});


