/*$j(window).ready(function() {
    $j('img').fixBroken();
});

$j.fn.fixBroken = function(){
    return this.each(function(){
        var tag = $j(this);
        var alt_img = tag.metadata().alt_img;
        // is there an alt_img metadata defined for this image? otherwise we dont touch the image
        if (alt_img) {
            tag.error(function(){
                tag.attr("src",alt_img);
				return true;
            });
        }
    });
};
*/

$j(window).load(function() {
    // add fixBroken code to all images on the document
    $j('img').fixBroken();
});

$j.fn.fixBroken = function(){

return this.each(function(){
        var tag = $j(this);
        var alt_img = tag.metadata().alt_img;
        // is there an alt_img metadata defined for this image? otherwise we dont touch the image
        if (alt_img) {
			if((typeof this.naturalWidth != "undefined" &&
				this.naturalWidth == 0 ) 
				|| this.readyState == 'uninitialized' || this.readyState == 'loading') {
					tag.attr('src', alt_img);
					tag.attr('style', 'inline');
			}
			tag.error(function(){
                tag.attr("src",alt_img);
				tag.attr('style', 'inline');
            });
        }
    });
	
};