function layermonkey(element)
{
	var divs = element.getElementsByTagName('div') ;
	var image;
	
	// loop through all the divs in the element

	for(i=0; i<divs.length; i++)
	{
		// make sure this one hasnt already been handled.

		if(!divs[i].layermonkeyed)
		{
			// now find any divs with a background url that has "?layermonkey=[num]" in it
			if (divs[i].currentStyle)  // ie way
			{
				image = divs[i].currentStyle.backgroundImage;
				
				// while we're in here we might as well fix ie's semi-transperant png support
				// btw, i hate ie with a passion for making me do this.
				if(image.search(/.*\('?"?(.*transmonkey)/) != -1)
				{
					divs[i].style.backgroundImage="none";
					if(image.search(/.*\('?"?(.*transmonkeyscale)/) != -1)
					{
						divs[i].runtimeStyle.filter = 
						"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='scale', src=" + RegExp.$1 +")";
					}
					else
					{
						divs[i].runtimeStyle.filter = 
						"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='crop', src=" + RegExp.$1 +")";
					}
				}
			}

			else if (document.defaultView) // all other browsers
			{
				image = document.defaultView.getComputedStyle(divs[i],null).getPropertyValue('background-image');
			}
			
			// check if the background url has "layermonkey=[num1]-[num2]-[num3]" in it
			// this regular expression will also parse out the variables
			var lmindex = image.search(/layermonkey=([0-9]+)-([0-9]+)-([0-9]+)/);
			if(lmindex != -1)
			{
				// get the number of tops, layers and bottoms to do
		
				var tnum= parseInt(RegExp.$1);
				var lnum= parseInt(RegExp.$2);
				var bnum= parseInt(RegExp.$3);
			
				// now we use innerHTML to insert the divs, since:
				// http://www.quirksmode.org/dom/innerhtml.html

				var inner = divs[i].innerHTML;  // save the innerhtml
				var before = ''; // insert this before
				var after = ''; // insert this after
				
				// fill the strings with the nested divs
				var k;
				for(k=1; k<=tnum; k++) 
				{ before += '<div class="'+divs[i].className+'-top'+k+'"></div>'; }

				for(k=1; k<lnum; k++)
				{
					before += '<div class="'+divs[i].className+'-layer'+k+'">';
					after += '</div>';
				}

				// set the id of the last inner div
				if(lnum)
				{
					if(divs[i].id)
					{
						before += '<div class="'+divs[i].className+'-layer'+k+'" id="'+divs[i].id+'">';
						divs[i].id='';
					}				
					else
					{
						before += '<div class="'+divs[i].className+'-layer'+k+'">';
					}
	
					after += '</div>';
				}

				for(k=1; k<=bnum; k++) 
				{ after += '<div class="'+divs[i].className+'-bottom'+k+'"></div>'; }
				
				divs[i].innerHTML=before+inner+after;  // pop in the divs
				//alert(divs[i].innerHTML);
			}
			divs[i].layermonkeyed=true;  // mark this one as done
		}
	}
}

// do this onload
window.onload = function()
{
	layermonkey(document.body);
	if (top.location != self.location) {
		top.location = self.location;
	}
	
};

function fbs_click() 
{
	u=location.href;
	t=document.title;
	pageTracker._trackPageview('/share/facebook/'+t)
	window.open('http://www.facebook.com/sharer.php?u='+u+'&t='+t,'sharer','toolbar=0,status=0,width=626,height=436');
}

function msp_click() 
{
	u=location.href;
	t=document.title;
	
	metas=document.getElementsByTagName('meta');
	
	for (var x=0,y=metas.length; x<y; x++) 
	{
		if (metas[x].name.toLowerCase() == "description") 
		{
    		c = metas[x];
		}
	}
	c=c.content;
	pageTracker._trackPageview('/share/myspace/'+t)
	window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+u+'&t='+t+'&c='+c,'sharer','toolbar=0,status=0,width=626,height=436');
}

function eml_click() 
{
	u=location.href;
	t=document.title;
	
	metas=document.getElementsByTagName('meta');
	
	for (var x=0,y=metas.length; x<y; x++) 
	{
		if (metas[x].name.toLowerCase() == "description") 
		{
    		c = metas[x];
		}
	}
	c=c.content;
	
	pageTracker._trackPageview('/share/email/'+t)
	window.open('http://www.40cozy.com/tellafriend/?u='+u+'&t='+t+'&c='+c,'sharer','toolbar=0,status=0,width=600,height=650');
}