/*! Project: mobi_duowan
 *  Version: 0.0.1
 *  Date: 2014-07-09 11:24:22 AM
 *  Author: [object Object]
 */

(function(){
    var reg = 'newgame.duowan.cn',
        host = document.domain;

/*    if(reg !== host && !/(Android)/i.test(navigator.userAgent)) {
        return;
    }*/

    var fragment = String(function(){/*!
            <div class="fixed-banner" id="fixedBanner">
                <div class="slogan">
                    <em>手机看攻略神器</em>
                    还有游戏点卡等你拿
                </div>
                <a href="#" class="open-btn">立即打开</a>
                <a href="#" class="close-btn">&times;</a>
            </div>
            */}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, '');

    cssText = String(function(){/*!
            .fixed-banner { background: rgba(0, 0, 0, 0.6); height: 72px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 99999; }
            .fixed-banner .slogan { float: left; padding: 0 0 0 55px; margin: 13px 0 0 15px; color: #fff; font-size: 12px; background: url(http://assets.dwstatic.com/project/mobidwartcle/img/fixed-banner-logo.png) no-repeat; -webkit-background-size: 45px 45px; background-size: 45px 45px; min-height: 55px; }
            .fixed-banner .slogan em { font-size: 16px; display: block; font-style: normal; }
            .fixed-banner .open-btn { float: right; margin: 20px 42px 0 0; background: #78bb18; border-radius: 6px; font-size: 15px; color: #fff; width: 85px; height: 32px; line-height: 32px; text-align: center; }
            .fixed-banner .close-btn { position: absolute; right: 0; top: 0; width: 24px; height: 24px; color: #fff; background: #333; line-height: 24px; font-size: 20px; text-align: center; font-weight: 100; }
            */}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, '');

    var style = document.createElement("style");
    style.type = "text/css";
    style.appendChild(document.createTextNode(cssText));

    var parseCookie = function(cookieString){
        var cookieList = cookieString.split('; ');
        var ret = {};
        for(var i in cookieList){
            var val = cookieList[i].split('=');
            ret[val[0]] = val[1];
        }
        return ret;
    }

    var cookies = parseCookie(document.cookie);
    var passport = cookies['username'] || '';
    var ya = new YA.report.YYAnalytics('dwapp_huodong', passport);

    //绑定事件
    var addEvent =  function(el,fn){
        try
        {
            el.addEventListener('click',fn,false);
        }
        catch(e)
        {
            el.attachEvent('onclick',fn);
        }
    }

    $(function(){
        document.getElementsByTagName("head")[0].appendChild(style);
        $('body').append(fragment);

        ya.reportProductEvent({ eid : "login/mobileAD", eid_desc :"登录/多玩移动底部广告曝光", pro : "dwapp_huodong", rso : 'website'});

        addEvent($('#fixedBanner').get(0),function(){
            var iosLink = "https://itunes.apple.com/cn/app/id900401083",
                androidLink = "http://m.duowan.com/apk/YYzdb.apk";
            ya.reportProductEvent({ eid : "click/mobileAD/dianji", eid_desc :"点击/多玩移动底部广告/广告点击", pro : "dwapp_huodong", rso : 'website'});
            if(/(Android)/i.test(navigator.userAgent)) {
                window.open(androidLink);
            }else{
                window.open(iosLink);
            }
        })

        addEvent($('#fixedBanner .close-btn').get(0),function(){
            event.stopPropagation();
            event.preventDefault();
            $('#fixedBanner').remove();
        })

        // $('#fixedBanner').on('click', function(){
        //     var iosLink = "https://itunes.apple.com/cn/app/id900401083",
        //         androidLink = "http://m.duowan.com/apk/YYzdb.apk";
        //     ya.reportProductEvent({ eid : "click/mobileAD/dianji", eid_desc :"点击/多玩移动底部广告/广告点击", pro : "dwapp_huodong", rso : 'website'});
        //     if(/(Android)/i.test(navigator.userAgent)) {
        //         window.open(androidLink);
        //     }else{
        //         window.open(iosLink);
        //     }
        // });

        // $('#fixedBanner .close-btn').on('click', function(event){
        //     event.stopPropagation();
        //     event.preventDefault();
        //     $('#fixedBanner').remove();
        // });
    });

})();