/***************************************************************\
/***************************************************************\
/**															  **\
/**   IFCSSshadow.js					                      **\
/**															  **\
/**	  This module provides the ability to add css based       **\
/**   shadows to your document.          					  **\
/**															  **\
/**	  Just place your text inside a span element and the      **\
/**   script will find it and do the rest.                    **\
/**															  **\
/**   To add a shadow to your text, add the "shadow"          **\
/**   attribute to the span element.                          **\
/**   e.g shadow="1px 0px #F8F6F6" where 1px is the x offset, **\
/**   0px is the y offset and #F8F6F6 is the color of the     **\
/**   shadow.                                                 **\
/**															  **\
/**	   Author: Frank Pérez									  **\
/**	   Date: June 4, 2008									  **\
/**															  **\
/***************************************************************\
/***************************************************************/

try{
	
	//set up our namespace & catch any errors with this process
	var IFCSSshadow;
	
	if(!IFCSSshadow) IFCSSshadow = {};
	else if(typeof IFCSSshadow != "object")
		throw new Error();
				
} catch(e){	
	//do nothing	
}

IFCSSshadow.add = function(element, shadow)
{
	if (typeof element == "string")
		element = document.getElementById(element);
		
	shadow = shadow.replace(/^\s+/, "").replace(/\s+$/, "");
	var args = shadow.split(/\s+/);
	
	var textNode = element.firstChild;
	
	var shadowX = args[0];
	var shadowY = args[1];
	var shadowColor = args[2];
	
	var shadow = document.createElement("span");
	shadow.style.position = "absolute";
	shadow.style.left = shadowX;
	shadow.style.top = shadowX;
	shadow.style.color = shadowColor;
						
	shadow.appendChild(textNode.cloneNode(false));
	element.appendChild(shadow);	
	
	var text = document.createElement("span");
	text.style.position = "relative";
	text.appendChild(textNode);
	element.appendChild(text);
};

IFCSSshadow.addAll = function(root, tagname)
{   
    var elements = document.getElementsByTagName('span');
	
	for(var i = 0; i < elements.length; i++)
	{		
		var shadow = elements[i].getAttribute("shadow");
		if(shadow) IFCSSshadow.add(elements[i], shadow);
	}
};

if(window.addEventListener)
	window.addEventListener("load", IFCSSshadow.addAll, false);
else if (window.attachEvent) window.attachEvent("onload", IFCSSshadow.addAll);
else window.onload = IFCSSshadow.addAll;
