/*
DYNAMIC SHADOWS by Andrea F.V. Di Marco aka Forrest2000

Some browser (ie. IE) hasn't got the method "getElementsByClassName"
so we got to provide it with a little trick (ok, no tricks, just some line of code)

Please do not customize _DynShadow class, add a different class instead.
The ID of your tag will be modifyed in ID_Normal for main Text and ID_Shadow for Shadows.

*/

var DynShadowColor = "#000";
var DynShadowPosH = 1;
var DynShadowPosW = 1;


// Let's provide IE "getElementsByClassName" function
function provideElementByClassName(){
	if (document.getElementsByClassName == undefined) {
		document.getElementsByClassName = function(className)
		{
			var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
			var allElements = document.getElementsByTagName("*");
			var results = [];
			var element;
			for (var i = 0; (element = allElements[i]) != null; i++) {
				var elementClass = element.className;
				if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
					results.push(element);
			}
			return results;
		}
	}
}

// Let's look in the dark...
function getShadows(){
	// Find all _DynShadow to be worked out
	var objToShadow = document.getElementsByClassName("_DynShadow");
	for(i=0; i < objToShadow.length; i++){
		// Get displayed size and move tags style to a display:block
		var offW = objToShadow[i].offsetWidth;
		var offH = objToShadow[i].offsetHeight;
		objToShadow[i].style.display = "block";
		objToShadow[i].style.width = offW+"px";
		objToShadow[i].style.height = offH+"px";
		// Create shadow Node and set its attributes
		var newShadowNode = objToShadow[i].cloneNode(true);
		newShadowNode.style.position = "absolute";
		newShadowNode.style.top = DynShadowPosH+"px";
		newShadowNode.style.left = DynShadowPosW+"px";
		newShadowNode.className = newShadowNode.className.replace("_DynShadow", "_Shadow");
		//newShadowNode.id += "_Shadow";
		// Create normal text Node and adjust attributes
		var newNormalNode = newShadowNode.cloneNode(true);
		newNormalNode.style.top = "0px";
		newNormalNode.style.left = "0px";
		newNormalNode.className =  newNormalNode.className.replace("_Shadow", "_Normal");
		//newNormalNode.id = newNormalNode.id.replace("_Shadow","_Normal");
		// Set the shadow color
		//newShadowNode.removeAttribute('style');
		newShadowNode.style.color = DynShadowColor;
		// Clear the object, set it relative and let's append the new two childs
		if (objToShadow[i].style.position == '') objToShadow[i].style.position = "relative";
		objToShadow[i].innerHTML = '';
		objToShadow[i].appendChild(newShadowNode);
		objToShadow[i].appendChild(newNormalNode);
	}
}

// Load Everything
onload=function(){
	provideElementByClassName();
	/* 
	You can load it here, if you haven't got any other "window.onload=..."
	otherwise you can call "getShadows()" at he end of you HTML code.
	*/
	getShadows();
}
