/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.2, 09.03.2009
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    09.03.2009 Version 1.2
 *    - Update for jQuery 1.3.x, removed @ from selectors
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function ($) {
   jQuery.fn.pngFix = function (settings) {
       settings = jQuery.extend({
           blankgif: '_js/pngFix/blank.gif'
       },
       settings);

       var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
       var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	   if (jQuery.browser.msie&&(ie55||ie6)) {
           jQuery(this).find("img[src$=.png]").add(jQuery(this).find("img[src$=.PNG]")).each(function () {
    if(jQuery(this).width() == 0) {
         if(jQuery(this).css('width') == "auto")
           {
       jQuery(this).css('width', jQuery(this).parent().css('width'));
        }else{
       jQuery(this).css('width', jQuery(this).css('width'));
        }

     }else{
      jQuery(this).css('width', jQuery(this).width());
                               
         }
             
    if(jQuery(this).height() == 0) {
              if(jQuery(this).css('height') == "auto")
           {
       jQuery(this).css('height', jQuery(this).parent().css('width'));
        }else{
       jQuery(this).css('height', jQuery(this).css('width'));
        }
     }else{
      jQuery(this).css('height', jQuery(this).height());
                                 
         }
               var filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"' + jQuery(this).attr('src') + '\",sizingMethod=\"scale\")';
               jQuery(this).attr('src', settings.blankgif);
               jQuery(this).css('position', 'relative');
               jQuery(this).css('filter', filter);
               jQuery(this).css('float', 'left');
 
               var imgHand = (jQuery(this).parent().attr('href')) ? 'hand': '';
               jQuery(this).css('cursor', imgHand);
           });
           jQuery(this).find("*").each(function () {
               var bgIMG = jQuery(this).css('background-image');
               if (bgIMG.indexOf(".png") != -1) {
                   var iebg = bgIMG.split('url("')[1].split('")')[0];
                   jQuery(this).css('background-image', 'none');
                   var sM = 'crop';
                   jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +  iebg + "',sizingMethod='" + sM + "')";
               }
           });
           jQuery(this).find("input[src$=.png]").each(function () {
               var bgIMG = jQuery(this).attr('src');
               jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
               jQuery(this).attr('src', settings.blankgif)
           })
       }
       return jQuery
   }
})(jQuery);

