function globalSearch(type, datas) {
    
    $("#header #top-search").each(function() {
        var loader = this;
        var openlist = $(this).find("div.openlist");
        var tempspan = $(this).find("span");
        var input = $("input:text", this);
        var message = "请输入关键字";
        var searcher = $(".search_list", this);
        input.blur(function() {
            if ($.trim(this.value) == "") {
                this.value = message;
            }
            searcher.slideUp("slow");
        }).focus(function() {
            input.css({"color":"#a5a5a5"});
            if ($.trim(this.value) == message) {
                this.value = "";
            } else {
                if (searcher.css("display") == "none") {
                    input.trigger("keyup");
                }
            }
        }).hover(function() {
            $(this).css({"border":"1px solid #000"});
            searcher.css({"border":"1px solid #000"});
        }, function() {
            $(this).css({"border":"1px solid #7f9db9"})
            searcher.css({"border":"1px solid #7f9db9"})
        });
        $.each(datas, function() {
            openlist.append('<a href="javascript://'+this.text+'" rel="' + this.id + '">' + this.text + '</a>');
        })
        openlist.find("a").click(function() {
            tempspan.text(this.innerHTML);
            openlist.hide();
            loader.type = this.rel;
            return false;
        }).eq(0).trigger("click");

        $("a.sel", this).click(function() {
            openlist.show();
        })

        /*提交按按钮*/
        $("input:button", this).click(function() {
	    var value = $.trim(input.val());
            input.css({"color":"#a5a5a5"});
            if (message == value || value == "") {
                $(input).css({"color":"#D20001"});
                return;
            }else {
		window.location.href="http://so.woyao6.com/?q="+value;
            }
        })

        /*查询输入框-即时关键字*/
        input.keyup(function($event) {
            if ($event.keyCode == 13) {
                var active = searcher.find(".on");
                if (active.size() > 0) {
                    active.removeClass("on").trigger("click");
                    return false;
                }
            } else if ($event.keyCode == 38 || $event.keyCode == 40) {
            } else {
                var value = $.trim(this.value).toLowerCase();
                searcher.empty().hide();
                if (value.length == 0 || !SearcheKeyWords[value.charAt(0)]) return true;
                $.each(SearcheKeyWords[value.charAt(0)], function(index) {
                    if (this.word.toLowerCase().match("^" + value.toLowerCase() + ".*")) {
                        searcher.append("<a href=\"javascript://\" onclick=\"$(this).parent().slideUp().parent().find('input:text').val(this.title);\" title=\"" + this.word + "\"><em>被查询 " + this.count + "次</em>" + this.word + "</a>");
                    }
                });
                if (searcher.html() == "") {
                    searcher.hide();
                } else {
                    searcher.show();
                }
            }
        }).keydown(function($event) {
            if ($event.keyCode == 38 || $event.keyCode == 40) {
                var options = searcher.find("a");
                var activeindex = options.index(searcher.find(".on"));
                options.removeClass("on");
                options.eq(($event.keyCode == 38) ? activeindex <= 0 ? options.size() - 1 : activeindex - 1 : activeindex + 1 >= options.size() ? 0 : activeindex + 1).addClass("on");
            }
        });

        /*注册回车提交表单事件*/
        $(this).keyup(function(event) {
            if (event.keyCode == 13) {
                $("input:button", this).trigger("click");
            }
        });
    });
}
