//Modified Thumb-o-matic from Christian Heilmann

function shoPic()
{
	if(!document.getElementById || !document.createTextNode){return;}
	var offsetX=0;
	var offsetY=(navigator.userAgent.indexOf("Firefox")!=-1)?-108:0;
	var alternative='backtothepicture.com';
	var titleinfo='Click to hide';

	var dlinks=document.getElementsByTagName('a');

	this.createContainer=function(id)
	{
		var imageContainer=document.createElement('div');
		if(id){imageContainer.id=id;}
		document.body.appendChild(imageContainer);
		return imageContainer;
	}
	this.setPic=function(o,auto,ix,iy,closeMessage,alternative,id)
	{
		if(!imageContainer){imageContainer=document.getElementById(id);}
		var x=auto?getCoordinates(o,'x')+ix:ix;
		var y=auto?getCoordinates(o,'y')+iy:iy;
		var newimg=document.createElement('img');
		var newa=document.createElement('a');
		newimg.src=(o.href)?o.href:o;
		newimg.alt=o.alt?o.alt:alternative;
		newimg.border=0;
		newa.title=closeMessage;
		newa.href='#';
		newa.onclick=function()
		{
			imageContainer.removeChild(imageContainer.firstChild);
			if(/a/i.test(o.tagName))
			{
				o.focus();
			}
			return false;
		}
		newa.appendChild(newimg);
		if(imageContainer.childNodes.length>0)
		{
			imageContainer.removeChild(imageContainer.firstChild);
		}
		imageContainer.appendChild(newa);
		imageContainer.style.position='absolute';
		imageContainer.style.left=x+'px';
		imageContainer.style.top=y+'px';
		newa.focus();
		return false;			
	}
	// Blatantly borrowed from the DHTML and JavaScript Cookbook
	this.getCoordinates=function(offsetTrail,d) 
	{
	    var offsetLeft = 0;
	    var offsetTop = 0;
	    while (offsetTrail) 
		{
	        offsetLeft += offsetTrail.offsetLeft;
	        offsetTop += offsetTrail.offsetTop;
	        offsetTrail = offsetTrail.offsetParent;
	    }
	    if (navigator.userAgent.indexOf("Mac") != -1 && 
	        typeof document.body.leftMargin != "undefined") 
		{
	        offsetLeft += document.body.leftMargin;
	        offsetTop += document.body.topMargin;
	    }
		return (d=='x')?offsetLeft:offsetTop;
	}
	var imageContainer=createContainer(null);
	for(var i=0;i<dlinks.length;i++)
	{
		if(/sho_big/.test(dlinks[i].className))
		{
			dlinks[i].onclick=function()
			{
				return setPic(this,true,offsetX,offsetY,titleinfo,alternative);
			}
		}
	}
}
/*
The scanit function is adapted from Christian Heilmann's article for JIR, http://www.onlinetools.org/tools/firdom/.

The swapics funtion is adapted from Peter-Paul Koch's JIR http://www.quirksmode.org/dom/fir.html with addtions from Heilmann's script as well.

Credit and thanks to both for pointing me in the right direction.
*/

function scanit()
{
	if(document.getElementsByTagName && document.createElement)
	{
		for (var n=1; n<=6; n++)
		{
			var hds=document.getElementsByTagName('h'+n);
			swappics(hds,'h'+n);
		}
	}
}

function swappics(hds,tag)
{
	var path = '/assets/';
	var ext = '.gif';
	var pic = document.createElement('img');
	pic.id = 'newPic';
	for (var i=0; i<hds.length; i++)
	{
		if (hds[i].id)
		{
         var header = document.getElementsByTagName(tag)[i];
		 var pichere = pic.cloneNode(false);
         pichere.id = hds[i].id + 'newPic';
		 pichere.src = path + hds[i].id + ext;
		 pichere.alt = hds[i].firstChild.nodeValue;
		 header.replaceChild(pichere,header.firstChild);
		}
   }
}

function mdwong_pop(path,pop_name,options)
{
	if(!options)
	{
		options="width=796,height=484,location=yes,menubar=yes,toolbar=yes,scrollbars,resizable=yes,status=yes";
	}
	if(path)
	{
		if(!pop_name)
		{
			var n = path.split("/");
			var temp = n[n.length-1];
			n = temp.split(".");
			pop_name = n[0];
		}
		mdwong_popwin = window.open(path,pop_name,options);
		if (window.focus){mdwong_popwin.focus();}
	}
}

window.onload=function(){
	scanit();
	shoPic();
	// add more!
}
