var timera = null;
var offseta = 5000;
var indexa = 0;

function slideImage2(i){
    var id = 'image_2'+ targetx[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 hookThumba(){    
    $('#thumbs2 li.slideshowItem a')
        .bind('click', function(){
            if (timera) {
                clearTimeout(timera);
            }                
            var id = this.id;            
            indexa = getindexa(id.substr(7));
            rechangea(indexa);
            slideImage2(indexa); 
            timera = window.setTimeout(autoa, offseta);  
            this.blur();            
            return false;
        });
}
//bind next/prev img
function hookBtn(){
    $('#thumbs2 li img').filter('#play_prev,#play_next')
        .bind('click', function(){
            if (timera){
                clearTimeout(timera);
            }
            var id = this.id;
            if (id == 'play_prev') {
                indexa--;
                if (indexa < 0) indexa = 3;
            }else{
                indexa++;
                if (indexa > 3) indexa = 0;
            }
            rechangea(indexa);
            slideImage2(indexa);
            timera = window.setTimeout(autoa, offseta);
        });
}
//get indexa
function getindexa(v){
    for(var i=0; i < targetx.length; i++){
        if (targetx[i] == v) return i;
    }
}
function rechangea(loop){
    var id = 'thumba_'+ targetx[loop];
    $('#thumbs2 li a.current').removeClass('current');
    $('#'+ id).addClass('current');
}
function autoa(){
    indexa++;
    if (indexa > 3){
        indexa = 0;
    }
    rechangea(indexa);
    slideImage2(indexa);
    timera = window.setTimeout(autoa, offseta);
}

