$(function(){
	/**版块选择相关*/
	var currentSection=0;
	var sectionSelectItem=$(".sectionSelectItem");
	var sectionSelectButton=$("#sectionSelectButton");
	$(".sectionSelectAll").css("width",$("#sectionSelect").width()+"px");
	$("#sectionSelectButton,.sectionSelectItem").hover(function(){
		$(this).animate( {
			"backgroundColor" :"white",
			"color":"black"
		}, doAnimation ? 300 : 0);
	},function(){
		$(this).animate( {
			"backgroundColor" :common_normalColor,
			"color":"white"
		}, doAnimation ? 300 : 0);
	});
	sectionSelectButton.click(function(){
		var sectionSelect=$("#sectionSelect");
		if(sectionSelect.is(":hidden")){
			sectionSelect.fadeIn(doAnimation?400:0);
		}else{
			sectionSelect.fadeOut(doAnimation?400:0);
		}
	});
	$(document).click(function(event){
		var eventId=$(event.target).attr("id")
		var eventClass=$(event.target).attr("class");
		if(eventId!="sectionSelectButton"&&eventClass!="sectionSelectTd"&&eventClass!="sectionSelectItemTop normalColor"){
			var sectionSelect=$("#sectionSelect");
			if(!sectionSelect.is(":hidden")){
				sectionSelect.fadeOut(doAnimation?400:0);
			}
		}
	});
	sectionSelectItem.click(function(){
		sectionSelectButton.html($(this).html());
		var id=$(this).attr("id");
		id=id.substring(id.indexOf("_")+1);
		currentSection=id;
	});
	/**搜索相关*/
	var bbsSearchIsVal=false;
	var search=$("#search");
	var searchInput=$("#searchInput");
	searchInput.focus(function(){
		if(!bbsSearchIsVal){
			$(this).css("color","black");
			$(this).val("");
			bbsSearchIsVal=true;
		}
	});
	searchInput.blur(function(){
		if($(this).val()==""&&bbsSearchIsVal){
			$(this).css("color","#999999");
			$(this).val("Search...");
			bbsSearchIsVal=false;
		}
	});
	searchInput.keyup(function(){
		var searchStr=$(this).val();
		if(trim(searchStr).length!=0&&searchStr.length<=20&&bbsSearchIsVal){
			search.attr("href","/bbs/search/"+encodeURIComponent(searchStr)+"/"+currentSection+"/1.html");
		}
	});
	function checkBbsSearch(){
		var searchStr=searchInput.val();
		if(trim(searchStr).length!=0&&searchStr.length<=20&&bbsSearchIsVal){
			return true;
		}else{
			return false;
		}
	}
	searchInput.keypress(function(e){
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code==13){
			if(!checkBbsSearch()){
				alert("搜索内容不能为空！");
				return;
			}
			window.parent.location.href=search.attr("href");
		}
	});
	search.click(function(){
		if(!checkBbsSearch()){
			alert("搜索内容不能为空！");
			return false;
		}
	});
	search.hover(function(){
		$(this).css("background-image","url('/pages/other/images/main/mainUtil/bbsSearchButtonHover.jpg')");
	},function(){
		$(this).css("background-image","url('/pages/other/images/main/mainUtil/bbsSearchButton.jpg')");
	});
	/**天气重新加载*/
	function reInitWeather(){
		$("#m_weatherError").hide();
		$("#m_weatherLoading").show();
		weather_getWeather();
	}
	$("#m_weatherError").click(function(){
		reInitWeather();
	});
	/**左上图片效果*/
	var leftPhotoA=$("#m_top2_leftPhoto ul li a");
	leftPhotoA.hover(function(){
		$(this).stop().animate({"width":"250px"},{"duration": doAnimation?450:0, "easing":"easeOutQuad"});
	},function(){
		if($(this.parentNode).index()!=$("#m_top2_leftPhoto ul li a").length-1){
			$(this).stop().animate({"width":"39px"},{"duration":doAnimation?400:0,"easing":"easeInOutQuad"});
		}
	});
	/**top2_middle切换效果*/
	var top2MiddleIndex=-1;
	$(".m_top2_middle_tItem").hover(function(){
		top2MiddleIndex=$(this).index();
		var obj=$(this);
		var index=$(this).index();
		setTimeout(function(){changeTop2Middle(obj,index)},200);
	},function(){
		top2MiddleIndex=-1;
	});
	function changeTop2Middle(obj,index){
		if(index==top2MiddleIndex){
			var items=$(obj[0].parentNode).find("div.m_top2_middle_tItem");
			items.css("border-bottom","1px solid #B1C8D7");
			items.css("font-weight","");
			items.css("background-image","url('/pages/other/images/main/mainUtil/selectItemBg.jpg')");
			items.css("background-color",mainTitleColor);
			obj.css("border-bottom","");
			obj.css("font-weight","bold");
			obj.css("background-image","");
			obj.css("background-color",mainTitleHoverColor);
			$("#m_top2_middle_d").animate({
				"marginLeft":-(obj.index()*372)+"px"
			}, doAnimation ? 300 : 0);
		}
	}
	var instanceOne = new ImageFlow();
	instanceOne.init({"ImageFlowID":"m_top3_photo", 
		"aspectRatio":5.464,
		"reflections":false,
		"buttons":true,
		"circular":true,
		"imageFocusM":1,
		"imageFocusMax":5,
		"imagesHeight":0.57,
		"imagesM":1.5,
		"reflectionP":0.2,
		"scrollbarP":0.6,
		"xStep":100,
		"opacity":true,
		"opacityArray":[10,7,4,2,1],
		"animationSpeed":40,
		"startAnimation":true
	});
});
/**天气获取结果*/
function weather_callback(json){
	var m_top2_right_t=$("#m_top2_right_t");
	$("#m_weatherLoading").hide();
	if(json==null){
		$("#m_weatherError").show();
		return;
	}
	m_top2_right_t.hide();
	var html="<table id='m_weather' cellpadding='0px' cellspacing='0px'>" +
			"<tr><td id='m_weatherTop'><img id='"+json.currentDay.icon+"' class='m_weatherTop_img' src='' style='float: left;width:80px;height:80px;' alt='"+json.currentDay.condition+"' title='实时天气'/>" +
			"<div id='m_weatherTop_info'><font id='m_weatherTop_info_f1'>"+json.city+"</font><br/><font id='m_weatherTop_info_f1'>"+json.currentDay.tempC+"°C | "+json.currentDay.tempF+"°F</font><br/>" +
			"<font class='m_weatherTop_info_f2'>"+json.currentDay.condition+" "+json.date+"</font><br/><font class='m_weatherTop_info_f3'>"+json.currentDay.windCondition+"<br/>"+json.currentDay.humidity+"</font>" +
			"</div></td></tr><tr><td>";
	for(var i in json.forecastDay){
		html+="<div class='m_weatherDown'><div class='m_weatherDown_info_f'>"+json.forecastDay[i].dayOfWeek+"</div>" +
				"<img id='"+json.forecastDay[i].icon+"' class='m_weatherDown_img' src='' style='width:40px;height:40px;' title='"+json.forecastDay[i].condition+"' alt='"+json.forecastDay[i].condition+"'/>" +
				"<div class='m_weatherDown_info_f2'><font class='m_weatherDown_info_min'>"+json.forecastDay[i].low+"~</font>"+json.forecastDay[i].high+"°C</div></div>";
		if(i==4){
			break;
		}
	}
	html+="</td></tr></table>";
	m_top2_right_t.html(html);
	var images=m_top2_right_t.find("img");
	for(i=0;i<images.length;i++){
		var image=$(images[i]);
		image.attr("src",image.attr("id"));
	}
	m_top2_right_t.show();
}
/**初始化左上角相片切换效果*/
function initLeftTopPhoto(){
	var leftPhotoA=$("#m_top2_leftPhoto ul li a");
	for(i=0;i<leftPhotoA.length;i++){
		if(i==2){
			$(leftPhotoA[i]).stop().animate({"width":"250px"},{"duration": 0, "easing":"easeOutQuad"});
		}else{
			$(leftPhotoA[i]).stop().animate({"width":"39px"},{"duration":0,"easing":"easeInOutQuad"});
		}
	}
}
