nam: Race Condition?

Beitrag lesen

Jetzt geht's!
Danke für's auf die Sprünge helfen.

  
var mp3player = (function () {  
  
	var aTags,  
	elBuffer = {},  
	toBuffer = function (el) {  
		if (!elBuffer[el]) {  
			elBuffer[el] = el;  
		}  
	},  
	replace = function (tag) {  
		var flobj = null,  
		param = null;  
		  
		flobj = document.createElement('object');  
		flobj.type = 'application/x-shockwave-flash';  
		flobj.data = 'js/player_mp3_mini.swf';  
		flobj.width = '200';  
		flobj.height = '20';  
		  
		param = document.createElement('param');  
		param.name = 'movie';  
		param.value = 'js/player_mp3_mini.swf';  
		flobj.appendChild(param);  
		  
		param = document.createElement('param');  
		param.name = 'bgcolor';  
		param.value = '#eeeeee';  
		flobj.appendChild(param);  
		param = document.createElement('param');  
		param.name = 'FlashVars';  
		param.value = 'mp3=' + tag.href;  
		flobj.appendChild(param);  
		tag.parentNode.replaceChild(flobj, tag);  
	},  
	replaceAllInBuffer = function () {  
		var key;  
		for (key in elBuffer) {  
			if (elBuffer.hasOwnProperty(key) && elBuffer[key]) {  
				replace(elBuffer[key]);  
				elBuffer[key] = false;  
			}  
		}  
	};  
	  
	return {  
		init : function () {  
			var key;  
			aTags = document.getElementsByTagName('a');  
			for (key in aTags) {  
				if (aTags.hasOwnProperty(key)) {  
					if (!/\.mp3$/i.test(aTags[key].href || '')) {  
						continue;  
					}  
					toBuffer(aTags[key]);  
				}  
			}  
			replaceAllInBuffer();  
		}  
	};  
  
}());  
  
window.onload = (function (o) {  
	return function () {  
		if (o) {  
			o();  
		}  
		mp3player.init();  
	};  
}(window.onload));