$(document).ready(function(){
	//fix ie6,7bug with jQuery.support.style return false
	$(".loading").ajaxStart(function(){
		if(jQuery.support.style){$(this).fadeIn();}else{$(this).show();}
	}).ajaxComplete(function(){
		if(jQuery.support.style){$(this).fadeOut();}else{$(this).hide();}
	});
	var isClicked = false;
	//TODO: 导航在加载过程中不允许再点击其它导航。
	$("#mainNav a").click(function(event){
		var nIndex = $("#mainNav a").index(this);
		//第一个索引为Home
		if(nIndex != 0){
			event.preventDefault();
			$("#mainNav a").removeClass("atNav");
			$(this).addClass("atNav");
			//导航点击后触发一次性事件
			if(isClicked == false){
				$("#siteIntro").fadeOut();
				$("#copyright").fadeOut();
				$(".preview").slideDown("3000");
				$("#co5").width("82%");
				$("#centerCon").animate({width:"16%"},{duration:500});
				$("#rightCon").animate({width:"64%"},{duration:450});
				isClicked = true;
			}else{
				//导航点击后触发动画效果
				$("#centerCon").animate({width:"8%"},{duration:100}).animate({width:"16%"},{duration:100});
				$("#rightCon").animate({width:"74%"},{duration:100}).animate({width:"64%"},{duration:100});
			}
			var nowAt = $(this).text();
			$("#nowAt").text(nowAt+"->").slideDown("slow");
			if(jQuery.support.style)$("#ajaxCon").slideUp(200);
			//导航点击后触发ajax请求事件并加载对应页面
			var nId = $(this).parent().attr("id");
			$.ajax({
				type: "POST",
				url: nId + ".php", 
				data: "t=" + Math.random(),
				dataType: "html",
				timeout: 10000,
				error: function(XMLHttpRequest, textStatus, errorThrown){
					//错误处理
					$("#ajaxCon").html("<div class='tipError'>Error occured &nbsp;("+XMLHttpRequest.status+" error)&nbsp;, please try again later.</div>");
				},
				success: function(data, textStatus){
					if(jQuery.support.boxModel){$("#ajaxCon").html(data).slideDown(200);}else{$("#ajaxCon").html(data);}
				}
			});
		}
	});
	$("#lang_c").toggle(function(){$("#langBox").slideDown();},function(){$("#langBox").slideUp();});
	$("#langBox a").click(function(e){
		e.preventDefault();
		var lang = $(this).attr("rel");	//default choice!
		lang = $(this).attr("rel") == "" ? 'zh-cn' : lang;
		$.post("lang.php", {c: lang}, function(){window.location.reload();});}
	);
});


