//a focus blur

function checkUrl() {

    var pattern = /%3C|%3E|[<>'"\(\)]/ig; //格式 RegExp("定义特殊过滤字符")
    var url = decodeURI(window.location.href);
    if (pattern.test(url)) {
        var safeUrl = '';
        for (var i = 0; i < url.length; i++) {
            safeUrl = safeUrl + url.substr(i, 1).replace(pattern, '');
        }
        safeUrl = encodeURI(safeUrl);
        setTimeout(function() {
            window.location.href = safeUrl;
        }, 0)
    }
}

checkUrl();
window.onload = function() {
    for (var i = 0; i < document.links.length; i++) document.links[i].onfocus = function() {
        this.blur()
    }
    var script = document.createElement("script");
    script.setAttribute('src', 'http://lbsyun.baidu.com/skins/MySkin/resources/js/guide.js?t=20160713');
    // script.setAttribute('src', './skins/MySkin/resources/js/guide.js?t=20151027');
    script.setAttribute("type", "text/javascript");
    script.setAttribute("charset", "utf-8");
    setTimeout(function() {
        document.getElementsByTagName('head')[0].appendChild(script);
    }, 1);
}

//button display and hide
function Contextdisplay(whichID) {
    document.getElementById(whichID).style.display = (document.getElementById(whichID).style.display != 'block' ? 'block' : 'none');
}

//change icon on class reference page----by xieyangxin
function changeIcon(whichID, target) {
    if (document.getElementById(whichID).style.display != 'block') {
        target.className += ' ' + whichID[0] + 'ccsubmenu';
    } else {
        target.className = whichID[0] + 'csubmenu';
    }
}
//button display hidden
function displayHidden(whichID) {
    document.getElementById(whichID).style.display = 'none';
}
//button display block
function displayBlock(whichID) {
    document.getElementById(whichID).style.display = 'block';
}

//修改, by wjp
if (typeof BMap != 'undefined') {
    var map = new BMap.Map("mmap");
    var point = new BMap.Point(116.307852, 40.057031);
    map.centerAndZoom(point, 15);
    var opts = {
        width: 250, // 信息窗口宽度
        height: 80, // 信息窗口高度
        title: "<a href='http://j.map.baidu.com/K3IXc' style='color:#CC5522;font-weight:800'>百度大厦<a>" // 信息窗口标题
    }
    var infoWindow = new BMap.InfoWindow("地址：北京市海淀区上地十街10号<br/>电话：(010)59928888", opts); // 创建信息窗口对象
    map.openInfoWindow(infoWindow, map.getCenter()); // 打开信息窗口
}

//banner切换 zhuqiao
var getTheme = function(width){
    if(width > 1100)
        width = 1200;
    else if(600 < width <= 1100)
        width = 1100;
    else if(width <= 600)
        width = 600;
    return width;
};

var screenWidth;

if(window.innerWidth == undefined){
    screenWidth = document.documentElement.clientWidth;
}else screenWidth = innerWidth

var current_theme = getTheme(screenWidth),window_resized = false;
var time = 4500,
    slideEl = $("#slideContent"),
    indexAt = 1,
    slideHode = false,
    clicked = false,
    resized = [0,0,0,0];
var changeLength = 3;
var tend;

var initialBaner = function(){
    var doms = $(".page li.show .img-content div:eq(0) img");
    IMGResizeHandler(doms);
};

$(document).ready(function(){
    window_resized = true;
    resized[0] = 1;
    $(".page li:first").removeClass("hidden").addClass("show");
    initialBaner();
});

var IMGResizeHandler = function(doms,tend){
    doms.each(function(index){
        var h_before = parseInt($(this).height()),
            h_new;
        tend ? h_new = h_before * 440 /264: h_new = h_before * parseInt($(".hdp").css("height")) /440;
        $(this).css("height",h_new+"px");
    });
};

$(window).resize(function(){
    if(window.innerWidth == undefined){
        screenWidth = document.documentElement.clientWidth;
    }else screenWidth = innerWidth
    if(current_theme != getTheme(screenWidth)){
        tend = getTheme(screenWidth) > current_theme;
        resized = [0,0,0,0];
        window_resized = true;
        $(".page li").each(function(index){
            if($(this).hasClass("show") && resized[index] == 0 ){
                resized[index] = 1;
                var doms = $(".page li.show .img-content div:eq(0) img");
                IMGResizeHandler(doms,tend);

            }
        });
        current_theme = getTheme(screenWidth);
    }
});

var changeBanner = function(index) {
    if(!slideHode || clicked ){
        clicked = false;
        var current_banner = $("#slideContent .page a li.show");
        // $("#slideContent .page a li.show").animate({
        //     "opacity": 0,
        //     "left": "-980px",
        // },500);

        //     $("#slideContent .page a li.show").css({
        //     "opacity": 1,
        //     "left": "0px",
        //     });
            current_banner.removeClass("show").addClass("hidden");
            var current_dot = $(".focus-content-item a.current");
            current_dot.removeClass("current");
            if(index == 0){
                $("#slideContent .page a li:first").removeClass("hidden").addClass("show");
                $(".focus-content-item a:first").addClass("current");
            }else{
                current_banner.parent().parent().find("li:eq("+index+")").removeClass("hidden").addClass("show");
                current_dot.parent().parent().find("a:eq("+index+")").addClass("current");
            }
            if(window_resized == true && resized[index] == 0){
                resized[index] = 1;
                var doms = $(".page li.show .img-content div:eq(0) img");
                IMGResizeHandler(doms,tend);
            }
            indexAt = index + 1;
            indexAt %= changeLength;


    }
};

var slideAction = setInterval(function(){
    changeBanner(indexAt);
},time);


$(".focus-content-item a").hover(function(){
    var idx = $(this).attr("idx");
    changeBanner(parseInt(idx));
    slideHode = true;
},function(){
    slideHode = false;
});

$(".img-content").bind({
    "mouseenter": function() {
        slideHode = true;
    },
    "mouseleave": function() {
        slideHode = false;
    }
});
//})();

/*******轮播上的左右按钮事件  zhuqiao******/
$(".slide-left").bind({
    "click":function(e){
        slideHode = true;
        clicked = true;
        $("#slideContent .page a li").each(function(index){
            if($(this).hasClass("show")){
                index === 0 ? changeBanner(3) : changeBanner(index - 1);
                return false;
            }
        });
    },
    "mouseout":function(e){
        slideHode = false;
        clicked = false;
    }
});
$(".slide-right").bind({
    "click":function(e){
        slideHode = true;
        clicked = true;
        $("#slideContent .page a li").each(function(index){
            if($(this).hasClass("show")){
                index === 3 ? changeBanner(0) : changeBanner(index + 1);
                return false;
            }
        });
    },
    "mouseout":function(e){
        slideHode = false;
        clicked = false;
    }
});

/*********推广的悬停效果 zhuqiao***********/
$(".notice").hover(function(){
        var idx = parseInt($(this).attr("idx"));
        $(".screen ul li").each(function(){
            $(this).removeClass("yellow-point");
        });
        $(".screen ul li").slice(idx,idx+1).addClass("yellow-point");
        var leftPos = "-" + 445*idx+"px";
        $(".screen .item div").css("left",leftPos);
        //$(".screen .item div").animate({left:leftPos},500);

    },function(){
        $(".screen ul li").each(function(){
            $(this).removeClass("yellow-point");
        });
        $(".screen ul li:first").addClass("yellow-point");
        $(".screen .item div").css("left",0);
        //$(".screen .item div").animate({left:0},500);

});

/**************变现字体滚动效果 zhuqiao***************/
var font_blur = function(){
    //间隔设置为4s
    var cycle = 4000;
    var timer = window.setInterval(function(){
        // $("#mservice h3:eq(1)").css({"font-size":"16px","line-height":"30px"});
        // $("#mservice h3:eq(1) img").remove();
        // $("#mservice h3:eq(0)").css({"font-size":"30px","line-height":"90px"});
        // $("#mservice h3:eq(0)").prepend("<img src='./skins/MySkin/resources/img/icon/quotation-left.png'>");
        // $("#mservice h3:eq(0)").append("<img src='./skins/MySkin/resources/img/icon/quotation-right.png' class='quote-style'> ");
        // var remove_item = $("#mservice h3:last").remove();
        // $("#mservice .bianxian").after(remove_item);
        var current = $("#mservice h3.cashtitle-big");
        current.find("img").remove();
        current.removeClass("cashtitle-big");
        if(current.next("h3").length){
            current.next("h3").addClass("cashtitle-big");
            current.next("h3").prepend("<img src='./skins/MySkin/resources/img/icon/quotation-left.png'>");
            current.next("h3").append("<img src='./skins/MySkin/resources/img/icon/quotation-right.png' class='quote-style'> ");
        }
        else{
            $("#mservice h3:eq(0)").addClass("cashtitle-big");
            $("#mservice h3:eq(0)").prepend("<img src='./skins/MySkin/resources/img/icon/quotation-left.png'>");
            $("#mservice h3:eq(0)").append("<img src='./skins/MySkin/resources/img/icon/quotation-right.png' class='quote-style'> ");
        }


    },cycle);
};

font_blur();

/***************导航的选中高亮效果 zhuqiao***************/
var nav_li = $("#nav ul>li");
var current_page = null;
var nav_blur_action = function(me){
        me.addClass("nav_selected_li");
        me.find(">a").addClass("nav_selected_a");
        me.find(">a .arrow").addClass("nav_selected_arrow");
    };

    var nav_fadeout_action = function(){
        nav_li.removeClass("nav_selected_li");
        nav_li.find(">a").removeClass("nav_selected_a");
        nav_li.find(">a .arrow").removeClass("nav_selected_arrow");
    };

var nav_hover = function(){
    nav_li.hover(function(){
            var me = $(this);
            nav_fadeout_action();
            if(current_page != null)
                current_page.find(">a").css({"color":"#0098dd"});
            nav_blur_action(me);
        },function(){
            nav_fadeout_action();
            if(current_page != null)
                current_page.find(">a").css({"color":"#0098dd"});
    });
};
nav_hover();

var nav_blur = function(){
    nav_li.each(function(index){
        if(String(window.location).indexOf(encodeURI($(this).find(">a").attr("href"))) >= 0){
            current_page = $(this);
            current_page.find(">a").css({"color":"#0098dd"});
        }else{
            $(this).find("a").each(function(index){
                    if(String(window.location).indexOf($(this).attr("href")) >= 0){
                    var current_li = $(this).parent().parent().parent().parent();
                    current_page = current_li;
                    current_page.find(">a").css({"color":"#0098dd"});
                }
            });
        }
    });
};
nav_blur();
// console.log(String(window.location));
if(String(window.location).indexOf(encodeURI("搜索")) >=0){
    console.log("搜索页面la");
    $("#sidebar").css("display","none");
    $(".mcontainer").css("width","100%");
}

if(($.browser.msie == true) && ($.browser.version == "7.0" || $.browser.version == "8.0" || $.browser.version == "9.0" )){
    $(".develop-bg").css("height","320px");
    $(".wrap .out").css("margin-top","-215px");
    $(".wrap .in").css("margin-top","0");
}

