window.onload = init;
var lastClicked = { box : null, button : null };

function init()
{
	var o;
	var th_c = document.getElementById( "timeline" ).getElementsByTagName( "TH" );
	var td_c = document.getElementById( "timeline" ).getElementsByTagName( "TD" );
	for ( var i = 0; i < th_c.length; i++ ) 
	{
		if ( td_c[ i ].childNodes.length > 0 )
		{
			// Insert Button
			o = document.createElement( "DIV" );
			o.className = "monthButton";
			o.month = i;
			o.style.left = findPosX( th_c[ i ] ) + "px";
			document.getElementById( "timeline" ).appendChild( o );
			
			// Add mouseover code
			o.onmouseover = function()
			{
				var td_c  = document.getElementById( "timeline" ).getElementsByTagName( "TD" );
				if ( lastClicked.box )
				{
					lastClicked.box.style.display = "none";
					lastClicked.button.style.backgroundPosition = "0 0";
				}
				lastClicked.box = td_c[ this.month ];
				lastClicked.button = this;
				lastClicked.box.style.left = findPosX( this ) - 60 + "px";
				lastClicked.box.style.display = "block";
				lastClicked.button.style.backgroundPosition = "-20px 0";
			}
		}
	}
}

function findPosX( obj )
{
	var curleft = 0;
	if ( obj.offsetParent ) while ( obj.offsetParent ) { curleft += obj.offsetLeft; obj = obj.offsetParent; }
	else if ( obj.x ) curleft += obj.x;
	return curleft;
}

if ( navigator.platform == "Win32" && 
	 navigator.appName == "Microsoft Internet Explorer" && 
	 window.attachEvent ) 
{
	window.attachEvent( "onload", alphaBackgrounds);
}
function alphaBackgrounds()
{
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	for ( i=0; i<document.all.length; i++ )
	{
		var bg = document.all[i].currentStyle.backgroundImage;
		if (itsAllGood && bg)
		{
			if (bg.match(/\.png/i) != null)
			{
				var mypng = bg.substring(5,bg.length-2);
				document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
				document.all[i].style.backgroundImage = "url('/assets/images/x.gif')";
			}
		}
	}
}

