/*
   jquery.opacity.js:  Create transparent backgrounds.

   Usage:

     <div style="background:#666" opacity=40></div>
     $(<selector>).opacity();

   or

     $(selector).opacity({opacity:40})

*/
(function ($) {

    function _opacity($this, settings) {
	var opacity = 100;

	if (settings.opacity == -1) {
	    if ($this.attr('opacity')) {
		opacity = parseInt($this.attr('opacity'));
	    }
	} else {
	    opacity = settings.opacity;
	}

        var clone = $this.clone();
	var cur_position = $this.css('position');
	if (cur_position == 'static') {
	    $this.css({
		position: 'relative'
	    });
	}

	var cur_zindex = $this.css('z-index');
	if (cur_zindex == 'auto') {
	    cur_zindex = 0;
	    $this.css('z-index', 0);
	}

        clone.html('');
        $this.css('background', 'none');
        //$this.css('background-color', 'none');
	//$this.css('background-image', 'none');
	clone.attr('id', $this.attr('id') + '_bg');
        clone.css({
	    '-ms-zoom':1,
	    zoom:1,
            'z-index': cur_zindex - 1,
            opacity: opacity / 100,
	    '-ms-filter': "alpha(opacity=" + opacity + ")",
            filter: 'alpha(opacity=' + opacity + ')',
	    top: '0px',
	    left: '0px',
	    margin: '0px',
	    border: 'none',
	    position: 'absolute'
        });

	clone.width($this.width());
	clone.height($this.height());
        $this.prepend(clone);

    }

    $.fn.opacity = function(settings) {
	settings = $.extend({
	    opacity:-1
	}, settings);

	if ($.browser.msie && $.browser.version >= '8') {
	  return 0;
	} else {
	  return this.each(function () {
	    _opacity($(this), settings);
	  });
	}
    };

})(jQuery);

