/* ***********************************************************************
 * Chris Slee - Home Page
 *
 * This javascript adds particular behaviour to modify the contents of the
 * page when possible in order to enhance the user experience for those
 * with capable browsers and degrade gracefully so as to remain usable for
 * other browsers such as text-only and handheld devices.
 *
 * formatDate(d) - makes pretty date strings
 * modFooter()   - adds the date of last modification to the footer.
 * modLinks()    - 
 * moveBkgrnd()  - 
 * initFunc()    - calls these functions when the page has finished 
 *                 loading.
 * ********************************************************************* */

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj.attachEvent( "on"+type, function() { obj["e"+type+fn](); } );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj["e"+type+fn] );
		obj["e"+type+fn] = null;
	}
}

// ***********************************************************************

function formatDate(d) {
	arDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
							 "Thursday", "Friday", "Saturday");
   arMonths = new Array("January", "February", "March",
								"April", "May", "June",
								"July", "August", "September",
								"October", "November", "December"); 
   theDate = new Date(d);
   year = theDate.getYear();
   if(year<1000) year+=1900
	formatDate = arDays[theDate.getDay()] + " ";
   formatDate += theDate.getDate() + " ";
   formatDate += arMonths[theDate.getMonth()] + " ";
   formatDate += year;
   return formatDate;
}

function modFooter() {
   if (document.getElementById && document.createTextNode) {
		var elEmail=document.getElementById("emailaddress");
      // elEmail.href="mailto:sleech@ozemail.com.au";
      elPara=elEmail.previousSibling;
      elPara.nodeValue=" and was last modified on ";
      elPara.nodeValue += formatDate(document.lastModified);
      elPara.nodeValue += ". ";
	}
}

function modLinks() {
	if (document.getElementsByTagName && document.createElement) {
		var links = document.getElementsByTagName('a');
		for (i=0; i<links.length; i++) {
			var currLink = links[i];
			var currAttrib=currLink.href; 
//			if (currAttrib.substring(0,4)=="http" && currAttrib.indexOf("chris_slee")<0) {     
			if (currAttrib.substring(0,4)=="http" && currAttrib.indexOf(document.domain)<0) {     
				var icon = document.createElement('img');
				icon.src="images/offsite.gif";
				icon.height=7;
				icon.width=15;
				icon.title="Offsite Link";
				currLink.parentNode.insertBefore(icon,currLink.nextSibling);
				currLink.title="Offsite Link";
			}
			if (currAttrib.substring(0,4)=="send") {
				var currHref= new String(currAttrib);
				var icon = document.createElement('img');
				icon.src="images/email.gif";
				icon.height=7;
				icon.width=15;
				icon.title="Email Address";
				currLink.parentNode.insertBefore(icon,currLink.nextSibling);
				currLink.title="Email Address";	
				currHref=currHref.replace(/^send/g,"mailto");
				currHref=currHref.replace(/\[Q\]/g,"@");
				currHref=currHref.replace(/\[X\]/g,".");
				currLink.href=currHref;
			}
		}
	}
}

function moveBkgrnd() {
	if (document.getElementById) {
		var objDiv  = document.getElementById('container');
		var objBody = objDiv.parentNode;
		var strPosition = (objDiv.offsetLeft-120) + "px 0px";
		objBody.style.backgroundPosition= strPosition;
	}
}

addEvent(window,"load",function(){modFooter();});
addEvent(window,"load",function(){modLinks();});
addEvent(window,"load",function(){moveBkgrnd();});
addEvent(window,"resize",function(){moveBkgrnd()});


