function PreloadController(imgSrc, width, height) {
	this.debug = false;
	try {
		this.aktiv = false;
		this.preloader = null;
		this.iframe = null;
		this.imgSrc = imgSrc;
		this.imgWidth = width;
		this.imgHeight = height;
		this.isIE = (typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE');
		EventListener.addEvent(document, 'mousemove', this.scope('moveListener'));
	} catch ( exception ) {
		if ( this.debug ) alert('PreloadController.__construct()' + ' - ' + exception.message);
	}
}

PreloadController.prototype = {
	
	scope:function(method) {
		var scope = this;
		return function() {
			scope[method].apply(scope, arguments);
		}
	},
	
	moveListener:function(e) {
		try {
			if( !this.preloader && this.aktiv ) this.createPreloader(e);
			if ( this.aktiv ) this.addPreload(e);
			return EventListener.cancelEvent(e);
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.moveListener()' + ' - ' + exception.message);
		}
	},
	
	addPreload:function(e) {
		try {
			var pos = this.getPreloaderPos(e);
			this.preloader.style.left = String(pos.x) + 'px';
			this.preloader.style.top = String(pos.y) + 'px';
			if ( this.iframe ) {
				this.iframe.style.left = this.preloader.style.left;
				this.iframe.style.top = this.preloader.style.top;
			}
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.addPreload()' + ' - ' + exception.message);
		}
	},
	
	deletePreload:function() {
		try {
			this.preloader.style.left = String(-1000) + 'px';
			if ( this.iframe ) {
				this.iframe.style.left = this.preloader.style.left;
			}
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.deletePreload()' + ' - ' + exception.message);
		}
	},
	
	getPreloaderPos:function(e) {
		try {
			var scrollpoz = this.getScrollPoz();
			var xpoz = String( 
				Math.min (Math.max(e.clientX - (this.imgWidth/2) + scrollpoz.x, scrollpoz.x), 
						 document.documentElement.clientWidth - this.imgWidth + scrollpoz.x )
							 );
			var ypoz = String( 
				Math.min (Math.max(e.clientY - (this.imgHeight/2) + scrollpoz.y, scrollpoz.y), 
						  document.documentElement.clientHeight - this.imgHeight + scrollpoz.y )
							 );
			return {x:xpoz, y:ypoz};	
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.getPreloaderPos()' + ' - ' + exception.message);
		}
	},
		
	createPreloader:function(e) {
		try {
			if ( !this.preloader ) {
				var pos = this.getPreloaderPos(e);
				this.preloader = document.createElement('img');
				this.preloader.src = this.imgSrc;
				this.preloader.width = this.imgWidth;
				this.preloader.height = this.imgHeight;
				this.preloader.style.border = 0; 	
				this.preloader.style.alt = ''; 
				this.preloader.style.zIndex = 10000;
				this.preloader.style.cursor = 'wait';
				this.preloader.style.position = 'absolute';
				document.body.appendChild(this.preloader);
				this.preloader.style.left = String(pos.x) + "px";	
				this.preloader.style.top = String(pos.y) + "px";
				this.preloader.style.width = String(this.imgWidth) + "px";
				this.preloader.style.height = String(this.imgHeight) + "px";
				if ( this.isIE && !this.iframe ) {
					this.iframe = document.createElement('iframe');
					this.iframe.tabIndex = '-1';
					this.iframe.src = 'javascript:false;';
					this.iframe.style.position = 'absolute';
					this.iframe.style.zIndex = Number(this.preloader.style.zIndex - 1);
					document.body.appendChild(this.iframe);
					this.iframe.style.left = String(pos.x) + "px";
					this.iframe.style.top = String(pos.y) + "px";
					this.iframe.style.width = String(this.imgWidth) + "px";
					this.iframe.style.height = String(this.imgHeight) + "px";
				}
			}
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.createPreloader()' + ' - ' + exception.message);
		}
	},
		
	localToGlobal:function(div) {
		try {
			var myObject = new Object();
			myObject.x = 0;
			myObject.y = 0;
			while (div != null) {
			   myObject.x += div.offsetLeft;
			   myObject.y += div.offsetTop;
			   div = div.offsetParent;
			}
			return myObject;
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.localToGlobal()' + ' - ' + exception.message);
		}
	},
	
	getScrollPoz:function() {
		try {
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
				scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
			return { x:scrOfX, y:scrOfY };
		} catch ( exception ) {
			if ( this.debug ) alert('PreloadController.getScrollPoz()' + ' - ' + exception.message);
		}
	}
}
