﻿$(function () {
    var $GloMenu = $("#GloMenu > Li"),
        $Channel = $("#Channel > div"),
        $SearchKey = $("#SearchKey"),
        $SearchOpts = $("#SearchOpts"),
        $SearchBtn = $("#SearchBtn"),
        $RegionChannel = $("#RegionChannel"),
        GloNavTime,
        GloNavActive,
        GloNavIndex = 0;
    //菜单
    $GloMenu.children("a").each(function (i) {
        var URL = location.href.toLowerCase().substring(0, location.href.lastIndexOf("/")), HREF = this.href.toLowerCase().substring(0, this.href.lastIndexOf("/"));
        if (HREF.indexOf(URL) > -1) {
            if (HREF == URL || HREF == "/") {
                $(this).parent().addClass("Active").removeClass("Prev").siblings().removeClass("Active Prev").end().prev().addClass("Prev"); return false;
            }
        }
    }).hover(function () {
        if (!$(this).parent().is(".Active")) {
            $(this).parent().prev(":not(.Active)").addClass("Prev");
        }
    }, function () {
        if (!$(this).parent().is(".Active")) {
            $(this).parent().prev(":not(.Active)").removeClass("Prev");
        }
    });
    //搜索
    $SearchKey.val(function () {
        var value = location.pathname.match(new RegExp("/Category_[0-9]+/", "i"));
        if (value) {
            value = value.toString().replace("/Category_", "").replace("/", "");
            $("#SearchOpts li[value='" + value + "']").click();
        }
        value = $.Ext.Q("Key");
        if (value) {
            return decodeURI(value)
        } else {
            return $SearchKey.attr("Message")
        }
    }).click(function () {
        var o = $(this).addClass("FocusKey");
        if (o.val() == o.attr("Message")) {
            o.val("")
        }
    }).blur(function () {
        var o = $(this);
        if (o.val() == "") {
            o.removeClass("FocusKey").val(o.attr("Message"))
        }
    }).keydown(function (event) {
        if (event.which == 13) {
            event.preventDefault();
            $SearchBtn.click()
        }
    });
    $SearchBtn.click(function () {
        __Search($SearchKey.val()); $(this).blur()
    });
    $(".LinkKeys").click(function () {
        if ($SearchKey.length > 0 && $SearchBtn.length > 0) {
            $SearchKey.val($(this).text());
            $SearchBtn.click()
        } else {
            __Search($(this).text())
        }
    });
    function __Search(Key) {
        var url = "/Category_" + $("#SearchOpts > span").attr("value") + "/index.aspx";
        if (Key != $SearchKey.attr("Message")) {
            url += "?Key=" + encodeURI(Key);
        }
        window.location = url;
    };
    //地区频道
    $RegionChannel.find("div.Title").click(function () {

    });
    $("div.iPanel > h2 > a").bind("mouseover click", function () {
        $(this).siblings("a.Active").removeClass("Active").end().addClass("Active").parent().parent().find("ul.List").hide().eq($(this).index()).show();
    });
});

