<!--

var _NH_slide_page = 0;     // current page number
var _NH_scroll_timer;
var _NH_scroll_timer_is_on=1;
var _NH_current_articleid = "";         // current article id to identify an object
var _NH_image_fade_timer;
var _NH_currentPhoto;       // current image id
var _NH_nextPhoto;           // next image id

function doScrolling( )
{
    if( _NH_scroll_timer_is_on)
    { 
        var toobj = null; 
        // just load the page,  item is on the first
        if( _NH_current_articleid == "" )
        {
            // scrolling to _NH_scroll_next
            var obj = document.getElementById("lnScrollable0");   // first ul
            toobj =  nh_firstChild(nh_firstChild(obj));
        } 
        else
        { 
            toobj = setNextScrolling(); 
        }

        if( toobj )
        {
            scroll_to(toobj);
        }
        clearTimeout(_NH_scroll_timer);
        _NH_scroll_timer = setTimeout("doScrolling()", 4000);
    } 
}

function setNextScrolling()
{
    var currentobj = document.getElementById("leadingnews_li_" + _NH_current_articleid);
    var nextobj = nh_nextSibling(currentobj);
    if(nextobj)
      {
            return nextobj;
      }
      else   // reach end of the list
      {
            if(++_NH_slide_page >=3)
                _NH_slide_page = 0;
            scroll_topage( _NH_slide_page, "lnScrollable", "lnNavi");
      }
      return null;
}

function scroll_to(thisobj)
{
   _NH_current_articleid = thisobj.id.substring(thisobj.id.length-12, thisobj.id.length);
   // highlight the title while clear all others 
   for( i=0; i< nh_childCount(thisobj.parentNode); i++)
        if( nh_ChildByIdx(thisobj.parentNode, i).className == "up" )
            nh_ChildByIdx(thisobj.parentNode, i).className = "";
   thisobj.className = "up";
   
   // update title display and link
   var obj1 = document.getElementById("leadingnews_title_link");
   var objA = nh_firstChild(thisobj)
   if( obj1 )
   {
        obj1.href= objA.href;
        obj1.innerHTML = objA.innerHTML;
   } 
      
   // update the image display
   _NH_nextPhoto = "leadingnews_img_"  + thisobj.id.substring(thisobj.id.length-12, thisobj.id.length);
   
   var imgObj = document.getElementById(_NH_nextPhoto);
    var parentObj = imgObj.parentNode;    //document.getelementById("leadlingnews_img_link");
    // update the image link 
    imgObj.parentNode.href=objA.href;
    image_cross_fade();
}

function scroll_selected(thisobj)
{
    // stop the scrolling
    _NH_scroll_timer_is_on=0;
    clearTimeout(_NH_scroll_timer);
    
    scroll_to(thisobj);
}

function scroll_deselected(thisobj)
{
    clearTimeout(_NH_scroll_timer);   // reset timer 
    // restart the scrolling
    if (!_NH_scroll_timer_is_on)
    {
        _NH_scroll_timer_is_on=1;
        _NH_scroll_timer = setTimeout("doScrolling()", 4000);
    }
}

function image_cross_fade()
{
   var nextPhoto = document.getElementById(_NH_nextPhoto); 
   var photoListObj = document.getElementById("leadlingnews_img_link");
   var temp;
   for ( var i=0; i < photoListObj.childNodes.length; i++ )
   {
        var childimg = photoListObj.childNodes[i];
        if( childimg.tagName == "IMG" )
        {
            if( _NH_nextPhoto != childimg.id )    // need to decrease the opacity
            {
                temp = 0; //childimg.style.opacity * 1.0 - 0.3;
                if (temp < 0.1)
                    temp = 0;
                childimg.style.opacity = temp;
                childimg.style.filter =  'alpha(opacity = ' + (temp * 100) + ')';
            }
        }
   } 
        var nextPhotoOpacity = 1; //nextPhoto.style.opacity * 1.0 + 0.3;
        if (nextPhotoOpacity >= 1.0)
            nextPhotoOpacity = 1;
        // Increase next photo's opacity
        nextPhoto.style.opacity = nextPhotoOpacity;
        nextPhoto.style.filter = 'alpha(opacity = ' + (nextPhotoOpacity*100) + ')';
      /*
        if(nextPhoto.style.opacity >= 1)
        {
            clearTimeout(_NH_image_fade_timer);
        }
        else
        {
            clearTimeout(_NH_image_fade_timer);
            _NH_image_fade_timer = setTimeout("image_cross_fade()", 100);
        }
        */
}

function scroll_topage( pageidx, listobjid, naviobjid )
{
   clearTimeout(_NH_scroll_timer);
   var toobj = nh_firstChild(nh_firstChild(document.getElementById(listobjid + pageidx)));
   slide_topage( pageidx, listobjid, naviobjid );
   scroll_to(toobj); 
   _NH_slide_page = pageidx;
   _NH_current_articleid = toobj.id.substring(toobj.id.length-12, toobj.id.length);
   _NH_scroll_timer = setTimeout("doScrolling()", 6000);
}

function scroll_topagenext( listobjid, naviobjid )
{
   clearTimeout(_NH_scroll_timer);
   var pageidx = slide_topagenext(listobjid, naviobjid);
   var toobj = nh_firstChild(nh_firstChild(document.getElementById(listobjid + pageidx)));
   scroll_to(toobj); 
   _NH_slide_page = pageidx;
   _NH_current_articleid = toobj.id.substring(toobj.id.length-12, toobj.id.length);
   _NH_scroll_timer = setTimeout("doScrolling()", 6000);
}

function scroll_topageprevious( listobjid, naviobjid )
{
   clearTimeout(_NH_scroll_timer);
   var pageidx = slide_topageprevious(listobjid, naviobjid);
   var toobj = nh_firstChild(nh_firstChild(document.getElementById(listobjid + pageidx)));
   scroll_to(toobj); 
   _NH_slide_page = pageidx;
   _NH_current_articleid = toobj.id.substring(toobj.id.length-12, toobj.id.length);
   _NH_scroll_timer = setTimeout("doScrolling()", 6000);
}

/********************************** shared by multiple section of the home page *********************************/

function slide_initpages(listobjid, naviobjid)
{
   var listobj = document.getElementById(listobjid);
   var naviobj = document.getElementById(naviobjid);
   var navcount = nh_childCount(naviobj);
   var listcount = nh_childCount(nh_lastChild(listobj));
   
   for( var i = 0; i < listcount; i++ )
   {
        nh_ChildByIdx(naviobj, i).style.display = "block";
   }
}

function slide_topage( pageidx, listobjid, naviobjid )
{
   var naviobj = document.getElementById(naviobjid);
   var navcount = nh_childCount(naviobj);
   for(var i = 0; i< navcount; i++ )
   {
        document.getElementById(naviobjid + i).style.backgroundPosition = "0px -8px";
        document.getElementById(listobjid + i).style.display = "none";
   }
    document.getElementById(naviobjid + pageidx).style.backgroundPosition = "0px 0px";
    document.getElementById(listobjid + pageidx).style.display = "block";
}

function slide_topagenext(listobjid, naviobjid)
{
   var naviobj = document.getElementById(naviobjid);
   var navcount = nh_childCount(naviobj);
   var nextp = 0;
   for(var i = 0; i< navcount; i++ )
   {
        if(document.getElementById(naviobjid + i).style.backgroundPosition == "0px 0px")
        {
            nextp = i;
            break;
        }
   }
   if( ++nextp >=3 )   nextp = 0;
   slide_topage(nextp, listobjid, naviobjid);
   return nextp;
}

function slide_topageprevious(listobjid, naviobjid)
{
   var naviobj = document.getElementById(naviobjid);
   var navcount = nh_childCount(naviobj);
   var nextp = 0;
   for(var i = 0; i< navcount; i++ )
   {
        if(document.getElementById(naviobjid + i).style.backgroundPosition == "0px 0px")
        {
            nextp = i;
            break;
        }
   }
   if( --nextp < 0 )   nextp = 2;
   slide_topage(nextp, listobjid, naviobjid);
   return nextp;
}

//-->

