/*
 * AudioFix - A jQuery Plugin
 *
 * fixes a html5 audio in IE < 9
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * (c) 2011, Dmitry Sherbina
 */
 
 /* naive non jquery implementation
  <!--[if (gte IE 9)|!(IE)]><!--> 
<audio id="bgs1" preload src="{{=URL(c='static',f='test/square_1000_50.wav')}}" type="audio/wav" >
</audio> 
<!--<![endif]-->

<!--[if IE lt 9]>    <bgsound id="bgs1" src="" src0="{{=URL(c='static',f='test/square_1000_50.wav')}}" loop="1" />
<script> //update code here</script>
<![endif]-->

 */
(function($) {
    var name='audiofix';
    if( $.browser.msie && $.browser.version < '9'){
        var defaults = {
            timeout: 1000
        };
        $.fn.audioIE = function(options) {
            //advance bgsound
            var settings=$.extend({}, defaults, options);
            return this.each(function() {
                 var o={
                    stop: function(){
                    //~ this.src0=this.src;
                    this.src='';
                    },
                    play: function(){
                        this.src=this.src0;
                        setTimeout(this.stop, settings.timeout)
                    }
                };
                $.extend(this, o);
                return this;
            });
        };
        $('audio').each(function() {
            var el = $('<bgsound/>').attr({
		        id: this.id,
                src0: this.src,
				loop: 1,
                src: '',
            })
            $(this).after(el)
            $(this).remove()
        });
        $('bgsound').audioIE();
    };
})(jQuery);

