var years=[];
var yearHolder='';
var monthHolders='';
function entry(year,month,link)
{
	this.year=year;
	this.month=month;
	this.link=link;
}
function customCompare(a,b)
{
	return (b.year-a.year)
}
function showArchive(id,liRef)
{
mh=$('#'+id).clone();
$('#'+id).remove();
liRef.append(mh);
$('#'+id).slideToggle();
return;
liRef.parent().children('li').each(function(){
if($(this)!=liRef)
	$(this).css({'border-bottom':'1px solid #950707','color':'black','background-color':'transparent'});

});
	$('div[id^="monthholder"]').each(function(){
		if($(this).attr('id')!=id){
			$(this).slideUp();
			//liRef.css({'border-bottom':'1px solid #950707'});
			liRef.css({'border-bottom':'1px solid #950707','color':'black','background-color':'transparent'});
				//alert('aa');
			}
			
	});

	ref=$('#'+id);
	
	if(ref.is(':hidden')){
		liRef.css({'border-bottom':'none','color':'white','background-color':'#950707'});
}

	ref.slideToggle('slow',function(){
	if(ref.is(':hidden'))
		{
							
		 liRef.css({'border-bottom':'1px solid #950707','color':'black','background-color':'none'});
		}

});
}
$('document').ready(function(){
	//return;
	ref=$('#thearch');
	ref.children('li').each(function(){
	t=$(this).children().text().split(' ');
	link=$(this).children().attr('href');
	//if(years.indexOf(t[1])==-1)
	years.push(new entry(t[1],t[0],link));
	years.sort(customCompare);
	});
	cYear=0;
		y=1;
	for(var i in years)
	{
		if(cYear!=years[i].year){
			if(cYear!=0){
				monthHolders+='</ul><br  style="clear:both"/></div>';
			}

			monthHolders+='<div style="display:none;" id="monthholder-'+years[i].year+'"><ul>';
			cYear=years[i].year;
			yearHolder+='<li onclick="showArchive(\'monthholder-'+cYear+'\',$(this))" style="font-weight:bold;padding:1px;margin:2px;margin-bottom:-1px;cursor:pointer;">'+cYear+'</li>';
				
		}
			monthHolders+='<li style="float:left;padding:5px;width:80px;font-weight:normal;"><a style="color:black"  href="'+years[i].link+'">'+years[i].month+'</a></li>';			
		
			
	y++;
	}
ref.remove();
$('#arch').append('<ul style="margin-top:35px;" id="theYearHolders">'+yearHolder+'</ul><br style="clear:both" />'+monthHolders+'</ul><br style="clear:both"/></div>').children("#theYearHolders").children('li:first-child').click();
});

