jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		input_src: true,
		shim: 'x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.supersleightGetWidth() + 'px',
						'height': self.supersleightGetHeight() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// input image elements with src
				if (settings.input_src && self.is('input[src$=png]')){
					var styles = {
						'width': self.supersleightGetWidth() + 'px',
						'height': self.supersleightGetHeight() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input, label') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

$.fn.supersleightGetHeight = function() {
	
	var paddingHeight = parseInt($(this).css("padding-top"), 10) + parseInt($(this).css("padding-bottom"), 10);
	var marginHeight = parseInt($(this).css("margin-top"), 10) + parseInt($(this).css("margin-bottom"), 10);
	var borderHeight = parseInt($(this).css("borderTopWidth"), 10) + parseInt($(this).css("borderBottomWidth"), 10);
	
	var totalHeight = $(this).height();
	
	if (paddingHeight > 0) {
		totalHeight -= paddingHeight;
	}
	if (marginHeight > 0) {
		totalHeight -= marginHeight;
	}
	if (borderHeight > 0) {
		totalHeight -= borderHeight;
	}
	
	return totalHeight;
	
}

$.fn.supersleightGetWidth = function() {
	
	var paddingWidth = parseInt($(this).css("padding-left"), 10) + parseInt($(this).css("padding-right"), 10);
	var marginWidth = parseInt($(this).css("margin-left"), 10) + parseInt($(this).css("margin-right"), 10);
	var borderWidth = parseInt($(this).css("borderLeftWidth"), 10) + parseInt($(this).css("borderRightWidth"), 10);
	
	var totalWidth = $(this).width();
	
	if (paddingWidth > 0) {
		totalWidth -= paddingWidth;
	}
	if (marginWidth > 0) {
		totalWidth -= marginWidth;
	}
	if (borderWidth > 0) {
		totalWidth -= borderWidth;
	}
	
	return totalWidth;
	
}
