//返回顶部
$(document).ready(function(){  
    $("#go_top").hide();  
    $(function () {  
        //检测屏幕高度  
        var height=$(window).height();  
        //scroll() 方法为滚动事件  
        $(window).scroll(function(){  
            if ($(window).scrollTop()>height){  
                $("#go_top").fadeIn(500);  
            }else{  
                $("#go_top").fadeOut(500);  
                }  
        });  
        $("#go_top").click(function(){  
            $('body,html').animate({scrollTop:0},100);  
            return false;  
        });  
    });  
}); 

//导航下拉
$(function(){
	var _this1 = null;
	$('.navbar-nav > li').hover(function(){
		_this1 = $(this);
		_this1.find('.child_1').show();
		var _this2 = null;
		_this1.find('.child_1').find('li').hover(function(){
			_this2 = $(this);
			_this2.find('.child_2').show();
			_this2.find('.child_2').hover(function(){
				$(this).show();
			},function(){
				$(this).hide();
			});
		},function(){
			_this2.find('.child_2').hide();
		});
	},function(){
		_this1.find('.child_1').hide();
	});
});

//提交搜索
function search_submit(){
	var wd = $('#wd').val();
	if(wd == ''){
		alert('请输入搜索关键词');
		return false;
	}
	window.location.href = "/search/"+wd;
}

//分享代码
window._bd_share_config = {
	"common": {
		"bdSnsKey": {},
		"bdText": "",
		"bdMini": "2",
		"bdMiniList": false,
		"bdPic": "",
		"bdStyle": "0",
		"bdSize": "16"
	},
	"share": {}
};
with(document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];

//在线客服
$.fn.toggle = function (fn, fn2) {
    var args = arguments,
        guid = fn.guid || $.guid++,
        i = 0,
        toggle = function (event) {
            var lastToggle = ($._data(this, "lastToggle" + fn.guid) || 0) % i;
            $._data(this, "lastToggle" + fn.guid, lastToggle + 1);
            event.preventDefault();
            return args[lastToggle].apply(this, arguments) || false;
        };
    toggle.guid = guid;
    while (i < args.length) {
        args[i++].guid = guid;
    }
    return this.click(toggle);
};
var _windowScrollTop = 0; //滚动条距离顶端距离  
var _windowWidth = $(window).width(); //窗口宽度  
$(window).scroll(actionEvent).resize(actionEvent); //监听滚动条事件和窗口缩放事件 
 
//响应事件  
function actionEvent() {
	_windowScrollTop = $(window).scrollTop(); //获取当前滚动条高度  
	moveQQonline(); //移动面板  
}
//移动面板  
function moveQQonline() {
    $(".kf").stop().animate({
        top: _windowScrollTop + 180
    }, "fast");
    $('.alignCenter').stop().animate({
        top: _windowScrollTop + 133
    }, "fast");
}
$(".kf_btn").toggle(
    function () {
        $('.open').addClass('close');
        $('.alignCenter').hide();
        $(".kf_main").animate({
            width: 'hide',
            opacity: 'hide'
        }, 'normal', function () {
            $(".kf_main").hide();
        });
    },
    function () {
        $('.open').removeClass('close');
        $(".kf_main").animate({
            opacity: 'show'
        }, 'normal', function () {
            $(".kf_main").show();
        });
    }
);
$('#hidden_share').click(function () {
    $('.alignCenter').show();
})
$('.alignCenter .title img').click(function () {
    $('.alignCenter').hide();
})

//留言板
$(function(){ 
  $('.m_close').addClass('m_open');
  $('.w_message').css('display','none');
})

$(".w_title").toggle(function(){
	//$(".w_message").hide();
    $(".w_message").show();
	$(".m_close").attr("title","最大化");	
	//$(".m_close").addClass("m_open");
	$(".m_close").removeClass("m_open");
},
function(){
	$(".w_message").hide();
	//$(".m_close").attr("title","最小化");
	$(".m_close").addClass("m_open");	
});


//提交留言
$('#footsub').on('click', function(){
  name = $('#iname').val();
  content = $('#icontent').val();
  code = $('#icode').val();
  mobile = $('#imobile').val();
  
  if(!content){	 alert('请输入留言内容'); return false; }  
  if(!name){ alert('请输入姓名'); return false; }  
  if(!mobile){ alert('请输入电话'); return false; }  
  if(!code){ alert('请输入验证码');  return false; }
  
  $.ajax({ 
        url: '/index/guestbook/save/',
		data:{"name":name,"mobile":mobile,"content":content,"code":code},
        type: "POST",
        success: function(data){
			if(data.code==0){
				alert('留言失败');
				return false;
			} else if(data.code==1){
				alert('留言成功');
				return false;
			}
        },
        error:function(data){
			layer.msg('系统繁忙', {icon: 2,time: 2000}, function(){}); 
        }
    });
});

//走马灯效果
$(function(){
	var walking = $('.walking');
	//走马灯
	walking.liMarquee();
	//向上滚动新闻	
	$('.dowebok').liMarquee({
		direction: 'up',
		scrollamount: 20
	});
	//大图片适应
	//$("#banner .item").autoIMG();

	walking.find('.str_move a').click(function () {
		window.location.href = $(this).attr('href');
	});
});

//首页产品分类菜单
$(".sy_layer1").hover(
	function () {
		if ($(this).find(".sy_layer2 li").length > 0) {
			$(this).find(".sy_layer2").show();
		}
	},
	function () {
		$(this).find(".sy_layer2").hide();
	}
);

//大图轮换
$(document).ready(function(){
	$('.flexslider').flexslider({
		animation: "slide",
      slideshow:false,
		slideshowSpeed: 5000,
		directionNav: true,
		pauseOnAction: false,
		keyboardNav: true,
	});
});

//大图打开URL
function adurl(url){
	if(url){
		window.location.href = url;
	}
}

$('.layer1').hover(function() {
	if ($(this).find('.layer2 li').size() > 0) {
		$(this).find('.layer2').show();

		$(this).find('.layer2 .ll').each(function(k, v) {
			$('.layer-c-' + k).hover(function() {
				 if ($(this).find('.layer3 li').size() > 0) {
					$(this).find('.layer3').show();
				 }
			}, function() {
				$(this).find('.layer3').hide();
			});
		});
	}
}, function() {
	$(this).find(".layer2").hide();
});

// 询盘邀请
var Dialogue = $('#Dialogue_invitation'),
m_div = $('#m_div');

if (Dialogue.attr('is_show') == 1) {
	// 咨询、关闭
	Dialogue.find('.Dialogue_close,.Dialogue_btn_no,.Dialogue_btn_ok').on('click', function() {
		if ($(this).attr('class') == 'Dialogue_btn_ok') {
			m_div.find('.w_message').css('display', 'block');
			$('#icontent').focus();
			Dialogue.hide();
		} else {
			Dialogue.hide();
		}
	});

	setTimeout(function () {
		setCenter(Dialogue);
		Dialogue.show();
	}, 3000);
}

setCenter(Dialogue);

// 设置物体居中
function setCenter(dom) {
	dom.css({
		top: ($(window).height() - Dialogue.height()) / 2,
		left: ($(window).width() - Dialogue.width()) / 2
	});
}