	// Preload image from the thumbnails
function preloadImages(){
	if(document.images){
		var thumbs = document.getElementById('thumbs').getElementsByTagName('img');
		
		// Check if its a content page or not
		if(thumbs.length > 0){		
			for (var i=0; i < thumbs.length; i++) {
				// is image already large on the page?
				var selected = thumbs[i].parentNode.parentNode.className == 'sel' ? true : false;
				
				// Load all the images into cache except current one
				if(!selected){
					var thumb_source = thumbs[i].src;
					// Create large image filename from the thumbs filename
					var large_source = thumb_source.replace('-thumb','');
					// Puts image object in cache
					var pic = new Image();
					pic.src = large_source;								
				}
			};			
		}
	}
};

// Write the email address out with JavaScript
function writeEmail(){
	var thispage = document.getElementById('contact_info');
	if(!thispage){return;}
	
	var details = thispage;
	
	// Yes I know it is quite verbose
	var para = document.createElement('p');
	para.id="email";
	var label = document.createElement('span');
	label.innerHTML = "Email<br />";
	para.appendChild(label);
	
	var name = "alex";
	var at = "@";
	var site = "alexmacnaughton";
	var com = ".com";
	var email = name+at+site+com;
	
	var link = document.createElement('a');
	link.href = "mailto:"+email;
	link.innerHTML = email;
	para.appendChild(link);
	
	var phone = document.getElementById('phone');
	details.insertBefore(para,phone);
};

// Slideshow
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;

function so_init() {
	if(!d.getElementById("slideshow")){return;}
	imgs = d.getElementById("slideshow").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++){
		imgs[i].style.display = 'none';
		imgs[i].xOpacity = 0;
	}		
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade,3000);
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,3000);
	} else {
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

// Remove Title attributes
function removeAttributes(node) {
	if (node.title) {node.title = "";}
	if (node.alt) {node.alt = "";}

	var children = node.childNodes;
	for(var i=0; i < children.length; i++) {
	  removeAttributes(children[i]);
	};
}

// DOM Loaded
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) clearInterval(_timer);
	
	preloadImages();
	writeEmail();
	removeAttributes(document.body);
};

/* for Mozilla/Opera9 and Safari */
if (document.addEventListener) {
	/* for Safari */
	if (/WebKit/i.test(navigator.userAgent)){
		var _timer = setInterval(function(){if(/loaded|complete/.test(document.readyState)){ init(); }}, 0);
		window.onload(init);
	} else {
		document.addEventListener("DOMContentLoaded", init, false);
	}
} else {
	document.write("<script id=__ie_onload defer src=//:><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			this.onreadystatechange = null;
			init(); // call the onload handler
		}
	};
}
