// IE5.5+ PNG Alpha Fix v1.0RC4
// (c) 2004-2005 Angus Turnbull http://www.twinhelix.com

// This is licensed under the CC-GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/


// This must be a path to a blank image. That's all the configuration you need.
if (typeof blankImg == 'undefined') var blankImg = 'blank.gif';


var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
var filters = new Array();
function filt(img, s, m)
{
  if (filters[f])
    {
      filters[f].enabled = s ? true : false;
      if (s) with (filters[f]) { src = s; sizingMethod = m }
    }
  else if (s) img.style.filter = 'progid:'+f+'(src="'+s+'",sizingMethod="'+m+'")';
}


function fixPNG(img)
{
   // Assume IE7 is OK.
 if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) return;

 var bgImg = img.currentStyle.backgroundImage || img.style.backgroundImage;

 if (img.tagName == 'IMG')
 {
  if ((/\.png$/i).test(img.src))
  {
   if (img.currentStyle.width == 'auto' && img.currentStyle.height == 'auto')
    img.style.width = img.offsetWidth + 'px';

   filt(img, img.src, 'scale');
   img.src = blankImg;
  }
  else if (img.src.indexOf(blankImg) < 0) filt();
 }
 else if (bgImg && bgImg != 'none')
 {
  if (bgImg.match(/^url[("']+(.*\.png)[)"']+$/i))
  {
   var s = RegExp.$1;
   if (img.currentStyle.width == 'auto' && img.currentStyle.height == 'auto')
    img.style.width = offsetWidth + 'px';
   img.style.backgroundImage = 'none';
	alert(s);
   filt(img, s, 'crop');
   // IE link fix.
   for (var n = 0; n < img.childNodes.length; n++)
    if (img.childNodes[n].style) img.childNodes[n].style.position = 'relative';
  }
  else filt(img);
 }
}

function fixAllPNG()
{
 // Assume IE7 is OK.
 if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)) return;

 for (var i=0;i<document.images.length;i++)
	{
		fixPNG(document.images[i]);
	}
}		
