﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("web");
web.PYIndex = function (element) {
    web.PYIndex.initializeBase(this, [element]);
    this._pop = $get("category_popup");
    this._titleHoverDelegate = null;
    this._titleOutDelegate = null;
    this._popHoverDelegate = null;
    this._popOutDelegate = null;
    this.timeout = 500;
    this.closetimer = 0;
    this.ddmenuitem = 0;
}
web.PYIndex.prototype = {
    initialize: function () {
        web.PYIndex.callBaseMethod(this, 'initialize');
        this.buildEvents();
        // Add custom initialization here
    },
    buildEvents: function () {

        if (this._titleHoverDelegate === null) {
            this._titleHoverDelegate = Function.createDelegate(this, this.titleHoverHandler);
        }
        if (this._titleOutDelegate === null) {
            this._titleOutDelegate = Function.createDelegate(this, this.titleOutHandler);
        }
        if (this._popOutDelegate === null) {
            this._popOutDelegate = Function.createDelegate(this, this.popOutHandler);
        }
        if (this._popHoverDelegate === null) {
            this._popHoverDelegate = Function.createDelegate(this, this.popHoverHandler);
        }
        var e = this._element;
        for (var i = 0; i < e.children.length; i++) {
            if (e.children[i].nodeName == "A") {
                $addHandler(e.children[i], "mouseover", this._titleHoverDelegate);
                $addHandler(e.children[i], "mouseout", this._titleOutDelegate);

            }
        }
        $addHandler(this._pop, "mouseout", this._popOutDelegate);
        $addHandler(this._pop, "mouseover", this._popHoverDelegate);
    },
    titleHoverHandler: function (e) {
        this.mcancelclosetime();
        var v = e.target.innerText;
        var value = PYIndex[v];
        this.setValues(value);
        this.closeTitle(value);
        this.showMenu(e);
    },
    titleOutHandler: function (e) {

        this.mclosetime();
    },
    popOutHandler: function (e) {
      this.mclosetime();
    },
    popHoverHandler: function (e) {
        this.mcancelclosetime();
    }
    ,
    setValues: function (value) {
        var categoryString = "<h4><span>类目</span></h4>";
        var brandString = "<h4><span>品牌</span></h4>";
        for (var i = 0; i < value.length; i++) {
            var t = value[i];
            if (t[2] == 0) {
                categoryString += "<a href='ProductCategory.aspx?id=" + t[1] + "'>" + t[0] + "</a>";
            }
            else {
                brandString += "<a href='ProductCategory.aspx?id=" + t[1] + "'>" + t[0] + "</a>";
            }
        }
        this._pop.innerHTML = categoryString + brandString;
    },
    showMenu: function (e) {
        //设置层离开状态
        this.isOutPop = false;
        this.isOutTitle = false;
        //设置层
        this._pop.style.display = "block";
        this._pop.style.position = "absolute";
        this._pop.style.top = "31px";
        this._pop.style.left = "0px";
        //设置A标记

        Sys.UI.DomElement.addCssClass(e.target, "PyIndexHover");
    }
    ,
    closeTitle: function (value) {
        var e = this._element;
        for (var i = 0; i < e.children.length; i++) {
            if (e.children[i].nodeName == "A" ) {
                Sys.UI.DomElement.removeCssClass(e.children[i], "PyIndexHover");
            }
        }
    },
    hideMenu: function () {
        $get("category_popup").style.display = "none";
     
    },
    mcancelclosetime: function () {
        if (this.closetimer) {
            window.clearTimeout(this.closetimer);
            this.closetimer = null;
        }
    },
    mclosetime: function () {
        this.closetimer = window.setTimeout(this.hideMenu, this.timeout);
    },


    dispose: function () {
        //Add custom dispose actions here
        web.PYIndex.callBaseMethod(this, 'dispose');
    }
}
web.PYIndex.registerClass('web.PYIndex', Sys.UI.Behavior);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
