﻿// sample style: .shadimg { filter:alpha(opacity=40); -moz-opacity:.4; opacity:.4; }

var shadowPieces = 
	{ 
		shadowPath:"/dw/image/",
		size: "8",
		lead: "12",
		zIndex: "20",
		className: "shadimg",
		shad_bottomleft:"shad_bl3.png", 
		shad_h:"shad_h3.png", 
		shad_topright:"shad_tr3.png", 
		shad_v:"shad_v3.png", 
		shad_bottomright:"shad_br3.png" 
	};

function addShadow(oDiv, bDontCallPosition)
{
	if (typeof oDiv == "string")
	{
		oDiv = document.getElementById(oDiv);
		if (!oDiv)
			return;
	}

	var sPx = "px";
	var typeImage = "img"
	var zeroPx = "0px";
	var positionAbsolute = "absolute";

	var par_element = oDiv.parentNode;
	var img_bl = document.getElementById(oDiv.id + "shadow_bl");
	if (!img_bl)
	{
		img_bl = document.createElement(typeImage);
		img_bl.id = oDiv.id + "shadow_bl";
		img_bl.src = shadowPieces.shadowPath + shadowPieces.shad_bottomleft;
		img_bl.style.width = shadowPieces.lead + sPx;
		img_bl.style.height = shadowPieces.size + sPx;
		img_bl.style.left = zeroPx;
		img_bl.style.top = zeroPx;
		img_bl.className = shadowPieces.className;
		img_bl.style.position = positionAbsolute;
		img_bl.style.zIndex = shadowPieces.zIndex;
		par_element.appendChild(fixpng(img_bl));
	}
	var img_h = document.getElementById(oDiv.id + "shadow_h");
	if (!img_h)
	{
		img_h = document.createElement(typeImage);
		img_h.id = oDiv.id + "shadow_h";
		img_h.src = shadowPieces.shadowPath + shadowPieces.shad_h;
		img_h.style.width = shadowPieces.size + sPx;
		img_h.style.height = shadowPieces.size + sPx;
		img_h.style.left = shadowPieces.lead + sPx;
		img_h.style.top = zeroPx;
		img_h.className = shadowPieces.className;
		img_h.style.position = positionAbsolute;
		img_h.style.zIndex = shadowPieces.zIndex;
		par_element.appendChild(fixpng(img_h));
	}
	var img_tr = document.getElementById(oDiv.id + "shadow_tr");
	if (!img_tr)
	{
		img_tr = document.createElement(typeImage);
		img_tr.id = oDiv.id + "shadow_tr";
		img_tr.src = shadowPieces.shadowPath + shadowPieces.shad_topright;
		img_tr.style.width = shadowPieces.size + sPx;
		img_tr.style.height = shadowPieces.lead + sPx;
		img_tr.style.left = zeroPx;
		img_tr.style.top = zeroPx;
		img_tr.className = shadowPieces.className;
		img_tr.style.position = positionAbsolute;
		img_tr.style.zIndex = shadowPieces.zIndex;
		par_element.appendChild(fixpng(img_tr));
	}
	var img_v = document.getElementById(oDiv.id + "shadow_v");
	if (!img_v)
	{
		img_v = document.createElement(typeImage);
		img_v.id = oDiv.id + "shadow_v";
		img_v.src = shadowPieces.shadowPath + shadowPieces.shad_v;
		img_v.style.width = shadowPieces.size + sPx;
		img_v.style.height = shadowPieces.size + sPx;
		img_v.style.left = zeroPx;
		img_v.style.top = shadowPieces.lead + sPx;
		img_v.className = shadowPieces.className;
		img_v.style.position = positionAbsolute;
		img_v.style.zIndex = shadowPieces.zIndex;
		par_element.appendChild(fixpng(img_v));
	}

	var img_br = document.getElementById(oDiv.id + "shadow_br");
	if (!img_br)
	{
		img_br = document.createElement(typeImage);
		img_br.id = oDiv.id + "shadow_br";
		img_br.src = shadowPieces.shadowPath + shadowPieces.shad_bottomright;
		img_br.style.width = shadowPieces.size + sPx;
		img_br.style.height = shadowPieces.size + sPx;
		img_br.style.left = zeroPx;
		img_br.style.top = shadowPieces.lead + sPx;
		img_br.className = shadowPieces.className;
		img_br.style.position = positionAbsolute;
		img_br.style.zIndex = shadowPieces.zIndex;
		par_element.appendChild(fixpng(img_br));
	}

	if (!bDontCallPosition)
		positionShadow(oDiv);
}

function positionShadow(oDiv)
{
	var itemHeight = 0;
	var itemWidth = 0;
	if (typeof oDiv == "string")
	{
		oDiv = document.getElementById(oDiv);
		if (!oDiv)
			return;
	}

	var img_bl = document.getElementById(oDiv.id + "shadow_bl");
	var img_h = document.getElementById(oDiv.id + "shadow_h");
	var img_tr = document.getElementById(oDiv.id + "shadow_tr");
	var img_v = document.getElementById(oDiv.id + "shadow_v");
	var img_br = document.getElementById(oDiv.id + "shadow_br");

	if (! oDiv.offsetHeight)
	{
		try
		{
			itemWidth = parseInt(oDiv.style.width);
			itemHeight = parseInt(oDiv.style.height);
			if (oDiv.style.border)
			{
				itemWidth += (parseInt(oDiv.style.border) * 2);
				itemHeight += (parseInt(oDiv.style.border) * 2);
			} else if (oDiv.style.borderLeft)
			{
				itemWidth += (parseInt(oDiv.style.borderLeft) * 2);
				itemHeight += (parseInt(oDiv.style.borderTop) * 2);
			}
		}
		catch (E) { }
	}
	
	try
	{
		img_bl.style.top = "" + ( itemHeight + oDiv.offsetHeight ) + "px";
		img_h.style.top = img_bl.style.top;
		if (oDiv && ( oDiv.offsetWidth || itemWidth ) )
			img_h.style.width = "" + (itemWidth + oDiv.offsetWidth - parseInt(shadowPieces.lead)) + "px";
		img_tr.style.left = "" + ( itemWidth + oDiv.offsetWidth ) + "px";
		img_v.style.left = img_tr.style.left;
		if (oDiv && ( oDiv.offsetHeight || itemHeight ) )
			img_v.style.height = "" + (itemHeight + oDiv.offsetHeight - parseInt(shadowPieces.lead)) + "px";
		img_br.style.left = "" + (itemWidth + oDiv.offsetWidth) + "px";
		img_br.style.top = "" + (itemHeight + oDiv.offsetHeight) + "px";
	}
	catch (E) { }
}

function removeShadow(oDiv)
{
	if (typeof oDiv == "string")
	{
		oDiv = document.getElementById(oDiv);
		if (!oDiv)
			return;
	}

	var img_bl = document.getElementById(oDiv.id + "shadow_bl");
	if (img_bl)
		img_bl.parentNode.removeChild(img_bl);
	var img_h = document.getElementById(oDiv.id + "shadow_h");
	if (img_h)
		img_h.parentNode.removeChild(img_h);
	var img_tr = document.getElementById(oDiv.id + "shadow_tr");
	if (img_tr)
		img_tr.parentNode.removeChild(img_tr);
	var img_v = document.getElementById(oDiv.id + "shadow_v");
	if (img_v)
		img_v.parentNode.removeChild(img_v);
	var img_br = document.getElementById(oDiv.id + "shadow_br");
	if (img_br)
		img_br.parentNode.removeChild(img_br);
}

var arVersion = navigator.appVersion.split("MSIE")
var IEversion = parseFloat(arVersion[1])

function fixpng(imgItem)
{
	if ((IEversion >= 5.5) && (document.body.filters))
	{
		var replacement = document.createElement("span");
		replacement.id = imgItem.id;
		replacement.style.left = imgItem.style.left;
		replacement.style.top = imgItem.style.top;
		replacement.style.width = imgItem.style.width;
		replacement.width = imgItem.style.width;
		replacement.style.height = imgItem.style.height;
		replacement.height = imgItem.style.height;
		replacement.style.display = "inline-block";
		replacement.className = imgItem.className;
		replacement.style.position = imgItem.style.position;
		replacement.style.zIndex = imgItem.style.zIndex;
		replacement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgItem.src + "', sizingMethod='scale')";
		return replacement;
	}
	return imgItem;
}

