/* - - - - - - - - - - - - - - - - - - - - -
Title : Everyday Action switcher
Description: uses todays date to switch the 'today's action' links.

Created : 26/09/06
- - - - - - - - - - - - - - - - - - - - - */
var current_date = new Date();
var today = current_date.getDate();
var tomorrow = today + 1;
var yesterday = today - 1;

/* for all pages except index.html */
function todaysAction() {
	if (!document.getElementById || !document.getElementById("todaysAction")) return false;
	var link = document.getElementById("todaysAction");
	link.setAttribute("href", "actions/" + today + ".html");
}

/* for index.html */
function todaysActionHome() {
	if (!document.getElementById || !document.getElementById("todaysActionHome") || !document.getElementById("tomorrowsAction") || !document.getElementById("yesterdaysAction")) return false;
	
	var todayLink = document.getElementById("todaysActionHome");
	var tomorrowLink = document.getElementById("tomorrowsAction");
	var yesterdayLink = document.getElementById("yesterdaysAction");
	
	/* change the link values for tomorrow, yesterday, today links */
	tomorrowLink.setAttribute("href", "actions/" + tomorrow + ".html");
	yesterdayLink.setAttribute("href", "actions/" + yesterday + ".html");
	todayLink.setAttribute("href", "actions/" + today + ".html");

	/* create an img, set the src and alt values, replace the placeholder text link for today's action */
	var replaceImage = document.createElement('img');
	replaceImage.setAttribute("src", "img/actions/index"+ today +".png");
	todayLink.replaceChild(replaceImage, todayLink.firstChild);
	replaceImage.setAttribute("alt", "today's action");
	replaceImage.onload = function() {
		replaceImage.setAttribute("width", replaceImage.width);
		replaceImage.setAttribute("height", replaceImage.height);
	}
}

/* - - - - - - - - - - - - - - - - - - - - -
Title : External Links
Description: uses rel="external" instead of rel="external"
to open in new windows (to pass XHTML strict validation)

address: http://www.sitepoint.com/article/standards-compliant-world/

Created : 06/10/06
- - - - - - - - - - - - - - - - - - - - - */
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
	   	anchor.target = "_blank";
   }
 }
}
addLoadEvent(todaysAction);
addLoadEvent(todaysActionHome);
addLoadEvent(externalLinks);

