$(document).ready(function(){
	/*大事记*/
	if($(".about_year").length>0){
		$(".events").hide();
		$(".events").eq(0).show();
		about_dashiji();
	}
	/*留言*/
	if($("#btn_msg").length>0){
		leave_message();
	}
	$("#btn_reset").click(function(){
		document.frm.reset();
	})
	/*搜索*/
	if($("#search_btn").length>0){
		$("#search_btn").click(function(){
			var keywords=$.trim($("#keywords").val());
			if(keywords==''){
				alert("请输入关键字！");
				$("#keywords").focus();
				return false;
			}
		})
	}
	//菜单--新闻中心
	var num=$(".news_nav_type li").length;
	var height=num*34;
	var top=-height;
	$(".sub_news_list").css("height",height+"px");
	$(".sub_news_list").css("top",top+"px");
	
	//首页滚动
	if($(".index_productPic").length == 1){
		setInterval('move()', 4000);
	}
})

function move(){
	var top = parseInt($(".move").css('top'))-150;
	$(".move").animate({top:top},1000,function(){
		var h = $(".move").height()/2;
		if(top+h<=0){
			$(".move").css("top",top+h);
		}
	});
}

function about_dashiji(){
	$(".about_year").click(function(){
		$(".about_year").removeClass("on");
		$(this).addClass("on");
		$(".events").hide();
		$(this).next(".events").show();
	})
}

function leave_message(){
	if($("#load").length == 0)
	{
		var w = $(document).width();
		var h = $(document).height()- ($.browser.msie?4:0);
		var load = $('<div id="load" style="position:absolute;left:0px;top:0px;width:100%;height:100px;text-align:center;background:#fff;z-index:999;"></div>').appendTo("body");
		$("#load").html("<img src='images/loading.gif'>").css({height:h});	
		$("#load img").css({marginTop:h/2});
		$("#load").hide();
	}
	$("#btn_msg").click(function(){
		var title = $.trim($("#title").val());
		var name = $.trim($("#name").val());
		var tel = $.trim($("#tel").val());
		var email = $.trim($("#email").val());
		var content = $.trim($("#content").val());
		var code = $("#code").val();
		if(title==''){
			alert("标题不能为空！");
			$("#title").focus();
			return false;
		}
		if(name==''){
			alert("姓名不能为空！");
			$("#name").focus();
			return false;
		}
		if(tel==''){
			alert("联系电话不能为空！");
			$("#tel").focus();
			return false;
		}
		if(email==''){
			alert("电子邮箱不能为空！");
			$("#email").focus();
			return false;
		}
		if(!isEmail(email)){
			alert("电子邮箱格式错误！");
			$("#email").focus();
			return false;
		}
		if(content==''){
			alert("详细内容不能为空！");
			$("#content").focus();
			return false;
		}
		if(code==''){
			alert("验证码不能为空！");
			$("#code").focus();
			return false;
		}
		var data = {title:title,name:name,tel:tel,email:email,content:content,code:code};
		$("#load").fadeTo(200,0.7,function(){
			$.ajax({
				type:'POST',
				url:'/ajax.php',
				dataType:'text',
				data:data,
				complete:function(){
					$("#load").hide();
				},
				success:function(msg){
					if(msg==1){
						alert("验证码错误！");
						$("#code").val('');
						$("#imgcode").attr("src","/include/checkcode.php?r="+ Math.random());
						$("#code").focus();
					}
					else{
						alert("留言成功！");
						document.frm.reset();
					}
				}
			});
		});
	})
}

function isEmail(str){ 
	res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/; 
	var re = new RegExp(res); 
	return !(str.match(re) == null); 
}
