$(function () {
    if($('body').attr('data-type') =='NewIndex'){
        $(function () {
            (function (w) {
                setSize();
                function setSize() {
                    var vWidth = (w.document.documentElement.getBoundingClientRect().width > 750) ? 750 : w.document.documentElement
                            .getBoundingClientRect().width;
                    w.document.documentElement.style.fontSize = vWidth / 7.5 + "px";
                }
                window.onresize = function () {
                    setSize();
                }
            })(window);
//        document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
        })
    }else {
        (function (doc, win) {
            var docEl = doc.documentElement,
                resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
                recalc = function () {
                    var clientWidth = docEl.clientWidth;
                    if (!clientWidth) return;
                    /* docEl.style.fontSize = 20 * ( clientWidth / 320 ) + 'px'; */
                    docEl.style.fontSize = (20 * ( clientWidth / 320 ) > 32 ? 32 : 20 * ( clientWidth / 320 )) + 'px';
                };
            recalc();
            if (!doc.addEventListener) return;
            win.addEventListener(resizeEvt, recalc, false);
            doc.addEventListener('DOMContentLoaded', recalc, false);
        })(document, window);
    }
});



$(function () {
    function bigimg(imgdiv) {
        //点击图片放大
        imgdiv.on('click',function(){
            var urls=[];
            var imgList = imgdiv;
            imgList.each(function(i){
                urls.push(imgList.eq(i).attr('src'));
            });
            WeixinJSBridge.invoke('imagePreview', {
                'current':server + $(this).attr('src'),
                'urls': urls
            });
        });

    };
    function getCookie(cname) {
        console.log(cname)
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++)
        {
            var c = ca[i].trim();
            if (c.indexOf(name)==0) return c.substring(name.length,c.length);
        }
        return "";
    }
    var _cibe = getCookie("cibe");
    if(_cibe ==1){
        $("body").append('<div class="mbh-img" style="position: fixed;right: 10%;bottom: 10%;width: 4rem;height: 4rem;cursor: pointer"> <img style="width: 100%;height: 100%;" src="/html/cibe/img/mbh.png"> </div>');
    }
    $("body").on("click",".mbh-img",function () {
        setCookie("cibe","",-1);
        window.location.href='/html/cibe/view/placeholder.jsp';
        // document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
    });
//存储cookie
    function setCookie(cname,cvalue,exmin)
    {
        var d = new Date();
        d.setTime(d.getTime()+(exmin*60*1000));
        var expires = "expires="+d.toGMTString();
        document.cookie = cname + "=" + cvalue + "; " + expires+";path=/";
    }
})

//前端适配
// var _link = window.location.href;
// if(_link.indexOf("/html/cmpage/view") != -1){//暂时注释因为木有数据
//     if(_link.indexOf("=") != -1){
//         var _url = _link.split('='),//链接第一个参数是页面类型，第二个参数是页面ID
//             _type = _url[1].split("&")[0],
//             _id = _url[2];
//     }
//     if(_type ==1){
//         _link = wwwServe+'/cmpage/info-'+ _type +'-'+ _id +'.html';
//         browserRedirect(_link);
//     }else if(_type ==2) {
//         _link = wwwServe+'/cmpage/info-'+ _type +'-'+ _id +'.html';
//         browserRedirect(_link);
//     }
// }else if(_link.indexOf("/product/cmbeanDetail.action") != -1){//商品详情采美豆
//     var productID =_link.split('productID=')[1];
//     _link = wwwServe+'/cmbean/product-'+productID+'-1.html';
//     browserRedirect(_link);
// }else if(_link.indexOf("/product/productDetail.action") != -1){//普通
//     var productID =_link.split('productID=')[1];
//     _link = wwwServe+'/product-'+productID+'.html';
//     browserRedirect(_link);
// }else if(_link == 'http://crm.caimei365.com/cmpage/index.rpc'|| _link == "http://crmtest.365mdd.com/cmpage/index.rpc"){
//     _link = wwwServe;
//     browserRedirect(_link);
// }else if(_link.indexOf("/html/cmBeans/view/cmBeans.jsp") > -1){
//     if(_link.indexOf("=") != -1){
//         var _url = _link.split('=')[1];//链接第一个参数是页面类型，第二个参数是页面ID
//     }
//     _link = wwwServe+'/cmBeans/search/list-'+_url+'.html';
//     browserRedirect(_link);
// }else if(_link.lastIndexOf("/product/list.action") != -1){//商品搜索list
//     var _url = _link.split('bigTypeId=');
//     var bigTypeID = _url[1].split('&smallTypeId')[0];//0
//     var smallTypeID = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId')[0];//0
//     var tinyTypeID = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId=')[1].split('&sortType=')[0];//0
//     var sortType = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId=')[1].split('&sortType=')[1].split('&shopID=')[0];
//     var wd;
//     if(_link.lastIndexOf('keyWord') > -1){
//         var shopID = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId=')[1].split('&sortType=')[1].split('&shopID=')[1].split('&keyWord=')[0];
//         if (_link.lastIndexOf('searchTypeID') > -1) {
//             wd = _link.split('&keyWord=')[1].split('&searchTypeID')[0];
//             var searchTypeID = _link.split('searchTypeID=')[1];
//             _link = wwwServe+'/product/search/list/' + bigTypeID + '-' + smallTypeID + '-' + tinyTypeID + '-' + sortType + '-' + shopID + '.html?wd='+ wd +'&searchTypeID=' +searchTypeID;
//         }else{
//             wd = _link.split('&keyWord=')[1];
//             _link = wwwServe+'/product/search/list/' + bigTypeID + '-' + smallTypeID + '-' + tinyTypeID + '-' + sortType + '-' + shopID + '.html?wd='+ wd;
//         }
//         browserRedirect(_link);
//     }else {
//         var shopID = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId=')[1].split('&sortType=')[1].split('&shopID=')[1];
//         if (_link.lastIndexOf('searchTypeID') > -1) {
//             var searchTypeID = _link.split('searchTypeID=')[1];
//             _link = wwwServe+'/product/search/list/' + bigTypeID + '-' + smallTypeID + '-' + tinyTypeID + '-' + sortType + '-' + shopID + '.html?searchTypeID=' +searchTypeID;
//         }else{
//             _link = wwwServe+'/product/search/list/' + bigTypeID + '-' + smallTypeID + '-' + tinyTypeID + '-' + sortType + '-' + shopID + '.html';
//         }
//         browserRedirect(_link);
//     }
// }
//
//
// function browserRedirect(link) {
//
//     var sUserAgent= navigator.userAgent.toLowerCase();
//
//     var bIsIpad= sUserAgent.match(/ipad/i) == "ipad";
//
//     var bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os";
//
//     var bIsMidp= sUserAgent.match(/midp/i) == "midp";
//
//     var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
//
//     var bIsUc= sUserAgent.match(/ucweb/i) == "ucweb";
//
//     var bIsAndroid= sUserAgent.match(/android/i) == "android";
//
//     var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce";
//
//     var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile";
//
//     if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
//         console.log('啥都不干!!!!!');
//     }else {
//         // var _link = window.location.href;
//         // if(_link.indexOf("/html/cmpage/view") != -1){//暂时注释因为木有数据
//         //     var _url = _link.split('='),//链接第一个参数是页面类型，第二个参数是页面ID
//         //         _type = _url[1].split("&")[0],
//         //         _id = _url[2];
//         //     if(_type ==1){
//         //         _link = wwwServe+'/cmpage/info-'+ _type +'-'+ _id +'.html';
//         //     }else if(_type ==2) {
//         //         _link = wwwServe+'/cmpage/info-'+ _type +'-'+ _id +'.html';
//         //     }
//         // }
//         // else
//             // if(){//商品搜索list
//             // _link.lastIndexOf("/product/list.action") != -1
//             // var _url = _link.split('bigTypeId=');
//             // var bigTypeID = _url[1].split('&smallTypeId')[0];
//             // var smallTypeID = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId')[0];
//             // var tinyTypeID = _url[1].split('&smallTypeId=')[1].split('&tinyTypeId=')[1];
//             //
//             // // var sortType = _url[3];
//             // // var shopID = _url[4].split('.html')[0];
//             // var wd;
//             // if(_link.lastIndexOf('?') > -1){
//             //     wd = _link.split('?')[1];
//             //     if (wd.lastIndexOf('wd=') > -1) {
//             //         wd = wd.replace('wd=', 'keyWord=');
//             //     }
//             // }
//             // _link = wwwServe+'/product/search/list/' + bigTypeID + '-' + smallTypeID + '-' + tinyTypeID + '-0-0.html';
//             //
//             // if(wd){
//             //     _link+='&' + wd;
//             // }
//
//         // }
//         // else if(_link.indexOf("/product/productDetail") > -1){//商品详情
//         //     var productID =_link.split('productID=')[1];
//         //     _link = wwwServe+'/product-'+productID+'.html';
//         //
//         //
//         // }else if(_link.indexOf("/cmpage/index") > -1){
//         //
//         //     _link = wwwServe;
//         // }
//
//         window.location.href= link;
//
//     }
// };
