﻿jQuery.noConflict();

var preurl = "http://gip.xcb.sdo.com:9024/";

var xcb_avator_bbs;
(function($) {
    xcb_avator_bbs = {

        initFromBBS: function(para, region_id) {
            //动态引入样式文件
            (function(path) {
                var fileref = document.createElement("link")
                fileref.rel = "stylesheet";
                fileref.type = "text/css";
                fileref.href = path;
                fileref.media = "screen";
                var headobj = $('head')[0];
                headobj.appendChild(fileref);
            })(preurl + "css/avatar_bbs.css");
            //json获取动态参数
            eval('$.getJSON("' + preurl + 'services/getavatar.ashx?show=bbs&JsonCallback=?", {p:"' + para + '"}, function(data) {  $("#' + region_id + '").html(data);  xcb_avator_bbs.menu();  xcb_avator_bbs.popUp(); }); ');
        },
        menu: function() {
            //右侧折叠菜单
            $(".charTitle").click(function() {
                $(this).parent().find(".dB").removeClass("dB")
                $(this).next().addClass("dB")
            })
        },

        popUp: function() {
            var thisClass = this;
            //左侧物品描述信息弹出层
            var liLen = $(".list_bbs_equipment li").length;
            $(".list_bbs_equipment li").each(function(i) {
                $(this).css({ zIndex: (liLen - i) * 10 })
            })
            $(".list_bbs_equipment li").hover(
                function() {
                    //$(this).find(".itemDesc").show()
                    //$(this).find(".itemDescTitle").show()           
                    thisClass.tooltipShow($(this).find(".itemDesc"))
                    thisClass.tooltipShow($(this).find(".itemDescTitle"))
                },
                function() {
                    $(this).find(".itemDesc").hide()
                    $(this).find(".itemDescTitle").hide()
                }
            );
            $("#xcb_avatar_pf .itemDesc").hover(
                function() {
                    //$(this).show()
                    thisClass.tooltipShow($(this))
                },
                function() {
                    $(this).hide()
                }
            ).parent().find(".itemDescTitle").remove();


        },
        tooltipShow: function(elem) {
            elem.css({
                top: 0,
                left: 38
            });
            elem.show();
            var v = {
                x: $(window).scrollLeft() - 20,
                y: $(window).scrollTop() - 20,
                cx: $(window).width(),
                cy: $(window).height(),
                ex: $(elem).offset().left,
                ey: $(elem).offset().top,
                ew: $(elem).width(),
                eh: $(elem).height(),
                px: $(elem).position(parent).left,
                py: $(elem).position(parent).top
            };
            elem.css({
                top: (v.ey + v.eh) > (v.y + v.cy) ? v.py - ((v.ey + v.eh) - (v.y + v.cy)) : v.py,
                left: (v.ex + v.ew) > (v.x + v.cx) ? v.px - ((v.ex + v.ew) - (v.x + v.cx)) : v.px
            });
            if ($(elem).offset().top < 0) elem.css({ top: 0 });
            if ($(elem).offset().left < 0) elem.css({ left: 38 });
        }
    }

})(jQuery)

