/* Rewrites date format string into multiple divs for styling */
function rewriteNewsLinks() {
	var news = document.getElementById('latest-news');
	if ( news != null ) {
	for ( var i = 0; i <= news.childNodes.length; i ++ ) {
		if ( news.childNodes[i] ) {
		if ( news.childNodes[i].className && news.childNodes[i].className.indexOf("news-item") != -1 ) {
			if ( news.childNodes[i].childNodes.length >= 1 ) {
			for ( var j = 0; j <= news.childNodes[i].childNodes.length; j ++ ) {
			if ( news.childNodes[i].childNodes[j] ) {
			var node = news.childNodes[i].childNodes[j];
			if ( node.className && node.className.indexOf("published-date") != -1 ) {
			var parts = node.innerHTML.split(' ');
			var day = parts[0];
			var month = parts[1];
			var year = parts[2];
			node.innerHTML = "";

			/* Day */
			var dayDiv = document.createElement('div');
			dayDiv.className = "day";
			dayDiv.innerHTML = day;
			node.appendChild(dayDiv);

			/* Month */
			var monthDiv = document.createElement('div');
			monthDiv.className = "month";
			monthDiv.innerHTML = getMonthString(month);
			node.appendChild(monthDiv);

			/* Year */
			var yearDiv = document.createElement('div');
			yearDiv.className = "year";
			yearDiv.innerHTML = getMonthString(year);
			node.appendChild(yearDiv);
			}
			}
			}
			}
		}
		}
	}
	}
}

/* Get month string from abbreviated version */
function getMonthString(abb) {

	if ( abb == "Jan" ) { return "January"; }
	if ( abb == "Feb" ) { return "February"; }
	if ( abb == "Mar" ) { return "March"; }
	if ( abb == "Apr" ) { return "April"; }
	if ( abb == "May" ) { return "May"; }
	if ( abb == "Jun" ) { return "June"; }
	if ( abb == "Jul" ) { return "July"; }
	if ( abb == "Aug" ) { return "August"; }
	if ( abb == "Sep" ) { return "September"; }
	if ( abb == "Oct" ) { return "October"; }
	if ( abb == "Nov" ) { return "November"; }
	if ( abb == "Dec" ) { return "December"; }

	// All else fails, return original string
	return abb;

}

/* Attach to onload event */
var oldonload = window.onload;
window.onload = function() {
	oldonload;
	rewriteNewsLinks();
}
