/*** Javascript ***/
$(document).ready(function(){

	var cotyid = $("#city_id").val();
	var areaid = $("#area_id").val();

	getOption("#city_id",0,'/ajax/json_area.php');

	$("#city_id").change(function(){
		getOption("#area_id",this.value,'/ajax/json_area.php');
	})

});

$(function(){

	//搜索切换
	$(".search_tab li").hover(function(){
		$(".search_tab li").removeAttr('class');
		$(this).attr('class','search_tab_ch');
		//$("#togo").val($(this).attr("rel"));
		//var setype=$("#togo").val();
		var setype=$(this).attr("rel");
		if(setype==0){
			$("#search").attr("name","keyword22");
			$("#searchform").attr("action","/newhouse/search_newhouse.php");
		}else if(setype==1){
			$("#search").attr("name","KeyWord");
			$("#searchform").attr("action","/oldhouse/search_oldhouse.php");
		}else if(setype==2){
			$("#search").attr("name","KeyWord2");
			$("#searchform").attr("action","/rent/rent_search.php");
		}else if(setype==4){
			$("#search").attr("name","keys");
			$("#searchform").attr("action","/search/blog_search.php");
		}else if(setype==5){
			$("#search").attr("name","keys");
			$("#searchform").attr("action","/search/video_search.php");
		}else{
			$("#search").attr("name","keys");
			$("#searchform").attr("action","/search/news_search.php");
		}
	})

	//幻灯片
	var len  = $(".fouce_btn > li").length;
	var index = 0;
	var timer;
	$(".fouce_btn li").hover(function(){
	index = $(".fouce_btn li").index(this);
	show(index);
	}).eq(0).click();

	$("#fouce_l").click(function(){
		index--;
		if(index==-1){index=len-1;}
		show2(index)
	})
	$("#fouce_r").click(function(){
		index++;
		if(index==len){index=0;}
		show(index)
	})
	//经过暂停自动播放
	$('.fouce').hover(function(){
		clearInterval(timer);
		$('#fouce_l').show();
		$('#fouce_r').show();
	},function(){
		$('#fouce_l').hide();
		$('#fouce_r').hide();
		timer = setInterval(function(){
		index++;
		if(index==len){index=0;}
		show(index)
		 } , 3000);
	}).trigger("mouseleave");

	//切换
	var houselen = $("#housefocus .focus_btn > li").length;
	var houseindex = 0;
	var housetimer;
	$("#housefocus .focus_btn li").hover(function(){
	houseindex = $("#housefocus .focus_btn li").index(this);
	houseshow(houseindex);
	}).eq(0).click();

	//经过暂停自动播放
	$('#housefocus').hover(function(){
		clearInterval(housetimer);
	},function(){
		housetimer = setInterval(function(){
		houseindex++;
		if(houseindex==houselen){houseindex=0;}
		houseshow(houseindex)
		 } , 3000);
	}).trigger("mouseleave");


	//切换
	var intlen = $("#intfocus .focus_btn > li").length;
	var intindex = 0;
	var inttimer;
	$("#intfocus .focus_btn li").hover(function(){
	intindex = $("#intfocus .focus_btn li").index(this);
	intshow(intindex);
	}).eq(0).click();

	//经过暂停自动播放
	$('#intfocus').hover(function(){
		clearInterval(inttimer);
	},function(){
		inttimer = setInterval(function(){
		intindex++;
		if(intindex==intlen){intindex=0;}
		intshow(intindex)
		 } , 3000);
	}).trigger("mouseleave");


	//新闻切换
	var newslen = $("#newsfocus .focus_btn > li").length;
	var newsindex = 0;
	var newstimer;
	$("#newsfocus .focus_btn li").hover(function(){
	newsindex = $("#newsfocus .focus_btn li").index(this);
	newsshow(newsindex);
	}).eq(0).click();

	//经过暂停自动播放
	$('#newsfocus').hover(function(){
		clearInterval(newstimer);
	},function(){
		newstimer = setInterval(function(){
		newsindex++;
		if(newsindex==newslen){newsindex=0;}
		newsshow(newsindex)
		 } , 3000);
	}).trigger("mouseleave");

	//手机订阅滚动
	myGod('subscribe',5000);

})


function show(index){

	$(".fouce_pic li").stop(false,true).fadeOut();
	$(".fouce_pic li").eq(index).stop(false,true).fadeIn();
	$(".fouce_about li").stop(false,true).fadeOut();
	$(".fouce_about li").eq(index).stop(false,true).fadeIn();
	$(".fouce_btn li").removeClass("on")
	.eq(index).addClass("on");
}

function show2(index){
	$(".fouce_pic li").stop(false,true).fadeOut();
	$(".fouce_pic li").eq(index).stop(false,true).fadeIn();
	$(".fouce_about li").stop(false,true).fadeOut();
	$(".fouce_about li").eq(index).stop(false,true).fadeIn();
	$(".fouce_btn li").removeClass("on")
	.eq(index).addClass("on");
}




function houseshow(houseindex){
	$("#housefocus .focus_pic li").stop(false,true).fadeOut();
	$("#housefocus .focus_pic li").eq(houseindex).stop(false,true).fadeIn();
	$("#housefocus .focus_about li").stop(false,true).fadeOut();
	$("#housefocus .focus_about li").eq(houseindex).stop(false,true).fadeIn();
	$("#housefocus .focus_btn li").removeClass("on")
	.eq(houseindex).addClass("on");
}



function intshow(intindex){
	$("#intfocus .focus_pic li").stop(false,true).fadeOut();
	$("#intfocus .focus_pic li").eq(intindex).stop(false,true).fadeIn();
	$("#intfocus .focus_about li").stop(false,true).fadeOut();
	$("#intfocus .focus_about li").eq(intindex).stop(false,true).fadeIn();
	$("#intfocus .focus_btn li").removeClass("on")
	.eq(intindex).addClass("on");
}



function newsshow(newsindex){
	$("#newsfocus .focus_pic li").stop(false,true).fadeOut();
	$("#newsfocus .focus_pic li").eq(newsindex).stop(false,true).fadeIn();
	$("#newsfocus .focus_about li").stop(false,true).fadeOut();
	$("#newsfocus .focus_about li").eq(newsindex).stop(false,true).fadeIn();
	$("#newsfocus .focus_btn li").removeClass("on")
	.eq(newsindex).addClass("on");
}


function nTabs(thisObj,Num){
	if(thisObj.className == "active")return;
	var tabObj = thisObj.parentNode.id;
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");
	for(i=0; i <tabList.length; i++)
	{
		if (i == Num)
		{
		   thisObj.className = "active";
			  document.getElementById(tabObj+"_Content"+i).style.display = "block";
		}else{
		   tabList[i].className = "normal";
		   document.getElementById(tabObj+"_Content"+i).style.display = "none";
		}
	}
}

function myGod(id,w,n){
	var box=document.getElementById(id),can=true,w=w||1500,fq=fq||10,n=n==-1?-1:1;
	box.innerHTML+=box.innerHTML;
	box.onmouseover=function(){can=false};
	box.onmouseout=function(){can=true};
	var max=parseInt(box.scrollHeight/2);
	new function (){
		var stop=box.scrollTop%30==0&&!can;
		if(!stop){
			var set=n>0?[max,0]:[0,max];
			box.scrollTop==set[0]?box.scrollTop=set[1]:box.scrollTop+=n;
		};
		setTimeout(arguments.callee,box.scrollTop%30?fq:w);
	};
};
