var timer = null;
var offset =7000;
var index = 0;

//´óÍ¼½»ÌæÂÖ»»
function slideImage(i){
    var id = 'banner'+ 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(){    
    $('#btnBar a').bind('mouseover', 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;
        });
}
//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 = 'banBtn'+ target[loop];
    $('#btnBar a.selected').removeClass('selected');
    $('#'+ id).addClass('selected');
}
function auto(){
    index++;
    if (index >2){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
$(function(){
    //change opacity
    $('div.word').css({opacity: 0.85});
	window.setTimeout(auto, offset);  
    hookThumb(); 
    //hookBtn();
    
});
