var $leftBox = $("#leftBox");
var $middleBtn = $("#middleBtn");
var $rightBox = $("#rightBox");

var $iframeContainer = $("#iframeMainContainer");
var $menuContainer = $(".menu-container");

//初始化Iframe的宽度，高度等信息
function InitIframeSize() {
    var height = $rightBox.height();
    var width = $rightBox.width();
    $iframeContainer.width(width).height(height);
}
InitIframeSize();
$(window).resize(function () {
    InitIframeSize();
});

var $menuSort;
//初始化菜单
function InitMenu() {
    $menuSort = $(".menu-container").find(".sort"); //菜单分类标签
    $menuSort.append("<b class=\"caret\"></b>");
    $menuSort.each(function (index) {
        var $this = $(this);
        if ($this.hasClass("shut")) {
            $this.next("ul").hide();
        }
    });
    var $allLi = $menuContainer.find("li");
    $allLi.find("a").each(function (index) {
        var $this = $(this);
        var target = $this.attr("target");
        if (target == undefined) {
            $this.attr("target","iframeMainContainer");
        }
    });
}

$(document).ready(function () {

    //parent.HideLeftMenu();//关闭上级框架的左侧菜案

    InitMenu();
    //菜单收缩
    $menuSort.click(function () {
        var className = "shut";
        var $this = $(this);
        if ($this.hasClass(className)) {
            $this.next("ul").slideDown("fast");
            $this.removeClass(className);
        }
        else {
            $this.next("ul").slideUp("fast");
            $this.addClass(className);
        }
    });

    //左侧收缩/展开
    $middleBtn.click(function () {
        var $this = $(this);
        var className = "middel-btn-shut";
        var rightBoxClassName = "right-box-full";
        if ($this.hasClass(className)) {
            $leftBox.show();
            $rightBox.removeClass(rightBoxClassName);
            $this.removeClass(className);
        }
        else {
            $leftBox.hide();
            $rightBox.addClass(rightBoxClassName);
            $this.addClass(className);
        }
        InitIframeSize();
    });

    //a标签点击
    var $allLi = $menuContainer.find("li");
    $allLi.find("a").click(function () {
        $allLi.removeClass("current");
        $(this).parent().addClass("current");
    });

});