$(document).ready(function() {
	var defaults = { monthsShort: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"],
					 days: ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота", "воскресенье"]}
	var thisDayIs = new Date;
	
	var startThisBorder = new Date();
	startThisBorder.setDate(1);
	var thisName = $('#columnmain h5:first a').attr('name');
	if (thisName.length == 5) {
		startThisBorder.setMonth(in_array(thisName.substring(2), defaults.monthsShort));
	}
	else {
		startThisBorder.setMonth(in_array(thisName.substring(1), defaults.monthsShort));
	}

	endThisBorder = new Date();
	endThisBorder.setDate(1);
	thisName = $('#columnmain h5:last a').attr('name');
	if (thisName.length == 5) {
		endThisBorder.setMonth(in_array(thisName.substring(2), defaults.monthsShort));
	}
	else {
		endThisBorder.setMonth(in_array(thisName.substring(1), defaults.monthsShort));
	}
	
	if (endThisBorder.getMonth() < startThisBorder.getMonth()) {
		endThisBorder.setFullYear(endThisBorder.getFullYear()+1);
	}
	
	$('#columnmain h5 a').each( function() {
		var thisDate = new Date();
		thisName = $(this).attr('name');
		thisDate.setDate(1);
		
		if (thisName.length == 5) {
			thisDate.setDate(thisName.substring(0,2));
			thisDate.setMonth(in_array(thisName.substring(2), defaults.monthsShort));
		}
		else {
			thisDate.setDate(thisName.substring(0,1));
			thisDate.setMonth(in_array(thisName.substring(1), defaults.monthsShort));
		}
		if (thisDate.getMonth() < startThisBorder.getMonth()) {
			thisDate.setFullYear(thisDate.getFullYear()+1);
		}

		$(this).text($(this).text() + ' / ' + defaults.days[thisDate.getDay()]);		
		
		if ( ( (thisDate.getDate() < thisDayIs.getDate()) && (thisDate.getMonth() == thisDayIs.getMonth()) && (thisDate.getFullYear() == thisDayIs.getFullYear())) || 
			 ( (thisDate.getMonth() < thisDayIs.getMonth()) && (thisDate.getFullYear() == thisDayIs.getFullYear()) ) ||
			 (thisDate.getFullYear() < thisDayIs.getFullYear()) ) {
			$(this.parentNode).hide();
			var remove = 1;
			var element = this.parentNode;
			while (remove) {
				remove = hideEvent (element);
				element = $(element).next('.event');
			}
		}
		else {;}
		
	});
});


function hideEvent (element) {
	if ($(element).next('.event').length) {
		$(element).next('.event').hide();
		return (1);
	}
	else {	return (0);}
}