
var ah =  new Number( screen.availHeight );
var aw = new Number( screen.availWidth );

var artIndex = new Number ( 0 );

var allArtTitles = new Array("Coordinator's Corner - A Message from Fr. Scott [en]",
        'A Brief History of the Use of the Divine Mercy Devotion in the CTF/SOS DRS [en]',
        'Present Disaster Responses',
        'Appello CTF - Aprile 17 - Terremoto in Abruzzo [it]',
        'New Update - Earthquake in Abruzzo, Italy - The Role of the Camillians, CTF and SOS DRS [en]',
        'Nuovo Update - Terremoto in Abruzzo, Italia - Il Ruolo dei Camilliani, la CTF and SOS DRS [it]  ',
        'Nuevo Update - Terremoto en Abruzzo, Italia - La función que desempeña los Camillos, la CTF y SOS DRS [sp] ',
        'Nouveau Update - Tremblement de terre dans la région d’Abruzzo, Italie – Le rôle des Camilliens, CTF et SOS DRS [fr] ',
        'CTF Thailand - Myanmar Mission 5 [en]',
        'CTF Tailandia - Quinta Missione in Myanmar (Birmania) [it]',
        'Recent Disaster Responses',
        'CTF Thailand and CTF Indonesia – Myanmar Mission 2 – Part 1 [en] ',
        'CTF Kenya - Response to post-election violence [en]',
        'Looking Back and Looking Ahead',
        'Recent and Upcoming CTF/SOS DRS Activities [en]',
        'A Message to the Camillians and to Our Friends - News from CTF Central [en]',
        'Un Messaggio ai Camilliani e ai Nostri Amici - Notizie da CTF Central [it]',
        'Looking Back – Camillian Task Force – A Work in Progress 2 [en]',
        'Vivere il Quarto Voto - Rispondere ai Disastri Fa Parte della Storia Camilliana [it]',
        'Meet the CTF/SOS DRS',
        "Member Profile - in the Spotlight - D'Ann Fisher [en]",
        'St. Therese of Lisieux and St. Camillus de Lellis - The Patron Saints of CTF/SOS DRS [en]',
        'From the Board - Sherman Runions [en]');
var allArtUrls   = new Array('http://docs.google.com/Doc?id=dcfp5v5n_3f8ksgnd6&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_348ds99hfc7&hgd=1',
        'Section',
        'http://docs.google.com/Doc?id=dcfp5v5n_430hp7568d6&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_371f84q4sf5&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_370df897jcf&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_399ct32wvh3&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_382gpbn4kmv&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_378c73pnjz5&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_403hsgrnvfq&hgd=1',
        'Section',
        'http://docs.google.com/Doc?id=dcfp5v5n_26fnssgnr2&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_328hqg3t9hn&hgd=1',
        'Section',
        'http://docs.google.com/Doc?id=dcfp5v5n_0fp5fpbgm&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_344fc24brc2&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_38043s29qgh&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_2gjdkmwhs&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_372n8sfqsdz&hgd=1',
        'Section',
        'http://docs.google.com/Doc?id=dcfp5v5n_332fs9q45f8&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_333gssjkpdv&hgd=1',
        'http://docs.google.com/Doc?id=dcfp5v5n_334fxdrvxg7&hgd=1');
var artTitles =  allArtTitles;
var artUrls   = allArtUrls;
var firstCall = true;
function createToc ()
{
    removeEmptySections();
	var numItems = artTitles.length; 
	var tocDiv1 = document.getElementById('tocDiv1');
	var tocDiv2 = document.getElementById('tocDiv2');
	var tocDiv3 = document.getElementById('tocDiv3');
	 tocDiv1.innerHTML = ''; tocDiv2.innerHTML = ''; tocDiv3.innerHTML = '';
	//var tocCol1 = document.getElementById('tocCol1');
	//var tocCol2 = document.getElementById('tocCol2');
	//tocCol1.innerHTML='foo' + numItems;tocCol2.innerHTML='bar';
	var ul1  = document.createElement('ul');
	var ul2  = document.createElement('ul');
	var ul3  = document.createElement('ul');
	  ul1.className ="newsUl"; ul2.className ="newsUl"; ul3.className ="newsUl";
	 //ul1.style.listStyle='none'; ul2.style.listStyle='none'; ul3.style.listStyle='none';
	var currDiv = tocDiv1;
	var currUl = ul1;
	for( i = 0; i < numItems ; i++ )
	{
         var ctrl = document.createElement('li');
         ctrl.className='newsLi';
         if( artUrls[i] == 'Section' )
        {
            ctrl.innerHTML = stripLangCode(artTitles[i]);
            ctrl.className="newsSectionHeadline";
        }
        else
        {
            var link = document.createElement('a');
            link.className="newsHeadline";
            
            link.setAttribute('title',  stripLangCode(artTitles[i])  );
            
            link.setAttribute("href","javascript:setNewsIndex("+i+");");
            link.innerHTML= doDrs(stripLangCode(artTitles[i]))  ;
            //link.appendChild(document.createTextNode( stripLangCode(artTitles[i])));
            ctrl.appendChild(link);
        }
        
        if( i >  ( numItems * (2/3) ) )
            currUl = ul3;
        else if(  i >  ( numItems * (1/3) ) )
        currUl = ul2;	
        currUl.appendChild(ctrl);
        }
	 
	tocDiv1.appendChild(ul1);
	tocDiv2.appendChild(ul2);
	tocDiv3.appendChild(ul3);
        
 
	
}
function filterArtsLang(   lang )
{
    if(lang == 'all' || lang.length == 0 )
    {
        artTitles =  allArtTitles;
        artUrls   = allArtUrls;  
    }
    else
    {       
        artTitles = new Array();artUrls = new Array();
        for( i = 0; i < allArtTitles.length; i ++ )
        {
            if(  allArtTitles[i].indexOf('['+lang+']') > -1 || allArtUrls[i] == 'Section')
            {
                artTitles.push(allArtTitles[i]);artUrls.push(allArtUrls[i]);
            }
        }
    } 
    createToc ();
    window.location.hash='thisIssue';
     
}
function removeEmptySections()
{
    var prevUrl = 'blah';
    var tempUrls = new Array();var tempTitles = new Array();
    for( i = 0; i < artTitles.length; i ++ )
    {
        var nextDex = new Number( i + 1 );
        var onLast = false;
        if( nextDex >=  artTitles.length   )
            onLast = true;
        if( !onLast )
        {
            if(  ( artUrls[i] == 'Section' && artUrls[nextDex] != 'Section') || artUrls[i] != 'Section' )
            {
                tempTitles.push(artTitles[i]);tempUrls.push(artUrls[i]); 
            }
        }
        else
        {
             if( artUrls[i] != 'Section' )
                  tempTitles.push(artTitles[i]);tempUrls.push(artUrls[i]); 
        }          
    }
    artTitles = tempTitles;   artUrls = tempUrls;  
}

function stripLangCode( s )
{     //  s = handleAccented( s ) ;
        var i = s.lastIndexOf('[');
        if( i > -1 ) return s.substr( 0, i );
        else return s;
}
function handleAccented( s ) 
{
        if( s.indexOf('ñ') > -1 )
                s = s.replace(/ñ/g,'&ntilde');
        return s;
}

function doDrs ( s )
{
        if( s.indexOf( 'SOS DRS' ) > -1 )
        {
            return s.replace(/SOS DRS/g,'SOS D<span style="font-size: 70%;">RS</span>');    
        }
        else return s;
}

function setNewsIndex( dex ) 
{
    artIndex = getValidDex( dex )
    var nf = document.getElementById( 'newsFrame' );
    nf.src=artUrls[artIndex] ;  
    if( new Number ( nf.height ) <  new Number (   ah*.5   ) ) nf.height = new Number (  ah*.5 ); 
    document.getElementById('currStory').innerHTML = " - " + doDrs(stripLangCode(artTitles[artIndex]));
    
    document.getElementById('next').title= "Next Story: " + stripLangCode(artTitles[getNextNewsItem(artIndex)]);
    
    document.getElementById('prev').title= "Previous Story: " + stripLangCode(artTitles[getPrevNewsItem(artIndex)]);
    document.getElementById('pArr').title= document.getElementById('prev').title;
    document.getElementById('nArr').title = document.getElementById('next').title;
    if( firstCall == true ) firstCall = false;
        else
    window.location.hash='newsP';
}
// accounts for rollover
function getValidDex( candidate )
{
	var td = new Number( candidate );
	if( td >=  (  artUrls.length  )  ) td = 0;
	        else if( td < 0 ) td = artUrls.length - 1; 
	return td;
}
function getNextNewsItem( current )
{
    var nextDex = getValidDex( current + 1) ;
    if( artUrls[nextDex] != 'Section' ) return nextDex;
    else
    {
        for(   i = 0; i < artTitles.length; i ++ )
        {
            nextDex = getValidDex( nextDex + 1) ;
            if( artUrls[nextDex] != 'Section' ) break;
        }
    }
    return nextDex;
}
function getPrevNewsItem( current )
{
    var nextDex = getValidDex( current - 1) ;
    if( artUrls[nextDex] != 'Section' ) return nextDex;
    else
    {
        for(   i = artTitles.length - 1; i >= 0; i -- )
        {
            nextDex = getValidDex( nextDex - 1) ;
            if( artUrls[nextDex] != 'Section' ) break;
        }
    }
    return nextDex;
}
function nextNews()
{
    var next = getNextNewsItem( artIndex );
     setNewsIndex( next );
     /*   if( artUrls[artIndex + 1 ] == 'Section' )
                setNewsIndex( artIndex + 2 ); 
        else
                setNewsIndex( artIndex + 1 ); */
}
function prevNews()
{
           var next = getPrevNewsItem( artIndex );
     setNewsIndex( next );
}
function sizeNewsFrame( h ){ document.getElementById( 'newsFrame' ).height = h;
}
function growNewsFrame()
{
	var nf = document.getElementById( 'newsFrame' );
	var o = new Number ( nf.height ) + ( ah * .20 ); 
	sizeNewsFrame( o );
}
function sepWindow()
{
	window.open( artUrls[artIndex], 'wow' );	
}

 

 


  

























