$(document).ready(function(){
	removeTH();
});	

function removeTH() {
	$("#searchContent th").remove();
}

	var managementAttr = ".managementList ul li";
	var industrialAttr = ".productBlocks ul li";
	
	function GetHighestIndex(values)
	{
		var index = 0;
		var lastVal;
		
		for(var i=0; i < values.length; i++)
		{
			if(i == 0)
			{
				lastVal = values[0];
			}
			else
			{
				if(values[i] > lastVal)
				{
					lastVal = values[i];
				}
			}
		}
		
		return lastVal;
	}
	
	var heightFix = {
		Management: function() {
			$(managementAttr).each(function(e) {
				e = e + 1;
				var twoColumns = ((e % 2) == 0);
				
				if (twoColumns) 
				{
					if ($(managementAttr).eq(e - 2).height() < $(managementAttr).eq(e - 1).height()) 
					{
					    $(managementAttr).eq(e - 2).height(
						    $(managementAttr).eq(e - 1).height()
						);
					    $(managementAttr).eq(e - 1).height(
						    $(managementAttr).eq(e - 2).height()
						);
					} 
					else 
					{
					    $(managementAttr).eq(e - 1).height(
						    $(managementAttr).eq(e - 2).height()
						);
					    $(managementAttr).eq(e - 2).height(
						    $(managementAttr).eq(e - 1).height()
						);
					}
				}
			});
		},
		Industrial: function() {
			var size = $(industrialAttr).length;
			var amountOfThreeColumns = parseInt(size / 3);
			
			$(industrialAttr).each(function(e) {
				e = e + 1;
				var threeColumns = ((e % 3) == 0);
				var twoColumns = ((e % 2) == 0);
				var remainder = (((amountOfThreeColumns * 3) + 2) == size);
				
				if(threeColumns && amountOfThreeColumns > 0)
				{
					var itemArray = Array();
					itemArray[0] = $(industrialAttr).eq(e - 1).height();
					itemArray[1] = $(industrialAttr).eq(e - 2).height();
					itemArray[2] = $(industrialAttr).eq(e - 3).height();
					
					var setHeight = GetHighestIndex(itemArray);
					
					$(industrialAttr).eq(e - 1).height(setHeight);
					$(industrialAttr).eq(e - 2).height(setHeight);
					$(industrialAttr).eq(e - 3).height(setHeight);
					
					amountOfThreeColumns--;
				}
				
				if (amountOfThreeColumns <= 0 && remainder)
				{
					if($(industrialAttr).eq(size - 1).height() < $(industrialAttr).eq(size - 2).height())
					{
					    $(industrialAttr).eq(size - 1).height(
						    $(industrialAttr).eq(size - 2).height()
						);
					    $(industrialAttr).eq(size - 2).height(
						    $(industrialAttr).eq(size - 1).height()
						);
					}
					else
					{
					    $(industrialAttr).eq(size - 2).height(
						    $(industrialAttr).eq(size - 1).height()
						);
					    $(industrialAttr).eq(size - 1).height(
						    $(industrialAttr).eq(size - 2).height()
						);
					}
				}
			});
		}
	}

    function numberPadding(value) {
        var numPad = "0";
        
        if (value > 0 && value < 10) {
            value = numPad + value;
        }
        return value;
    }
    
    function AddNumbers() {
        $(".blockOne ol li").each(function(e) {
            var input = "<span class='numbers'>" +
                        numberPadding(e + 1) +
                        "</span>";
            var curInput = $(this).html();
            
            $(this).empty();
            $(this).append(input + " <p class='pContent'>" + curInput + "</p>");
        });
    }
    
    function AddRecipeNumbers() {    
        $(".recipeHomeRight ul li").each(function(e) {
            var input = "<span class='numbers'>" +
                        numberPadding(e + 1) +
                        "</span>";
            var curInput = $(this).html();
            
            $(this).empty();
            $(this).append(input + "<br />" + curInput);
        });
    }

	function FormattedDate()
	{
		var d_names = new Array("Sunday", "Monday", "Tuesday",
								"Wednesday", "Thursday", "Friday", 
								"Saturday");
		
		var m_names = new Array("January", "February", "March", 
								"April", "May", "June", "July", 
								"August", "September", "October", 
								"November", "December");
		
		var d = new Date();
		var curr_date = d.getDate();
		var sup = "";
		
		if (curr_date == 1 || curr_date == 21 || curr_date == 31)
		{
			sup = "st";
		}
		else if (curr_date == 2 || curr_date == 22)
		{
		   sup = "nd";
		}
		else if (curr_date == 3 || curr_date == 23)
		{
		   sup = "rd";
		}
		else
		{
			sup = "th";
		}
		
		var curr_month = d.getMonth();
		var curr_year = d.getFullYear();
		var curr_day = d.getDay();
		
		return d_names[curr_day] + " " + curr_date + sup + " " + m_names[curr_month] + " " + curr_year;
	}

	function TableFormat() {
	    var tableAttr = "div.blockOne table";
	    $(tableAttr + " thead tr th").addClass("tableHeader");
	    $(tableAttr + " thead tr th:last-child").addClass("tdLast");
	    $(tableAttr + " tbody tr:odd").children().addClass("tdOdd");
	    $(tableAttr + " tbody tr:even").children().addClass("tdEven");
	    $(tableAttr + " tbody tr td:last-child").addClass("tdLast");
	    //$(tableAttr + " tbody tr td").addClass("tdOdd");
	}

	$(document).ready(function() {
	    $("#dateDisplayContainer").show();
	    $("#dateDisplayContainer").append(FormattedDate());
	    $(".recipeHomeRight ul li:last-child").addClass("noPadding");

	    TableFormat();
	});