var timerSlide = null;
var offsetSlide = 5000;
var indexSlide = 0;

//´óÍ¼½»ÌæÂÖ»»
function slideImage(i){
    var id = 'image_'+ target[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 thumb a
function hookThumb(){    
    $('#thumbs li a')
        .bind('click', function(){
            if (timerSlide) {
                clearTimeout(timerSlide);
            }                
            var id = this.id;            
            indexSlide = getindexSlide(id.substr(6));
            rechange(indexSlide);
            slideImage(indexSlide); 
            timerSlide = window.setTimeout(autoSlide, offsetSlide);  
            this.blur();            
            return false;
        });
}
//bind next/prev img
function hookBtn(){
    $('#thumbs li img').filter('#play_prev,#play_next')
        .bind('click', function(){
            if (timerSlide){
                clearTimeout(timerSlide);
            }
            var id = this.id;
            if (id == 'play_prev') {
                indexSlide--;
                if (indexSlide < 0) indexSlide = 4;
            }else{
                indexSlide++;
                if (indexSlide > 4) indexSlide = 0;
            }
            rechange(indexSlide);
            slideImage(indexSlide);
            timerSlide = window.setTimeout(autoSlide, offsetSlide);
        });
}
//get indexSlide
function getindexSlide(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 autoSlide(){
    indexSlide++;
    if (indexSlide > 4){
        indexSlide = 0;
    }
    rechange(indexSlide);
    slideImage(indexSlide);
    timerSlide = window.setTimeout(autoSlide, offsetSlide);
}