function init_red_timer(cont){
        clearInterval(global[cont]['rotate_time']);
}

function home_lead_rotate_start( cont ){
 
    if(jQuery('#home_lead_rotate').length == 0) return false;
    $cont = $('#' + cont);
    data  = global[cont];
    /*********/
    global[cont].time_handler = setInterval( function(){
        _home_lead_rotate_interval(cont);
    }, data['rotate_time'] );
	init_red_timer( cont );
    return true;
}

function _home_lead_rotate_interval(cont){
    data  = global[cont];
    global[cont]['current_id']++;
    home_lead_rotate_go( global[cont]['current_id'] , cont );
	//init_red_timer(cont);
}

function home_lead_rotate_go( key , cont , is_pause , button ){
        home_lead_rotate_pause( cont );
        home_lead_rotate_start( cont );    
    $cont = $('#'+cont);
    data  = global[cont];
    /*********/
    if(key <= 0 ){
        key = global[cont]['max_count'];
    }
    if( key > global[cont]['max_count']){
        key = 1;
    }
    //$caller = $cont.find('ul#pageRotate li:eq('+(key-1)+')');
    global[cont]['current_id'] = key;   
    /**************/
        //console.log($cont);
        if( data['row'][key]['overlay'] == 'video_overlay')
            {
                 $cont.find('.quickArticles #overlay_image').addClass('video_overlay');
                 $cont.find('.quickArticles #overlay_image').attr('href',data['row'][key]['embed']);
            }else{
                $cont.find('.quickArticles #overlay_image').removeClass();
            }
        //$cont.find('.quickArticles img').hide();
        $cont.find('.quickArticles h1.title a.title').fadeOut(500,function(){$(this).html( data['row'][key]['title'] ).fadeIn(500)});
        $cont.find('.quickArticles h1 a.title').attr('href', data['row'][key]['link']) ;
        $cont.find('.newsFeed .brief').fadeOut(500,function(){$(this).html( data['row'][key]['brief'] ).fadeIn(500)});
        $cont.find('.newsFeed a.moreBtn').attr('href' ,  data['row'][key]['link'] );
        $cont.find('#pageRotate ul li a').removeClass('selected');
        $cont.find('#pageRotate ul li a:eq('+(key)+')').addClass('selected');
        $cont.find('.quickArticles img.active').fadeOut(500,function(){$cont.find('.quickArticles img.image_'+(key)+'').fadeIn(500)});
        $cont.find('.quickArticles img.active').removeClass('active');
        $cont.find('.quickArticles img.image_'+(key)+'').addClass('active');

       //$cont.find('.quickArticles img.image_'+(key)+'').show();
    return false;
}

function home_lead_rotate_pause( cont ){

        data  = global[cont];
        if( typeof global[cont].time_handler !='undefined' ){
            clearInterval( global[cont].time_handler );
        }
        if( typeof global[cont].red_timer_handler !='undefined' ){
            clearInterval( global[cont].red_timer_handler );
        }
    return false;
}

function home_lead_rotate_next(cont , button){

//    if( !button.hasClass('select') ){
//        home_lead_rotate_start( cont );
//    }
    home_lead_rotate_go( global[cont]['current_id'] + 1 , cont);
    return false;
}

function home_lead_rotate_back( cont , button){

//    if( !button.hasClass('select') ){
//        home_lead_rotate_start( cont );
//    }
    home_lead_rotate_go( global[cont]['current_id'] - 1 , cont);
    return false;
}


function leading_prev(){
if(allow_press){
  home_lead_rotate_back('home_lead_rotate',$('#lead_start_pause_button'));
  allow_press = false;
  setTimeout( "allow_press = true;", 2000);
}
return false;
}

function leading_next(){
if(allow_press){
  home_lead_rotate_next('home_lead_rotate',$('#lead_start_pause_button'));
  allow_press = false;
  setTimeout( "allow_press = true;", 2000);
}
return false;
}
