/**
 * ChosenPNGFIX based upon SuperSleight by Drew McLellan
 * Supersleight: http://24ways.org/2007/supersleight-transparent-png-in-ie6
 * ChosenPNGFIX: http://chosendevelopment.com/demo-download (version: 1.1)
**/
var supersleight	= function() {
	
	var root = false;
	var applyPositioning = true;
	
	// Path to a transparent GIF image
	var shim			= 'path/to/blank.gif';
	
	// RegExp to match above GIF image name
	var shim_pattern	= /blank\.gif$/i;
	
	
	
	var fnLoadPngs = function() { 
		if (root) {
			root = document.getElementById(root);
		}else{
			root = document;
		}

		for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {

			// background pngs
			 if ((obj.currentStyle.backgroundImage.match(/\.gif\"\)$/i) == null) && (obj.currentStyle.backgroundImage.match(/\.jpg\"\)$/i) == null) && (obj.currentStyle.backgroundImage.match(/\.jpeg\"\)$/i) == null) && (obj.currentStyle.backgroundImage != "none")) {
				bg_fnFixPng(obj);
			}	
			
			// image elements
			if ((obj.tagName=='IMG' && obj.src.match(/\.gif$/i) == null) && (obj.tagName=='IMG' && obj.src.match(/\.jpg$/i) == null) && (obj.tagName=='IMG' && obj.src.match(/\.jpeg$/i) == null) && (obj.tagName=='IMG' && obj.src.match(/\.jpeg$/i) == null)){
				if(obj.src.match(/\.php/i) != null){
					getMimeType(obj,obj.src)
				}else{
					el_fnFixPng(obj);
				}
			}
			// apply position to 'active' elements
			
			if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.title=='icon' && obj.style.position === ''){
				obj.style.position = 'relative';
			}
			
		}
	};

	var bg_fnFixPng = function(obj) {
		var mode = 'scale';
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
			mode = 'crop';
		}
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
		obj.style.backgroundImage = 'url('+shim+')';
	};

	var el_fnFixPng = function(img) {
		var src = img.src;
		img.style.width = img.width + "px";
		img.style.height = img.height + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='image')";
		img.src = shim;
	};
	
	var addLoadEvent = function(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			};
		}
	};

	var getMimeType = function(obj,src){
		var xmlhttp=false;
 		try 
 		{
   			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); /* for IE < 5 */
 		} 
 		catch (e) 
 		{
    		try 
    		{
 				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    		} 
    		catch (E) 
    		{
 				xmlhttp = false;
    		}
 		}
 
 		/* mozilla & opera */
 		if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
 		{
   			xmlhttp = new XMLHttpRequest();
 		}
		xmlhttp.open("HEAD", src, false);
		xmlhttp.onreadystatechange = function()
		{
		if (xmlhttp.readyState == 4 && /^0|2\d\d$/.test(xmlhttp.status))
		{
			var type= xmlhttp.getResponseHeader("Content-Type");
			if (type!='image/gif' && type!='image/jpeg' && type!='image/pjpeg') el_fnFixPng(obj);
		}
		};
		xmlhttp.send(null);

	};
	
	return {
		init: function() { 
			addLoadEvent(fnLoadPngs);
		},
		
		limitTo: function(el) {
			root = el;
		},
		
		run: function() {
			fnLoadPngs();
		}
	};
}();

// limit to part of the page ... pass an ID to limitTo:
// supersleight.limitTo('header');
supersleight.init();