/**
 * When applied to select fields with a fixed width, this script will expand the 
 * field so the options are not cropped in IE version less than 9.
 */

(function($) {
  $.fn.ieSelectWidth = function() {
    if ($.browser.msie && parseInt($.browser.version) < 9) {
      $(this).each(function () {
        if ($(this).attr('multiple') == false) {
          $(this).mousedown(function() {
            if ($(this).data('origWidth') == undefined) {
              $(this).data('origWidth', $(this).css("width"));
              $(this).wrap('<div style="width:'+$(this).css("width")+'; overflow:hidden;" />');
            }

            var width = $(this).width();
            $(this).css('width', 'auto');

            if ($(this).width() < width) {
              $(this).unbind('mousedown');
              $(this).css("width", $(this).data("origWidth"));
            }
          })

          .blur(function() {
            $(this).css("width", $(this).data("origWidth"));
          })

          .change(function() {
            $(this).css("width", $(this).data("origWidth"));
          });
        }
      });
    }
  };
}) (jQuery);


