dojo.provide("custom.Archive");

function buildMenu()
{	
	var oldYear = '0000';
	var titlePanes = new Array(10);
	var counter = 0;
	var contents = new Array(10);
	
	
	// because of Google Chrome bug the content of a TitlePane 
	// can be set only via constructor so therefore two loops
	
	for (var i=0; i<dates.length; i++)
	{
		if (dates[i].substr(0, 4) != oldYear)
		{
			counter++;
			contents[counter] = '<a href="/'+controllerName+'/'+actionName+'/year/'+dates[i].substr(0, 4)+'">Wszystkie</a><br/>';
			oldYear = dates[i].substr(0, 4);
		}
		contents[counter]+='<a href="/'+controllerName+'/'+actionName+'/year/'+dates[i].substr(0, 4)+'/month/'+dates[i].substr(5, 2)+'">'+months[dates[i].substr(5, 2)]+'</a><br/>';
	}
	
	oldYear = '0000';
	counter = 0;
	
	for (var i=0; i<dates.length; i++)
	{
		if (dates[i].substr(0, 4) != oldYear)
		{
			counter++;
			titlePanes[counter] = new dijit.TitlePane({
				title: dates[i].substr(0, 4),
				content: contents[counter]
			});
			oldYear = dates[i].substr(0, 4);
			if (curYear == oldYear)
			{
				titlePanes[counter].attr('open', true);
			}
			else
			{
				titlePanes[counter].attr('open', false);
			}
		}
	}
	
	var theMenuTable = document.createElement('table');
	var theRow = theMenuTable.insertRow(0);
	counter = 0;
	for (var j=1; j<titlePanes.length; j++)
	{
		if (titlePanes[j] instanceof dijit.TitlePane)
		{
			var theCell = theRow.insertCell(counter);
			theCell.style.verticalAlign = "top";
			theCell.style.width = "90px";
			theCell.appendChild(titlePanes[j].domNode);
			counter++;
		}
	}
	dojo.byId('menuContainer').appendChild(theMenuTable);
}