﻿    var topClassHeight = 35;
    var secClassHeight = 22;
    function collapseClass(ph) {
        //----计算左侧菜单高度，根据情况折叠
        var topClassCount = jQuery("#clientClass ul").length;
        var secClassCount = jQuery("#clientClass ul li").length;
        var totalHeight = topClassCount * topClassHeight + secClassCount * secClassHeight + 260 + 480;//加上顶部和底部高度

        if (totalHeight > ph) { //需要折叠，
            jQuery("#clientClass ul:first").show();
            jQuery("#clientClass p:first img").attr("src", "/NewShowStand/images/Public/jian.jpg");
        } else {
            jQuery("#clientClass ul").show();
            jQuery("#clientClass p img").attr("src", "/NewShowStand/images/Public/jian.jpg");
        }
    }
    jQuery(document).ready(function () {
        var pageHeight = 0;
        var isIndex = false;
        var pattern = /\/st\d+(\/{0,1}(index.html){0,1})$/i; ;
        if (location.href.match(pattern) != null) { //是首页，则存储页面高度
            isIndex = true;
            pageHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
            WriteCookies("IndexPageHeight" + intCompanyID, pageHeight, 365);
        } else {
            pageHeight = ReadCookies("IndexPageHeight" + intCompanyID);
            if (pageHeight == "")
                pageHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
        }
        if (isIndex) {//是首页，则按既定规则折叠
            collapseClass(pageHeight);
        } else { //是其它页面
            if (location.href.indexOf("/list_") > 0 || location.href.indexOf("/erlist_") > 0) //是产品分类页
            {
                var topClassCount = jQuery("#clientClass ul").length;
                var secClassCount = jQuery("#clientClass ul li").length;
                var totalHeight = topClassCount * topClassHeight + secClassCount * secClassHeight;
                if (totalHeight > pageHeight) { //需要折叠，但分类页的折叠，是要计算过的。
                    //----计算展开哪个二级类
                    var isTopClass = false;
                    jQuery("#clientClass p a").each(function (i) {
                        if (location.href.indexOf(jQuery(this).attr("href")) > 0) {
                            jQuery(this).parent().next().show();
                            jQuery(this).prev().attr("src", "/NewShowStand/images/Public/jian.jpg");
                            isTopClass = true;
                            return false;
                        }
                    });

                    if (!isTopClass) {
                        jQuery("#clientClass ul li a").each(function (i) {
                            if (location.href.indexOf(jQuery(this).attr("href")) > 0) {
                                jQuery(this).parent().parent().show();
                                jQuery(this).parent().parent().prev().find("img").attr("src", "/NewShowStand/images/Public/jian.jpg");
                                return false;
                            }
                        });
                    }
                } else {
                    jQuery("#clientClass ul").show();
                    jQuery("#clientClass p img").attr("src", "/NewShowStand/images/Public/jian.jpg");
                }
            } else { //是其它页面
                collapseClass(pageHeight);
            }
        }
    });