// Global PNG transparency fix for Internet Explorer up to version 6 - Combined by Fotis Evangelou, http://www.webpr.gr/joomla

// The inline PNG fix, courtesy of Bob Osola, http://homepage.ntlworld.com/bobosola/

/*
Usage Notes:
Please note that due to IE's limitations in rendering transparent PNG images, you must not use one such image as a background underneath content that includes links! These links will not work in IE in that case! Well, what can you do then? For example if you have a "blog style" template and want to use a transparent png of size 800px width and 10px height with shadows left and right as the background of your articles list, don't make a table with 1 cell with that png as a background, but instead use a table with 3 cells and "split" your png image in 3 pieces using a graphics editor like Photoshop. Then use just the left and right parts of that image that contain the shadows and in the middle cell just use a background color or other non-png image to match the colors or pattern. This is just a simple example, but I believe you get the picture! It can be tricky, but not difficult. After all, it's just a matter of "smart" design!

One more thing! If you use inline png images, never forget to include the width and height of your images, as the javascript will fail to work. If you are using an editor to insert content, then the size of any png imported image will be automatially added. So you don't have to worry about that, but I just thought you should know!
*/

// ensure this is correct based on the paths
// NIc you need to change this for your server.
var blankSrc = '/Templates/Boultbee/Images/blank.gif'; // The tilda ("~") at the start is MANDATORY. It indicates to the server to resolve the path to the resource at runtime. 

// Corrects all images in line in the page
function correctPNG()
{
    for(var i=0; i<document.images.length; i++)
    {
        var img = document.images[i]
       
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
            var imgID = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText;
            if (img.align == "left") imgStyle = "float:left;" + imgStyle;
            if (img.align == "right") imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;		
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
            img.outerHTML = strNewHTML;
            i = i-1;
        }
    }
}

// corects all css background images
function alphaBackgrounds()
{
	
    
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	if (itsAllGood)
	{
	
		for (i=0; i<document.all.length; i++)
		{
		    var bg = document.all[i].currentStyle.backgroundImage;
		    
		    if (bg)
		    {
		        
		        // test if is png and that its not meant to be ignored ("II");
		        // mark ignored ones for pngs that have no transparency !!
			    if (bg.match(/\.png/i) != null && bg.indexOf('II') == -1)
			    {
			        
			        // MUST get size from css and match
			        var width = document.all[i].currentStyle.width;
				    var mypng = bg.substring(5,bg.length-2);

				    document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
				    document.all[i].style.backgroundImage = "url('" + blankSrc + "')";
                    
                    // crop or scale
                    // crop only works if you have the image dimensions.
			    }	
			}
		}
	}
}




// The background PNG fix, courtesy of Youngpup (http://www.youngpup.net) and Drew McLellan (http://www.allinthehead.com)
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
{
	// only want to load if lower than IE 7
	if (navigator.userAgent.toLowerCase().indexOf("msie 7.0") == -1)
	{
		window.attachEvent("onload", correctPNG);
		window.attachEvent("onload", alphaBackgrounds);
	}

}

