function slideSwitch() {
    var $active = $('#slideshow DIV.active');
    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    
    //tab
    $('#slidetab li').attr("class","");
    //get next_num
    next_num=getStrNum($next.attr("id"));

    $('li[id=lisort_'+next_num+']').attr("class","Mark");
    //description
    $('div[id*=descsort]').attr("class","last-active");
    $('div[id=descsort_'+next_num+']').attr("class","active");
}

function selectSlider(num){
	//pic
	var $active = $('#slideshow DIV.active');
	if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
	
    $active.addClass('last-active');
    var $current = $('div[id=divsort_'+num+']');
    $current.css({opacity: 0.0})
    .addClass('active')
    .animate({opacity: 1.0}, 100, function() {
       $active.removeClass('active last-active');
    });
    
    //tab
    $('#slidetab li').attr("class","");
    $('li[id=lisort_'+num+']').attr("class","Mark");
    //description
    $('div[id*=descsort]').attr("class","last-active");
    $('div[id=descsort_'+num+']').attr("class","active");
}

$(function() {
    var sliderInterval=setInterval( "slideSwitch()", 5000 );
    
    $('#slidetab li').click(function(){
    	clearInterval(sliderInterval);
    	sliderInterval=setInterval( "slideSwitch()", 5000 );
    	var num=getStrNum($(this).attr("id"));
    	var active=getStrNum($('#slideshow DIV.active').attr("id"));
    	if(active!=num){
    		selectSlider(num);
    	}
    }); 
});
/**
 *从字符串（结构为string_num，如：id_3）获取数字
 */
function getStrNum(str){
	if(str=='')return ;
	var arr=str.split("_");
	return arr[1];
}
