$(function() {
    
    // FIND ALL PAST DAYS FROM LIST OUTPUTTED BY PHP, APPLY CLASS TO THOSE DATES
    $("#hiddenpastdayslist p").each(function() {
    
        var pastDate = $(this).text();
    
        $("td[rel=" + pastDate + "]").addClass("past-day").wrapInner("<strike>");
        
    });

	$("#hiddenshowlist p").each(function() {
	
		var thisDate = $(this).text();
		var thisID = $(this).attr("rel");
		var thisAbout = $(this).attr("title");
		var color = $(this).attr("color");
		
		var timeString = $(this).attr("faketimeparam");
		timeString = $.trim(timeString);
		var hrefString = "/calendar/today/?time=" + timeString;
					
		if (color.length == 6) {
		  color = "#" + color;
		}
		
		$("table.calendar td").each(function() {
		
			if ( ($(this).attr("rel") == thisDate) && (true) ) {
									     
				 $(this).wrapInner("<a title='" + thisAbout + "' href='/show/?id=" + thisID + "' style='background: " + color + ";'></a>");
							
			} else if ($(this).attr("rel") == thisID) {
			     
			     $(this).wrapInner("<a title='" + thisAbout + "' href='" + hrefString +"' style='background: #f0f317; color: red;'></a>");
			
			} 
		
		});
	
	});
	
	$(".calendar a").tooltip({
		track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    fade: 250 
	})
	
	$(".calendar td:has(a)").css( "padding", 0 );
	
	$("#loading").hide();

});
