﻿$().ready( function() {
	var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
		months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	$("div.news ul li p.date").each( function() {
		var $this = $(this),
			currentDateDisplay = $this.html(),
			currentDate = new Date(currentDateDisplay);
		if (isNaN(currentDate.getDate())) {
			$this.html( currentDateDisplay.split(" ").slice(0, 4).join(" ") );
		} else {
			$this.html( days[currentDate.getDay()] + ", " + currentDate.getDate() + " " + months[currentDate.getMonth()] + " " + currentDate.getFullYear() );
		}
	} );
	
	$("div.modContainer div.news ul li p").each(function() {
		var calcNoLines = function(el) {
			return Math.round(el[0].offsetHeight / parseInt(el.css("line-height")));
		}
		var $this = $(this);
		if (calcNoLines($this) > 3) {
			var html = $this.html(),
				htmlSplit;
			while (calcNoLines($this) > 3) {
				htmlSplit = html.split(" ");
				html = htmlSplit.slice(0, htmlSplit.length-1).join(" ");
				$this.html(html + "...");
			}
		}
	});
	
} );

