/* $Id: pngfix.jquery.js,v 1.1.2.1 2008/03/20 22:05:00 gburns Exp $

Unobtrusive Accessible jQuery 1.2.1 drop downs.

Overview:
	jQuery.fn.()

Parameters:
	spacer: (String) URL to spacer.gif
		Default: '/images/spacer.gif'

Usage:
	JavaScript:
	if ( $.browser.msie && $.browser.version < 7 ) {
		$('img, input').pngfix();
	}

Author:
	gburns

TODO:
	documentation
	Combine jQuery.fn.pngfix and jQuery.pngfix?
*/

jQuery.fn.pngfix = function(options) {
	var settings = jQuery.extend({
		spacer: '/images/spacer.gif'
	}, options || {});

	jQuery.pngfix.spacer = settings.spacer;

	return this.each(function() {
		var type, background_image, background_repeat;

		type = this.tagName.toLowerCase();

		if ( type == 'input' || type == 'img' ) {
			if ( (type == 'input' && this.getAttribute('type') == 'image' && this.src.toLowerCase().search(/\.png$/) >= 0 ) || this.src.toLowerCase().search(/\.png$/) >= 0 ) {
				jQuery.pngfix.fix(this);
				$(this).bind('propertychange', function() {
					jQuery.pngfix.fix(this);
				});
			}
		}
	});
};

jQuery.pngfix = {
	fixing: false,
	spacer: '/images/spacer.gif',
	fix: function(obj) {
		if ( jQuery.pngfix.fixing ) return;

		jQuery.pngfix.fixing = true;

		var src = obj.src;

		if ( new RegExp(jQuery.pngfix.spacer).test(src) ) {
			jQuery.pngfix.fixing = false;
			return;
		}

		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src  + "', sizingMethod='image')";

		$(obj).bind('beforeprint', function(imgObjSrc) {
			return function() {
				this.src = imgObjSrc;
			}
		}(obj.src));

		$(obj).bind('afterprint', function() {
			this.src = jQuery.pngfix.spacer;
		});

		obj.src = jQuery.pngfix.spacer;
		jQuery.pngfix.fixing = false;
	}
}