(function($){

    // var ltie7 = $.browser.msie && ($.browser.version < 7),
    //     $header = $($('.hd')[0]),
    //     scrollbar = function(e){
    //         var stop = $(this).scrollTop(),
    //             timer;
    //         if(stop > 0){
    //             var css = {
    //                 'top':stop+'px',
    //                 'visibility':'visible'
    //             };
    //             $header.css({'visibility':'hidden'});
    //             window.clearTimeout(timer);
    //             timer = window.setTimeout(function(){
    //                 $header.css(css, 400 );
    //             },400);
    //         }else{
    //             window.clearTimeout(timer);
    //             timer = window.setTimeout(function(){
    //                 $header.css({'top':0});
    //             },400);
    //         }
    //     };
    // if(ltie7){
    //     $(window).resize(scrollbar);
    //     $(window).scroll(scrollbar);
    // }
    function shareTo(){
        var shareConfig = {
            tqq : ['http://v.t.qq.com/share/share.php','url','title'],
            tsina : ['http://v.t.sina.com.cn/share/share.php','url','title'],
            tkaixin : ['http://www.kaixin001.com/repaste/share.php','rurl','rcontent'],
            trenren : ['http://share.renren.com/share/buttonshare.do','link','title'],
            tdouban : ['http://www.douban.com/recommend/','url','title'],
            tsohu : ['http://bai.sohu.com/share/blank/add.do','link'],
            thi : ['http://apps.hi.baidu.com/share/','url'],
            tqzone : ['http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey','url','title']
        };

        var appkeys = {
            tqq : '',
            tsina : '',
            tkaixin : '',
            trenren : '',
            tdouban : '',
            tsohu : '',
            thi : '',
            tqzone : ''
        };

        function buildShareToUrl(data, stype, appkey){
            //console.log(arguments);
            var paramsAppkey = '',
                path,
                params = [],
                urlcfg,
                url;

            path = shareConfig[stype][0];
            urlcfg = shareConfig[stype];

            //TODO @360UXC t=encodeURIComponent('#CDC原创博文#：@腾讯CDC体验设计 - ' + articletitle);


            for (var i = 1; i < urlcfg.length; i++) {
                //console.log(urlcfg[i]);
                params.push(urlcfg[i] + '=' + encodeURIComponent(data[i-1]));
            };

            //console.log(typeof(appkey) != 'undefined' && appkey.length > 0);
            if(typeof(appkey) != 'undefined' && appkey.length > 0){
                paramsAppkey = '&appkey='+ encodeURIComponent(appkey);
                params.push(paramsAppkey);
            }


            url = path +'?'+ params.join('&');
            //console.log(url);
            return url;
        }

        $('.share-btn').mouseenter(function(e){
            var posL = $(this).offset().left,
                posT = $(this).offset().top + $(this).height(),
                dataId = parseInt($(this).attr('data-id'));
            $(this).addClass('share-btn-active');
            $('#sharetools').attr('data-id', dataId);
            $('#sharetools').css({"left":posL,"top":posT}).show();
        });

        $('#sharetools').mouseleave(function(e){
            $(this).hide();
            $('.share-btn').removeClass('share-btn-active');
        });
        
        $('#sharetools a').click(function(e){
            e.preventDefault();
            var stype = $(this).attr('data-type');
            //console.log(stype);
            if(!stype){
                return;
            }

            var appkey = appkeys[stype];
            //console.log(appkey);
            var dataId = $('#sharetools').attr('data-id');
            dataId = parseInt(dataId,10);

            //console.log(ShareData[dataId]);
            var url = buildShareToUrl(ShareData[dataId], stype, appkey);
            window.console && window.console.log && console.log(url);
            window.open(url, '_blank');
        });
    }

    shareTo();
})(jQuery);
