﻿//**幻灯片js**//

var timer;
var currentpoint;
currentpoint = 0;
var playId;
centertu = 1;
var MaxPoint = 4;
var imgArr = [];
var isUp=true;


 imgArr[0]=[];
 imgArr[1]=[];
 imgArr[2]=[];
 imgArr[3]=[];
 imgArr[0][0]="imgbyq/banner1.jpg";
 imgArr[1][0]="imgbyq/banner2.jpg";
 imgArr[2][0]="imgbyq/banner3.jpg";
 imgArr[3][0]="imgbyq/banner4.jpg";





function setTimeer() {
    clearTimer();
    TimerdoClick('tbnav', 'tbsub', MaxPoint, currentpoint);
    //alert(currentpoint);

    timer = setInterval("loadImage(setTimeer)", 5000);
}

function loadImage(callback) {
	
	

if (currentpoint >= MaxPoint) currentpoint = 0;
    callback.call(); //将回调函数的this替换为Image对象

}

function clearTimer() {
    clearInterval(timer);
}



//show
function curShowImg(e){
	 clearTimer();

    var curLeft=-currentpoint *960;
    
    //$(".big_banner_list").animate( { left:curLeft+"px"}, 700 );
     switchBanner(currentpoint);  
     timer = setInterval("loadImage(setTimeer)", 5000);
	
}


function TimerdoClick(navname, subname, idnum, o) {

    if (currentpoint >= MaxPoint) { currentpoint = 0; }
    if (currentpoint < 0) {currentpoint = MaxPoint - 1; }
	
	var curLeft=-currentpoint *960;
    
    switchBanner(currentpoint);
	curBtnDisplay();
	
	currentpoint++;
}


function switchBanner(id){
   playId=id;
   $(".big_banner_list").fadeOut(300,function(){
	   $(".big_banner_list").css("left",(-playId*960)+"px");
	   $(".big_banner_list").fadeIn(500);
   })
}

$(document).ready(function () {
    baneermain();
	
	
});

    function baneermain() {
		//底部5个区域的交互
		btmInteractive();
        MaxPoint = imgArr.length;
		
		//加载其他的大图
		bannerdisplay();
		
        loadImage(setTimeer);
		
		
		//按钮交互
		btnclickEvent();
		
		
    }
	
	function btmInteractive(){
	    $(".banner_adv").each(function(i){
			var curLeft=i*(173+18)+5;
			$(this).css("left",curLeft+"px");
			$(this).css("position","absolute");
			$(this).css("top","0px");
		});
		$(".banner_adv").mouseenter(function(){
	
			//$(this).css("display","none");
			
			
			$(this).animate( { top: "-10px"}, 200 );
		})
		
		$(".banner_adv").mouseleave(function(){
	        
			$(this).animate( { top: "0px"}, 200 );
			//$(this).css("display","none");
			//$(this).animate( { top: "10px"}, 50 );
		})
			
	}
	
	

	
	function bannerdisplay(){
		var imghtml=$(".big_banner_list").html();
		for(var i=1;i<MaxPoint;i++){
			imghtml +="<div class='banner_img_box'><a href='"+imgArr[i][1]+"'><img src='"+imgArr[i][0]+"' /></a></div>";
		}
		
		$(".big_banner_list").html(imghtml);
	}
	
	function btnclickEvent(){
	$(".index_banner_btn_bg").click(function(){
		  var id=$(this).attr("rel");
		  
		  var e = document.getElementById('tbsub');
		  currentpoint=id-1;

		  curShowImg(e);

		  curBtnDisplay();
	});
	
	
}

//按钮显示当前的状态；
function curBtnDisplay(){

	 $(".index_banner_btn_bg").each(function(i){
			
			   if(i==currentpoint){
				   if ($.browser.version == "6.0"){
					   $(this).css("background","url(imgbyq/banrbg.png)" );
					   $(this).css("filter","none");
				   }else{
					   

				       if($(this).hasClass("nocur")){
					       $(this).removeClass("nocur");
				       }
				       if(!$(this).hasClass("cur")){
					       $(this).addClass("cur");
				       }
				   
				   }	
					
					
			   }else{
				   
				    if ($.browser.version == "6.0"){
					   $(this).css("background","url(imgbyq/banrbg.png)" );
					   $(this).css("filter","alpha(opacity=55)");
				   }else{

				  
				        if($(this).hasClass("cur")){
					        $(this).removeClass("cur");
				       }
				        if(!$(this).hasClass("nocur")){
					       $(this).addClass("nocur");
				       }
				   }

				  
			   }
			   
		 });

}
  
   


