/*function 区域*/ 
function changeSlideC(sHead,sCont,sSource,sTitle){
var a=0;

$(sHead).each(function(i){
		$(sHead).eq(i).click(function(){
				if(a!=i){
				$(sHead).eq(a).attr("className","");
				$(sCont).eq(a).fadeOut('slow');
				a=i;}
				
				$(this).attr("className","now");
				$(sCont).eq(i).fadeIn('slow');
				$(sTitle).html($(sSource).eq(i).html());
				return false;
			});
		});
}


/*加载脚本*/

$(document).ready(function(){


if ($("#recomMain").length) {
	var a=0;
	var b,c;
	var img=$("#recomPic img");
	var len=img.length-1;
	var $prev=$("#a_recomPrev");
	var $next=$("#a_recomNext");
	var $prevS=$("#span_recomPrev");
	var $nextS=$("#span_recomNext");
	var autoRecomRun;

function microPic(x){
	if(a==len){b=-1;}else{b=a;}
	if(a==0){c=len+1;}else{c=a;}
	$nextS.html(img.eq(b+1).clone());
	$nextS.find('img').hide();
	$prevS.html(img.eq(c-1).clone());
	$prevS.find('img').hide();
}


$("#recomMain img:first").show();
//$prev.fadeOut();
	microPic(0);


function nextChange(){
//		$prev.show();
		if (a<=len) {
			img.eq(a).fadeOut("slow");
			img.eq(a+1).fadeIn("slow");
			a++;	
			microPic(a);
			if(a>len){
			img.eq(len).fadeOut("slow");
			img.eq(0).fadeIn("slow");			
			a=0;
			microPic(a);}
		}
		//alert(a);
		return false;
}

	
function PrevChange(){
		if (a>=0) {
			img.eq(a).fadeOut("slow");
			img.eq(a-1).fadeIn("slow");
			a--;
			microPic(a);
			if(a<0){
			img.eq(0).fadeOut("slow");
			img.eq(len).fadeIn("slow");
			a=len;
			microPic(a);}
		}
		//alert(a);
		return false;
	}

$next.hover(function() {
	$nextS.find('img').show();
	//clearInterval(autoRecomRun);
},function() {
	$nextS.find('img').hide();
	//autoRecomRun=setInterval(nextChange,5000);
});

$prev.hover(function() {
	$prevS.find('img').show();
	//clearInterval(autoRecomRun);
},function() {
	$prevS.find('img').hide();
	//autoRecomRun=setInterval(nextChange,5000);
});

$next.click(nextChange);
$prev.click(PrevChange);

//autoRecomRun=setInterval(nextChange,5000);


/*ul_scrollRecom*/
if($('#ul_scrollRecom li').length>4){
new Marquee("ul_scrollRecom",2,1,1002,120,20,0,0); 
}

$('#ul_scrollRecom li').hover(function () {
	var oLeft=parseInt($(this).offset().left)-7;
	//alert(oLeft);
	$(this).find('div').css({left:oLeft}).fadeIn();

},function () {
	$(this).find('div').fadeOut();
});



}



if ($('#historyBox').length) {
var galleryCont=$('#historyScrollBox');
var a_prev=$('#a_historyPrev');
var a_next=$('#a_historyNext');
//var imgBox=$('.eachBox');
var img=$('#historyScrollBox a');
var len=img.length-4;
var a=0;
var width=211;
var autoR;
var index;
function botAuto() {
	if (a==0) {a_prev.fadeOut();}else{a_prev.fadeIn()}
	if (a==len) {a_next.fadeOut();}else{a_next.fadeIn()}
}

botAuto();
a_prev.click(function () {
	if (a>0) {
		galleryCont.animate({marginLeft:'+='+width+'px'},1000);
		a--;
	}
	botAuto();
	return false;
});

a_next.click(function (){
	if (a<len) {
		galleryCont.animate({marginLeft:'-='+width+'px'},1000);
		a++;
	}
	botAuto();
	return false;
});

window.row=function(index) {
	img.eq(index).animate({marginTop:'-15px'},'fast',function () {
		$(this).find('div').fadeIn();
	});
}

img.hover(function () {
	index=img.index($(this));
	autoR=setTimeout("row("+index+")",200);
},function () {
	$(this).animate({marginTop:'0'},'fast',function () {
	$(this).find('div').fadeOut();
	});
	clearTimeout(autoR);
});

$('#historyScrollBox a:has(div)').click(function () {
	return false;
});

}

if ($('.historyDetails').length) {
	$('.historyDetails .a_back').click(function () {
		window.close();
		return false;
	});
}


if ($("#scrollContent").length) {
	$("#scrollContent").jScrollPane({scrollbarWidth:20});
}

//if ($(".vilMap").length) {
//	$('.vilMap a').lightBox();
//}

if ($('#specialGalleryBox').length) {

var ul=$("#ul_gallery");
var li=$("#ul_gallery li");
var img=$("#ul_gallery img");
var lastT=li.length-3;
//alert(lastT);
function resetLi() {
		li=$("#ul_gallery li");
		img=$("#ul_gallery img");
}

/*初始化*/
ul.find("li:gt("+lastT+")").prependTo(ul);
resetLi();
li.eq(0).css({left:"0px",display:"block"});
li.eq(1).css({left:"0px",display:"block"});
li.eq(2).css({top:"118px",left:"128px",width:"743px",height:"439px",display:"block",zIndex:"2"});
img.eq(2).css({width:"743px",height:"439px"});
li.eq(3).css({display:"block"});


/*向后*/
$("#span_next").click(function() {
		li.eq(3).css({zIndex:"2"}).animate({top:"118px",left:"128px",width:"743px",height:"439px"},800);
		img.eq(3).animate({width:"743px",height:"439px"},800);
		li.eq(4).fadeIn("slow");
		ul.find("li:first").appendTo(ul).css({top:"297px",left:"865px",display:"none"});
		li.eq(2).css({zIndex:"1"}).animate({top:"297px",left:"0",width:"137px",height:"81px"},800);
		img.eq(2).animate({width:"137px",height:"81px"},800);
		resetLi();
});

/*向前*/
$("#span_prev").click(function() {
		li.eq(1).css({zIndex:"2"}).animate({top:"118px",left:"128px",width:"743px",height:"439px"},800);
		img.eq(1).animate({width:"743px",height:"439px"},800);
		li.eq(3).fadeOut("slow");
		ul.find("li:last").prependTo(ul).css({top:"297px",left:"0",display:"block"});
		li.eq(2).css({zIndex:"1"}).animate({top:"297px",left:"865px",width:"137px",height:"81px"},800);
		img.eq(2).animate({width:"137px",height:"81px"},800);
		resetLi();
});

}


if ($('#ul_villagePic').length) {
	$('#ul_villagePic li').each(function (i) {
		$(this).show().addClass('villagePic_'+i+'');	
	})
}



if ($('.a_mailFriend').length) {
	$('.a_mailFriend').click(function () {
		$('#overMask').css({display:'block'});
		$('#overMask').animate({height:'376px'},function () {
			$('#mailtoFriend').fadeIn();
		});

		return false;
	});

	$('#isCancel').click(function () {
		$('#overMask').hide();
		$('#mailtoFriend').fadeOut('',function () {
			$('#overMask').css({height:'0px'});
		});
		
		return false;
	});


}







});
