
/* Title:		archive_links.js
** Description:		For a nice and smooth display of links to the archives of http://woodrow.de.vu/
** Author:		Woodrow Shigeru (woodrow.shigeru@gmx.net)
** created:		2oo6-1o-o7
** modified:		2oo7-o3-21
*/

	 // global variables that contain rough dates of the very first and the very last blog psoting
	var FirstArch, LastArch;

 // instantiates the global variables and initiates the whole archive-link-fuss
function arch_init()
{
	FirstArch = "2005_10";  // assume the last psoting was made in this very month
	var jetzt = new Date(), Hilf = jetzt.getMonth() +1;
	Hilf = ( Hilf < 10 ) ? "0"+ Hilf : Hilf;  // make M double digit MM
	LastArch = jetzt.getFullYear() + "_" + Hilf;

	arch_table_init();
}

 // creates the archive-sections, one table and one year per section
function arch_table_init()
{
	 // for all the years between FirstArch and Last do
	var i=FirstArch.substr(0,4), LastY=LastArch.substr(0,4);
	while( i <= LastY )
	{  // create a section with a table of all months
	  document.write( "&nbsp;<a href='javascript:toggle_archsection(\"arch"+i+"\");' style='font-size:8pt;' target='_self'>"+i+"</a>" );
	  document.write( "<div id='arch"+i+"' class='archsection' style='display:none;'>" );
	  document.write( make_table(i) );
	  document.write( "</div><br>" );
	  i++;
	}
}

 // creates a single table
function make_table( year )
{
	 // theCode: code to be returned via document.write
	 // Content: content of a single cell
	var theCode='', Content='', x, y, month=1, Sp="&nbsp;&nbsp;";

	theCode = theCode+ "<br><table cols=4 cellpadding=0 cellspacing=0 border=0>";
	 // repeat for all table-rows
	for( y = 1; y <= 3; y++ )
	{
	  theCode = theCode+ "<tr>";
	   // repeat for all table-columns
	  for( x = 1; x <= 4; x++ )
	  {  // make M double digit MM
	    Content = ( month < 10 ) ? "0"+ month : month;
	    Content = // if the current cell is either before FirstArch or after LastArch
	      ( ( ( year == FirstArch.substr(0,4) ) && ( Content < FirstArch.substr(5) ) )
	     || ( ( year ==  LastArch.substr(0,4) ) && ( Content >  LastArch.substr(5) ) ) )
		// then create current cell as no link
	      ? "<td class='archcellno'>"+ Sp+ Content +Sp +"</td>"
		// else create current cell as a link
	      : "<td class='archcell'><a class='archa' target='_self' href='http://woodrowshigeru.blogspot.com/"+ year +"_"+ Content +"_01_archive.html'>"+ Sp+ Content +Sp +"</a></td>";
	    theCode = theCode+ Content;
	    month++;
	  }
	  theCode = theCode+ "</tr>";
	}
	theCode = theCode+ "</table>";

	return theCode;
}

 // toggles the visibility of the clicked archive-section
function toggle_archsection( myID )
{
	var Hilf = document.getElementById( myID ).style;
	var IsVisible = Hilf.display == '';
	 // collapse all only if this archive-section is not visible by now
	if( !IsVisible )
	  collapse_all_archsections();
	Hilf.display = ( IsVisible ) ? 'none' : '';
}

 // collapses all the archive-link-sections
function collapse_all_archsections()
{
	var i = 0, HilfsList = document.getElementsByTagName('div');

	 // for all <div>-tags of class 'archsection' do hide
	for( i = 0; i < HilfsList.length; i++ )
	  if( HilfsList[i].className == 'archsection' )
	    HilfsList[i].style.display = 'none';
}
