/*
 * JCE Utilities 1.6.0
 *
 * Copyright (c) 2007 - 2008 Ryan Demmer (www.cellardoor.za.net)
 * Licensed under the GPL (http://www.gnu.org/licenses/licenses.html#GPL)license.
 * JCE Tooltips based on Mootools Tips plugin - http://www.mootools.net
 * JCE Lightbox plugin based on Slimbox - http://www.digitalia.be/software/slimbox - and Thickbox - http://jquery.com/demo/thickbox/
 */
jQuery.noConflict();
(function($){
	$.extend({
		
	});
	$.UltimatePNGfix = function(options){
		
		return $.UltimatePNGfix.init(options);
	};
	$.UltimatePNGfix.init = function(options){
		
		this.options = $.extend({
			imgpath: '/images/',
			fixinline			: 1,
			fixbg			: 1				
		}, options);
		
		$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
		
		if($.browser.msie6){
			
			if(this.options.fixinline == 1 || this.options.fixbg	 == 1){	
			
				this.pngFix(options);	
			}
		}
		
	};
	
	
	
	$.UltimatePNGfix.pngFix = function(options){
		
		var elements = $('*', document);
		elements.each(function(){
			
							  
			var $$ = $(this);
			
			// in case rewriting urls
			var base = $('base').attr('href');
			if (base) {
				// remove anything after the last '/'
				base = base.replace(/\/[^\/]+$/,'/');
			}
			
			if (($$.is('img') || $$.is('input'))) { // hack image tags present in dom
			
			
				if ($$.attr('src') && options.fixinline==1) {
					
					if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image
					
						// use source tag value if set 
						var source = (base && $$.attr('src').search(/^(\/|http:)/i)) ? base + $$.attr('src') : $$.attr('src');
						// apply filter
						$$.css({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale,src='"+source+"')", width:$$.width()+'px', height:$$.height()+'px'}).attr({src:imgpath+'blank.gif'});
					}
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i) && options.fixbg==1) {
					
					image = RegExp.$1;
					image = (base && image.substring(0,1)!='/') ? base + image : image;
					$$.css({backgroundImage:'none', filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale,src='"+image+"')"});
				}
			}
		});
	}
	
})(jQuery);
var ultimatepngfix 	= jQuery.UltimatePNGfix;