var timer = null;
var offset = 3000;
var index = 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: 'show'},'fast',function(){
            $(this).parent().animate({opacity: 100}, 800).hide();
        });
}

//bind thumb a
function hookThumb(){    
    $('#thumbs li 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('mouseover', 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 = 'thumb_'+ target[loop];
	
    $('#thumbs li a.current').removeClass('current');
    
	$('#'+ id).addClass('current');
}
function auto(){
    index++;
    if (index > 1){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
$(function(){    
    //change opacity
    $('div.word').css({opacity: 0.85});
    auto();  
    hookThumb(); 
   // hookBtn();
    
});











var notice_timer = null;
var notice_offset = 2000;
var noticeindex = 0;

function notice_slideImage(notice_i){
var id = 'notice_image_'+ notice_target[notice_i];
 $('#'+ id)
    .animate({opacity: 1}, 800, function(){
            $(this).find('.notice_word').animate({height: 'show'}, 'slow');
        }).show()
        .siblings(':visible')
        .find('.notice_word').animate({height: 'show'},'fast',function(){
            $(this).parent().animate({opacity: 100}, 800).hide();
        });
}

//bind thumb a
function noticeThumb(){    
    $('#notice_thumbs li a')
        .bind('mouseover', function (){
            if (notice_timer) 
			{
                clearTimeout(notice_timer);
            }      
            var id = this.id;            
            noticeindex = notice_getIndex(id.substr(13));
            notice_rechange(noticeindex);
            notice_slideImage(noticeindex);
            notice_timer = window.setTimeout(notice_auto, notice_offset);  
            this.blur();            
            return false;
        });
}
//get index
function notice_getIndex(notice_v){
    for(var notice_i=0; notice_i < notice_target.length; notice_i++){
        if (notice_target[notice_i] == notice_v) return notice_i;
    }

}
function notice_rechange(noticeloop)
{
    var id = 'notice_thumb_'+ notice_target[noticeloop];
	
    $('#notice_thumbs li a.current').removeClass('current');
    
	$('#'+ id).addClass('current');
}
function notice_auto(){
    noticeindex++;
    if (noticeindex > 1)
	{
        noticeindex = 0;
    }
    notice_rechange(noticeindex);
    notice_slideImage(noticeindex);
    notice_timer = window.setTimeout(notice_auto, notice_offset);
}
$(function(){    
    //change opacity
    $('div.notice_word').css({opacity: 0.85});
    notice_auto();  
    noticeThumb(); 
   // hookBtn();
    
});
