var timer = null;
var offset = 5000;
var index = 0;

//大图交替轮换
function slideImage(i){
    //var id = 'image_'+ target[i];
	var id = 'topSlider'+ i;
    $('#'+ id)
        .animate({opacity: 1}, 800, function(){
            $(this).find('.word').animate({height: 'show'}, 'slow');
        }).show()
        .siblings(':visible')
        .find('.word').animate({height: 'hide'},'fast',function(){
            $(this).parent().animate({opacity: 0}, 800).hide();
        });
}

//bind next/prev img
function hookBtn(){
    $('.thumbs 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 = 4;
            }else{
                index++;
                if (index > 4) index = 0;
            }
            //rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
        });
}
//get index
function getIndex(v){
    for(var i=0; i < i.length; i++){
		if (i == v) return i;
    }
}
function auto(){
    index++;
    if (index > 4){
        index = 0;
    }
    //rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
$(function(){    
    //change opacity
    $('div.html').css({opacity: 0.75});
    auto();  
    //hookThumb(); 
    hookBtn(); 
});
