// 2010/12/09 updated by xiaojun wu
// mouseover and mouseout event added

var timer = null;

var offset = 5000;

var index = 0;



//slide show image

function slideImage(i){

    var id = 'image_'+ target[i];

    $('#'+ id)

        .animate({opacity: 1}, 400).show()

        .siblings(':visible')

        .animate({opacity: 0}, 400).hide();                 

}



//bind thumb a

function hookThumb(){    

    $('#thumbs li img')

        .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;

        });

}


//onmouseover slideshow pause

function mouseover(){    

    $('#homeads img')

        .bind('mouseover', function(){

            clearTimeout(timer);           

            return false;

        });

}


//onmouseout slideshow go on

function mouseout(){    

    $('#homeads img')

        .bind('mouseout', function(){

            timer = window.setTimeout(auto, offset);  

            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];

    $('#thumbs li img.current').removeClass('current');

    $('#'+ id).addClass('current');

}

function auto(){

//quantity of images

 if (index > (adnum-1)){

        index = 0;

    }

    rechange(index);

    slideImage(index);

    

    timer = window.setTimeout(auto, offset);

    index++;                        

    

    }

$(function(){    

    //change opacity

    $('div.image').css({opacity: 0.85});

    auto();  

    hookThumb();

    mouseover();

    mouseout();
       
});
