$(function() {	
	function Slide(slid) {
		var sWidth = $(slid).width();
		var len = $(slid).find("ul li").length;
		var index = 0;
		var picTimer;
		var btn = "<p class='m-slide-item'>";
		for(var i = 0; i < len; i++) {
			var ii = i + 1;
			btn += "<i>" + ii + "</i>";
		}
		btn += "</p><a class='m-slide-btn m-slide-lbtn' href='javascript:void(0);'></a><a class='m-slide-btn m-slide-rbtn' href='javascript:void(0);'></a>";
		$(slid).append(btn);

		//为小按钮添加鼠标滑入事件，以显示相应的内容
		$(slid + " p.m-slide-item i").css("opacity", 0.4).mouseenter(function() {
			index = $(slid + " .m-slide-item i").index(this);
			showPics(index);
		}).eq(0).trigger("mouseenter");

		//上一页、下一页按钮透明度处理
		$(slid + " .m-slide-btn").css("opacity", 0.8).hover(function() {
			$(this).stop(true, false).animate({
				"opacity": "1"
			}, 300);
		}, function() {
			$(this).stop(true, false).animate({
				"opacity": "0.8"
			}, 300);
		});

		//上一页按钮
		$(slid + " .m-slide-lbtn").click(function() {
			index -= 1;
			if(index == -1) {
				index = len - 1;
			}
			showPics(index);
		});

		//下一页按钮
		$(slid + " .m-slide-rbtn").click(function() {
			index += 1;
			if(index == len) {
				index = 0;
			}
			showPics(index);
		});

		//本例为左右滚动，即所有li元素都是在同一排向左浮动，所以这里需要计算出外围ul元素的宽度
		$(slid + " ul").css("width", sWidth * (len));

		//鼠标滑上焦点图时停止自动播放，滑出时开始自动播放
		$(slid).hover(function() {
			clearInterval(picTimer);
		}, function() {
			picTimer = setInterval(function() {
				showPics(index);
				index++;
				if(index == len) {
					index = 0;
				}
			}, 4000); //此4000代表自动播放的间隔，单位：毫秒
		}).trigger("mouseleave");

		//显示图片函数，根据接收的index值显示相应的内容
		function showPics(index) { //普通切换
			var nowLeft = -index * sWidth; //根据index值计算ul元素的left值
			$(slid + " ul").stop(true, false).animate({
				"left": nowLeft
			}, 300); 
			$(slid + " .m-slide-item i").removeClass("hover").eq(index).addClass("hover"); 
			$(slid + " .m-slide-item i").stop(true, false).animate({
				"opacity": "0.4"
			}, 300).eq(index).stop(true, false).animate({
				"opacity": "1"
			}, 300); 
		}

	};
	Slide(".m-slide-box");
	$(".m-zttj-box").eq(1).removeClass("f-fl").addClass("f-fr");

	function tab() {
		var tabli = $(".j-tabli").children();
		tabli.mouseover(function() {
			$(this).addClass("hover").siblings().removeClass("hover");
			var index = tabli.index(this);
			$(".j-tabcon").eq(index).show().siblings(".j-tabcon").hide();
		})
	}
	tab();

	function show() {
		$(".j-show").each(function() {
			var showli = $(this).children();
			showli.eq(0).addClass("hover");
			showli.mouseover(function() {
				$(this).addClass("hover").siblings().removeClass("hover");
			})
		});
	}
	show();

	function nav() {
		csee = '';
		$(".g-secnav-box li").eq(0).css("paddingLeft", "130px");
		$(".g-secnav-box li").eq(1).css("paddingLeft", "300px");
		$(".g-secnav-box li").eq(2).css("paddingLeft", "400px");
		$(".g-secnav-box li").eq(3).css("paddingLeft", "600px");
		$(".g-secnav-box li").eq(4).css("paddingLeft", "200px");
		function cce() {
			$('.g-secnav-box').animate({
				height: 45
			});
		}
		function cse() {
			$(function() {
				csee = setTimeout(function() {
					$('.g-secnav-box').animate({
						height: 0
					})
					$('.g-nav-box li').find('img').hide();
				}, 1000);
			});
		}
		$('.g-nav-box li').mouseover(function() {
			var ind = $(this).index();
			if(ind > 0 && ind < 6) {
				cce();
				$(this).find('img').show();
				$(this).siblings('li').find('img').hide();
				clearTimeout(csee);
				$('.g-secnav-box li').eq(ind - 1).show().siblings().hide();
			}
		});
		$('.g-nav-box li').mouseleave(function() {
			var ind = $(this).index();
			cse();
		});
		$('.g-secnav-box li').mouseover(function() {
			var ind = $(this).index();
			cce();
			clearTimeout(csee);
		});
		$('.g-secnav-box li').mouseleave(function() {
			var ind = $(this).index();
			cse();
		});
	}
	nav();

	$(".m-mr-right .f-tw").mouseover(function() {
		$(this).find("p").stop().animate({
			opacity: "1"
		}, 300);
	}).mouseout(function() {
		$(this).find("p").stop().animate({
			opacity: "0"
		}, 300);
	})
	for(var n = 0; n < 3; n++) {
		$(".m-mr-right .f-newlist li").eq(n).addClass("top");
	}

	if($('.ContBox').length > 0){
		var scrollPic_02 = new ScrollPic();
		scrollPic_02.scrollContId = "ContBox";
		scrollPic_02.arrLeftId = "LeftBtn";
		scrollPic_02.arrRightId = "RightBtn";
		scrollPic_02.frameWidth = 1064;
		scrollPic_02.pageWidth = 270;
		scrollPic_02.speed = 10;
		scrollPic_02.space = 10;
		scrollPic_02.autoPlay = false;
		scrollPic_02.autoPlayTime = 3;
		scrollPic_02.initialize();
	}
	

	function gototop() {
		var backtop_box = document.getElementById("backtop");
		var oSys = true;
		$(".m-backtop .wxbox,.m-backtop .column").hover(function(){
          $(".column").show();
        },function(){
          $(".column").hide();
        });
		$(".m-backtop .ewm").hover(function(){
          $(".ewmbox").show();
        },function(){
          $(".ewmbox").hide();
        });
		var Top = 600;
		var sTop;
		window.onscroll = function() {
			if(!oSys) {
				clearInterval(timer);
			}
			oSys = false;
		}
		$(".scbox").hover(function() {
				$(this).find(".sc-zk").css("display", "block");
			},
			function() {
				$(this).find(".sc-zk").css("display", "none");
			});
		var gTop = $(".back");
		var timer = null;
		gTop.click(function() {
			timer = setInterval(function() {
				var sTop = document.documentElement.scrollTop || document.body.scrollTop;
				var speed = Math.floor(-sTop / 8);
				oSys = true;
				if(sTop <= 0) {
					clearInterval(timer);
				} else {
					document.documentElement.scrollTop = document.body.scrollTop = sTop + speed;
				}
			},
			20)
		});
		$(".m-backtop .column li").click(function(){
			var index = $(".m-backtop .column li").index(this);
			switch(index){
               case 0:
                scroll_to(".g-Cblock");
               break;
               case 1:
                scroll_to(".g-Dblock");
               break;
			   case 2:
                scroll_to(".g-Eblock");
               break;
			   case 3:
                scroll_to(".g-Fblock");
               break;
			   case 4:
                scroll_to(".g-Gblock");
               break;
               default:
               
            }
		});
		function scroll_to(div){
           $('html, body').animate({
              scrollTop: $(div).offset().top
           },500);
        }
	}
	gototop();

	function Search() {
		$(".hotwordbox li").eq(0).addClass("top");
		$(".hotwordbox li").eq(1).addClass("top");
		$(".hotwordbox li").eq(2).addClass("top");
		var n = true;
		$(".hotword").click(function(e) {
			e = e || window.event;
			e.stopPropagation();
			if(n) {
				$(".hotwordbox").show();
				$(this).removeClass("hotword-on");
				n = false;
			} else {
				$(".hotwordbox").hide();
				n = true;
			}
		});
		$(document).click(function() {
			$(".hotwordbox").hide();
			n = true;
		});
		function init(str){
			var input = $('.m-search-inputbox').val('')[0],
				s = '欢迎光临本站，您想搜索点神马'.split('').reverse(),
				len = s.length-1,
				e = $.Event('keypress');

			var	initInterval = setInterval(function(){
					if( s.length ){
						var c = s.pop();
						input.value += c;
					}
					else clearInterval(initInterval);
			},150);
		}
		init();
	}
	Search();

	function oSearchSuggest(searchFuc) {
		var input = $('#keyword');
		var suggestWrap = $('#search_suggest');
		var key = "";
		var init = function() {
			input.bind('keyup', sendKeyWord);
			input.bind('blur', function() {
				setTimeout(hideSuggest, 1000);
			})
		}
		var hideSuggest = function() {
			suggestWrap.hide();
		}
		//发送请求，根据关键字到后台查询 
		var sendKeyWord = function(event) {
			if(suggestWrap.css('display') == 'block' && event.keyCode == 38 || event.keyCode == 40) {
				var current = suggestWrap.find('li.hover');
				if(event.keyCode == 38) {
					if(current.length > 0) {
						var prevLi = current.removeClass('hover').prev();
						if(prevLi.length > 0) {
							prevLi.addClass('hover');
							input.val(prevLi.html());
						}
					} else {
						var last = suggestWrap.find('li:last');
						last.addClass('hover');
						input.val(last.html());
					}
				} else if(event.keyCode == 40) {
					if(current.length > 0) {
						var nextLi = current.removeClass('hover').next();
						if(nextLi.length > 0) {
							nextLi.addClass('hover');
							input.val(nextLi.html());
						}
					} else {
						var first = suggestWrap.find('li:first');
						first.addClass('hover');
						input.val(first.html());
					}
				}
			} else {
				var valText = $.trim(input.val());
				if(valText == '' || valText == key) {
					return;
				}
				searchFuc(valText);
				key = valText;
			}
		}
		//请求返回后，执行数据展示 
		init();
	};
	function datadispaly(data){
		    var suggestWrap = $('#search_suggest');
			if(data.length <= 0) {
				suggestWrap.hide();
				return;
			}
			//往搜索框下拉建议显示栏中添加条目并显示
			var li;
			var tmpFrag = document.createDocumentFragment();
			suggestWrap.find('ul').html('');
			for(var i = 0; i < data.length; i++) {
				li = document.createElement('LI');
				li.innerHTML = data[i];
				tmpFrag.appendChild(li);
			}
			suggestWrap.find('ul').append(tmpFrag);
			suggestWrap.show();
			//为下拉选项绑定鼠标事件 
			suggestWrap.find('li').hover(function(){ 
               $(this).addClass('hover'); 
            },function(){ 
               $(this).removeClass('hover'); 
            });
	}
	function sendKeyWordToBack(keyword){
		var key = keyword;
		$.ajax({
			   type: "Get",
			   url: "/e/api/search_keyword.php",
			   data: "keyword="+keyword,
			   dataType:"json",
			   success: function(data){
				 listDate(data,key);
			   }
	    });
	}
    function listDate(msg,keys){
		    var aData = [];
			var html = '';
			var keyword = keys;
			var a = new RegExp(keyword,"g");
			var t;
			msg.forEach(function(item){
				 var title = item.title;
				 t = title.replace(a,("<b style='color:#ff5555'>" + keyword + "</b>"));
                 html = '<a href="http://www.5h.com'+item.url+'">'+t+'</a>';
				 aData.push(html);
            })
			datadispaly(aData);
	}
	//var searchSuggest = new oSearchSuggest(sendKeyWordToBack); 
});