var userPanelsData = {};
var userPanelContainer = jQuery("#userPanel");
var offset = {};
var currentUid = null;
var isFetching = false;
userPanelsData['u7632449827'] = '<div class="quesSinglePopup quesSinglePopupWeb"><p class="avatar"><a href="http://home.babytree.com/u7632449827" target="_blank"><img src="http://pic05.babytreeimg.com/foto/thumbs/46/88/47/1c6edf123adb8cfd1433bf_hs.gif"></a></p><p class="siteName"><a href="http://home.babytree.com/u7632449827" target="_blank">39健康网</a></p><p class="siteInfo">宝宝树合作伙伴，众多医生每天在线为宝宝树用户解答问题</p><p class="extend">39健康网，专业的健康资讯门户网站，中国第一健康门户网站，医疗保健类网站杰出代表，提供最专业、完善的健康信息服务。</p></div>';

function showUserPanel(e)
{
    if(isFetching) return;
    var obj = jQuery(this);
    var uid = obj.attr('user');
	var x_hack = obj.attr('panelX');
	var y_hack = obj.attr('panelY');
    offset = obj.offset();
    if(typeof(userPanelsData[uid]) != 'undefined')
    {
        if(uid == currentUid)
        {
            if(obj.attr('rel') == 'userPanel')
            {
                var userPanel = jQuery("#userPanel :first-child");
                fixPosition(userPanel, x_hack, y_hack);
            }
            userPanelContainer.show();
            return;
        }
        userPanelContainer.empty();
        userPanelContainer.html(userPanelsData[uid]);
        userPanelContainer.attr('user', uid);
        var userPanel = jQuery("#userPanel :first-child");
        fixPosition(userPanel, x_hack, y_hack);
        currentUid = uid;
    }
    else
    {
        isFetching = true;
        jQuery.get('/ask/user_panel.php?uid='+uid, function(data) {
                userPanelContainer.html(data);
                userPanelContainer.attr('user', uid);
                var userPanel = jQuery("#userPanel :first-child");
                try {
                    fixPosition(userPanel, x_hack, y_hack);
                    userPanelsData[uid] = data;
                    currentUid = uid;
                } catch (e) {
                }
                isFetching = false;
        });
    }
}

function hideUserPanel()
{
    userPanelContainer.hide();
}

function fixPosition(o, x_hack, y_hack)
{
    var x = offset.left + (x_hack ? parseInt(x_hack) : 0);
    var y = offset.top + (y_hack ? parseInt(y_hack) : 56);
	o.css({ top: y, left: x });
    userPanelContainer.show();
}

jQuery("a[rel='userPanel']").mouseover(showUserPanel).mouseout(hideUserPanel);
userPanelContainer.mouseover(showUserPanel).mouseout(hideUserPanel);

