var timer = null;
var offset = 5000;
var index = 0;
var target = ["1","2","3","4","5","6"];
//´óÍ¼½»ÌæÂÖ»»
function slideImage(i){
    var id = 'fragment-'+ target[i];
    $('#'+ id)
        .animate({opacity: 1}, 800, function(){
            $(this).find('.img-tabs-info').animate({height: 'show'}, 'fast');
        }).show()
        .siblings(':visible')
        .find('.img-tabs-info').animate({height: 'hide'},'fast',function(){
            $(this).parent().animate({opacity: 0}, 800).hide();
        });
}
//bind thumb a
function hookThumb(){    
    $('.img-tabs-nav li a')
        .bind('click', function(){
            if (timer) {
                clearTimeout(timer);
            }                
            var id = this.id;            
            index = getIndex(id.substr(6));
            rechange(index);
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();            
            return false;
        });
}

//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];
    $('.img-tabs-nav-item').removeClass('img-tabs-selected');
    $('#'+id).parent().addClass('img-tabs-selected');
}
function auto(){
    index++;
    if (index > 5){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
$(function(){    
    //change opacity
    auto();  
    hookThumb();   
});
