function externalScriptChecker(scriptURL, imageURL, timeout) {
	this.scriptURL = scriptURL;
	this.imageURL = imageURL;
	this.timeout = timeout ? timeout : 2000;

	this.timeoutRef = null;
	this.testImage = null;
}

externalScriptChecker.prototype.check = function() {
	var _this = this;
	var handleLoad = function() {
		_this.deliver();
	}
	var handleError = function() {
		_this.error();
	}

	this.testImage = new Image();
	this.testImage.onload = handleLoad;
	this.testImage.onerror = handleError;

	this.timeoutRef = window.setTimeout(handleError, this.timeout);

	this.testImage.src = this.imageURL;
}

externalScriptChecker.prototype.loadScript = function(src, nextScripts) {
	// var e = document.getElementsByTagName("head")[0];
	var e = document.getElementById("external-skript-div");
	if (e) {
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.src = src;

		var done = false;		
		var _this = this;
		
		script.onload = script.onreadystatechange = function() {
			if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
				done = true;

				if (nextScripts && nextScripts.length) {
					_this.loadScript(nextScripts.shift(), nextScripts);
				}

				script.onload = script.onreadystatechange = null;
				e.removeChild( script );
			}
		};

		e.appendChild(script);
	}
}

externalScriptChecker.prototype.deliver = function() {
	this.error();
	var l = this.scriptURL.length;
	if (!l || this.scriptURL.split)
		// Ist wohl String, da Strings |length| und |split| haben
		this.loadScript(this.scriptURL);
	else 
		this.loadScript(this.scriptURL.shift(), this.scriptURL);
}

externalScriptChecker.prototype.error = function() {
	if (this.timeoutRef) {
		window.clearTimeout(this.timeoutRef);
		this.timeoutRef = null;
	}

	if (this.testImage) {
		this.testImage.onload = null;
		this.testImage.onerror = null
		this.testImage = null;
	}
}

