(function(a){

    
    /**
     * fangfang 用户页面，用户名及签到的下拉框移入/移出效果
     * @time 2014-02-19
     */
    $(".logined-show").live({
        mouseover:function(){
            $(this).addClass("hover");
        },
        mouseout:function(){
            $(this).removeClass("hover");
        }
    })

    //顶部导航隐藏显示功能
    allMenu_show=function(){
        var timer=null;
        a(".nav ul li:first").hover(
            function(){
                var mu=$(this);
                timer=setTimeout(function(){
                    mu.addClass("open");
                },100);
            },
            function(){
                clearTimeout(timer);
                $(this).removeClass("open");
            }
        );
    }
    allMenu_show();
    var header_sign_show=function(){
        var timer=null;
        clearInterval(timer);
        $(".normal-a:last,#top-side-box").hover(
            function(){
                clearTimeout(timer);
                timer=setTimeout(function(){
                    $("#top-side-box").show();
                },100);
            },
            function(){
                clearTimeout(timer);
                timer=setTimeout(function(){
                    $("#top-side-box").hide();
                },100);
            }
        )
    }
    header_sign_show();

    var tpl = '<div class="top_tips">'+
        '<p>签到成功，获得 <em class="org">{DOU}</em> 积分</p>'+
        '<p class="tips">您已连续签到{NUM}天，明天继续签到，可获得 <em class="org">{tDou}</em> 积分</p>'+
        '</div>'+
        '<div class="btn"><a class="sub" href="'+__URL_JUANPI__+'/jifen/gift">花积分</a></div>';

    var checkedTpl = '<div class="top_tips">'+
        '<p>您今天已经签过到了，明天再来，就可以获得{tDou}积分！ </p>'+
        '</div>'+
        '<div class="btn"><a class="sub" href="'+__URL_JUANPI__+'/jifen/gift">花积分</a></div>';
    var failTpl = '<div class="top_tips">'+
        '<p>签到失败！ </p>'+
        '</div>'+
        '<div class="btn"><a class="sub" href="'+__URL_JUANPI__+'/jifen/gift">花积分</a></div>';

    //签到领积分
    $(".state-show .normal-a:last,.side_right .trigger:first").live('click', function(){
        var btn = $(this);
        //验证是否登录
        if (XDPROFILE.uid == "") return XD.user_handsome_login_init(),
                XD.user_handsome_login(),
                false;
        if(btn.data('lock')) return false;
        btn.data('lock', 1);
        $.getJSON(__URL_MEMBER__ + "/public/doSign?uid="+XDPROFILE.uid+"&callback=?", function(d) {
            if( (d.code == 1005) && ((d.msg == "error"))){
                return XD.user_handsome_login_init(),
                    XD.user_handsome_login(),
                    false;
            }else if ( (d.code == 1001) && ((d.msg == "succuss"))) {
                var box_tpl = tpl
                    .replace(/{DOU}/, d.Dou)
                    .replace(/{tDou}/, d.tDou)
                    .replace(/{NUM}/, d.lastNum)
            }else if( (d.code == 1004) && (d.msg == "succuss")) {
                var box_tpl = checkedTpl
                    .replace(/{tDou}/g,  d.tDou);
            }else{
                var box_tpl = failTpl;
            }
            var box = new XDLightBox({
                title:'每日签到送积分',
                lightBoxId:'alert_sign',
                contentHtml:box_tpl,
                scroll:true
            });
            box.init();
            btn.data('lock', 0);
            getSign(__XD_USER__.uid);
            //关闭弹出框
            $(".alert_close").live('click', function(){
                $('#alert_sign').hide();
            });
        });
    });
})(jQuery);

$(document).ready(function(){
    //用户访问统计Cookie共享
    if(!XDTOOL.empty(XDTOOL.getCookie("_Qt")) && XDTOOL.empty(XDTOOL.getCookie("_QM")) ){
        var _Qt = XDTOOL.getCookie('_Qt');
        $.getJSON(__URL_JKY__+"/landcookie.php?callback=?",
            {qt:_Qt},
            function(data){
                if(data.code==1001){
                    var cookieobj = {expires:365,path:'/',domain:".juanpi.com"};
                    XDTOOL.setCookie("_QM",1,cookieobj);
                }
            });
    }
    if(!XDTOOL.empty(__XD_USER__.uid)&&(XDTOOL.empty(XDTOOL.getCookie("c_login"))||XDTOOL.getCookie("c_login")=='0')){
        var uid = XDPROFILE.uid;
        $.getJSON(__URL_JKY__+"/logincookie?callback=?",
            {uid:__XD_USER__.uid,pic:__XD_USER__.pic,nick:__XD_USER__.nick,sign:__XD_USER__.sign,exp:XDTOOL.getCookie("s_exp")},function(data){
                if(data.code==1001){
                    var cookieobj = {expires:0,path:'/',domain:".juanpi.com"};
                    XDTOOL.setCookie("c_login",1,cookieobj);
                }
            });
    }
    //收藏本站 by jimi
    function AddFavorite(sURL, sTitle) {
        try {
            window.external.addFavorite(sURL, sTitle);
        }
        catch (e) {
            try {
                window.sidebar.addPanel(sTitle, sURL, "");
            }
            catch (e) {
                alert("加入收藏失败，请使用Ctrl+D进行添加");
            }
        }
    }
    $(".user-head-top .top-box-left .collect").live('click', function(){
        AddFavorite(window.location,"卷皮折扣");
    });

    /**
     * 用户登录后，鼠标移入，三角形标志变换效果
     * @author: xiaoxiong
     * @time: 2014/05/04
     */
     F_logined = function(){

        if( navigator.userAgent.indexOf("MSIE") > -1 || navigator.userAgent.indexOf("rv:11") > -1 ){

           $(".normal").hover(function(){
            $(this).find("em.cur").addClass("iconup");
        },
        function(){
            $(this).find("em.cur").removeClass("iconup");
        });
        
    }else{
         $(".normal").hover(function(){
            $(this).find("em.cur").addClass("open");
        },
        function(){
            $(this).find("em.cur").removeClass("open");
        });
    }   
}

    F_logined();



     /**ake 关于兼容mac retina屏 首页当为mac系统logo换成两倍的图片
    *@time 2014-09-09
    */
        if(navigator.platform.indexOf('Mac') > -1){
          $("div.logo .juan-logo").addClass("juan-logo01 ") 
          $(".juan-txt").addClass("juan-txt01")
          $(".juan-user").addClass("juan-user01")
          $(".juan-jifen").addClass("juan-jifen01")
          $(".juan-fanli").addClass("juan-fanli01")
          $(".juan-iphone").addClass("juan-iphone01")
          $(".protection").addClass("protection01")
    }else{
          $("div.logo .juan-logo").removeClass("juan-logo1") 
          $(".juan-txt").removeClass("juan-txt01")
          $(".juan-user").removeClass("juan-user01")
          $(".juan-jifen").removeClass("juan-jifen01")
          $(".juan-fanli").removeClass("juan-fanli01")
          $(".juan-iphone").removeClass("juan-iphone01")
          $(".protection").removeClass("protection01")

          
    }
    /**
    /**
     * fangfang 用户消息评论页面，点击切换菜单的同时异步刷新数据
     * @time 2014-02-19
     */
    funcSharePull = function(){
        var allNum = 0,
            atNum = 0,
            cmtNum = 0,
            lastiid = "",
            g = null;
        var numAjax = function(){
            if (a("#zone_tab").size()){
                if (a("#zone_tab .zt_f").eq(0).hasClass("c")) lastiid = a(".t_l .t_f").eq(0).attr("tid");
            }
            a.getJSON(
                __URL_JUANPI__+"/shareajax?callback=?",{action:"ajaxSharenum",args:{lastiid:lastiid}},
                function(data) {
                    if (data){
                        if (null != data.status.code && data.status.code == 1001){
                            allNum = parseInt(data.result.allNum);
                            atNum = parseInt(data.result.atNum);
                            cmtNum = parseInt(data.result.cmtNum);
                            shareNumChange(allNum,atNum,cmtNum);
                            if (allNum > 20) return false;
                            clearTimeout(g);
                            g = setTimeout(numAjax,60E3);
                        }
                    }
                }
            )
        };
        var shareNumChange = function(allNum,atNum,cmtNum){
            var addNum = function(obj,num){
                if (num != 0) {
                    if (obj.find("sup").size()){
                        obj.find("sup em").text(num);
                    }else{
                        obj.append('<sup><em>' + num + '</em><i></i></sup>');
                    }
                }
            };
            var sum = 0,
                tip = "";

            if (allNum > 20) {
                allNum = 20 ;
                tip = "+";
            }
            sum = allNum + tip;
            if (location.href.indexOf("/share") != -1){
                if (a("#zone_tab .zt_f").eq(0).hasClass("c") && allNum){
                    if (a("#wb_new_messages").size()){
                        a("#wb_new_messages a").html("有" + allNum + tip + "条新分享，点此刷新");
                    }else{
                        var str = '<div class="wb_new_messages" id="wb_new_messages"><a class="blu" href="/share/me">有';
                        str += allNum + tip +'条新分享，点此刷新...</a></div>';
                        a("#zone_tab").after(str);
                    }
                }
                if (a("#zone_tab").size()){
                    a("#zone_tab .zt_f").each(function(index){
                        var _sel = a(this);;
                        if (_sel.find("a").text() == "@我的"){
                            addNum(_sel,atNum);
                        }else if(_sel.find("a").text() == "评论我的"){
                            addNum(_sel,cmtNum);
                        }
                    });
                }
            }

        };
        g = setTimeout(numAjax,2E3);
    };
});
