var timer = null;
var offset = 5000;
var index = -1;
var onPage = 0;
var timerc = null;
var yeskss = true;

//´óÍ¼½»ÌæÂÖ»»
function slideImage(i){
	//alert(i);
	if( yeskss ){
		index_c_gopage(i);
	}
	$('#image_index_bannel')[0].filters[0].Apply();
	$('#image_index_bannel')[0].filters[0].Play(duration=2);
    $('#image_index_bannel').attr("src",$("#thumb_"+target[i]).attr("tsrc"));
    $('#image_index_bannel_link').attr("href",$("#thumb_"+target[i]).attr("thref"));
	$('.index_bannel_smaill_image2').attr("class","index_bannel_smaill_image1");
	$('#thumb_'+target[i]).attr("class","index_bannel_smaill_image2");
}
//bind thumb a
function hookThumb(i){
	index = i;
    if (index >= target.length || index<0){
        index = 0;
    }
            if (timer) {
                clearTimeout(timer);
            }
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();
}
//bind next/prev img
function hookBtn(){
    $('#thumbs li img').filter('#play_prev,#play_next')
        .bind('click', function(){
            if (timer){
                clearTimeout(timer);
            }
            var id = this.id;
            if (id == 'play_prev') {
                index--;
                if (index < 0) index = 6;
            }else{
                index++;
                if (index > 6) index = 0;
            }
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
        });
}
//get index
function getIndex(v){
    for(var i=0; i < target.length; i++){
        if (target[i] == v) return i;
    }
}
function rechange(loop){
    var id = 'thumb_'+ target[loop];
    $('#thumbs li a.current').removeClass('current');
    $('#'+ id).addClass('current');
}
function auto(){
    index++;
    if (index >= target.length){
        index = 0;
    }
	//alert(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
$(function(){    
    auto();
});


function index_c_next(){
	var tabLeft = parseInt( $("#index_c").css("left") );
	var tabWidth = $("#index_c").width();
	var page = Math.ceil( (tabWidth-20) / 615 );
	//alert(tabLeft);
	if( tabLeft > -(page-1)*615 ){
		$("#index_c").animate({ left:tabLeft-615+"px" }, 1000 );
	}else{
		$("#index_c").animate({ left:"0px" }, 1000 );
	}
	ic();
}

function index_c_prev(){
	var tabLeft = parseInt( $("#index_c").css("left") );
	var tabWidth = $("#index_c").width();
	var page = Math.ceil( (tabWidth-20) / 615 );
	if( tabLeft <= -615 ){
		$("#index_c").animate({ left:tabLeft+615+"px" }, 1000 );
	}else{
		$("#index_c").animate({ left:(-(page-1)*615)+"px" }, 1000 );
	}
	ic();
}

function index_c_gopage(i){
	
	var onPagei = Math.floor(i/5);
	if( onPage != onPagei ){
		onPage = onPagei;
		var tabLeft = parseInt( $("#index_c").css("left") );
		var tabWidth = $("#index_c").width();
		var page = Math.ceil( (tabWidth-20) / 615 );
		
		//alert(onPage);
		if( onPage >= page ){
			onPage = page-1;
		}
		if( onPage < 0 ){
			onPage = 0;
		}
		//alert(tabLeft);
		if( tabLeft >= -(page-1)*615 ){
			$("#index_c").animate({ left:-onPage*615+"px" }, 1000 );
		}else{
			$("#index_c").animate({ left:"0px" }, 1000 );
		}
	}
}

function ic(){
	yeskss = false;
	setTimeout("yeskss=true", 4000 );
}










