var ns=false, ie=false;
var windowWidth, windowHeight;
var objRef, styleSwitch, pixSwitch, leftSwitch, topSwitch;
var gen5, elementID, diffX, diffY;
var lastScrollX = 0; 
var lastScrollY = 0;
var layerXY = [0, 0, 0, 0];
var mousePos = [0, 0];
var debug = 0;
checkBrowser();
function init() {
	self.onError=null;
	getDimensions();
}
function checkBrowser() {
	if( (parseInt( navigator.appVersion )) >= 4 ) {
		( navigator.appName.indexOf("etscape") != -1 ) ? ns = true : ns = false;
		( navigator.appName.indexOf("xplorer") != -1 ) ? ie = true : ie = false;
		gen5 = document.getElementById ? 1 : 0;
	}
}

function getDimensions() {
	if( ns ) {
		windowWidth = innerWidth;
		windowHeight = innerHeight;
	}
	else if( ie ) {
		windowWidth = self.document.body.clientWidth;
		windowHeight = self.document.body.clientHeight;
	}
return windowHeight, windowWidth;
}
function makeObj( elementID ) {
	if ( gen5 ) {
		objRef = 'document.getElementById("' + elementID + '")';
		styleSwitch = ".style";
	}
	if( ns ) {
		if ( !gen5 ) {objRef = 'document.layers["' + elementID + '"]'};
		if ( !gen5 ) {styleSwitch = ""};
		leftSwitch = ".left";
		topSwitch = ".top";   
		widthSwitch = ".clip.right";
		heightSwitch = ".clip.bottom";
	}
	else if( ie ) {	
		if ( !gen5 ) {objRef = 'document.all["' + elementID + '"]'};
		if ( !gen5 ) {styleSwitch = ".style"};
		leftSwitch = ".pixelLeft";
		topSwitch = ".pixelTop";
		widthSwitch = ".width";
		heightSwitch = ".height";
	} 
	
if ( eval( objRef ) ) {
this.obj = eval( objRef );
this.css = eval( objRef + styleSwitch );
this.css.left = eval( objRef + styleSwitch + leftSwitch );
this.css.top = eval( objRef + styleSwitch + topSwitch );
this.css.visibility = eval( objRef + styleSwitch + '.visibility' );
this.css.width = eval( objRef + styleSwitch + widthSwitch );
this.css.height = eval( objRef + styleSwitch + heightSwitch );
var Xleft = parseInt( this.css.left );
var Ytop = parseInt( this.css.top );
var Xright = parseInt( this.css.left ) + parseInt( this.css.width );
var Ybottom = parseInt( this.css.top ) + parseInt( this.css.height );
layerXY = [Xleft, Xright, Ytop, Ybottom];
return this, layerXY;
}
if ( debug == 1 && !eval(objRef) ) { 
alert('<div>-Layer mit der ID: "' + elementID + '" nicht gefunden !!') 
}
}
if ( ns ) { document.captureEvents(Event.MOUSEMOVE) } 
document.onmousemove = getMousePos;
function getMousePos(evnt) {
	mousePos = ( ie ) ? [event.clientX + document.body.scrollLeft, event.clientY + document.body.scrollTop] : [evnt.pageX, evnt.pageY];
		if ( ie ) {
			 event.cancelBubble = true; 
			 }
	return mousePos;
}


function checkMouseOverLayer( elementID, margin ) {
	makeObj( elementID );
	if (!margin ) {	var margin = 3; }
	if ( mousePos[0] > layerXY[0] - margin && mousePos[0] < layerXY[1] + margin && mousePos[1] > layerXY[2] - margin && mousePos[1] < layerXY[3] + margin ) {
	return true;
	}
return false;
}
function writeInLayer( elementID, txt ) {
	makeObj( elementID );
	if ( gen5 || ie ) { 
		this.obj.innerHTML = txt; 
	}
	if ( !gen5 && ns  ) { 
	with( this.obj.document )
		{
		 open();
		 write(txt);
		 close(); 
		}
	}
}
function stayInPlace( elementID, yScroll, xScroll ) {
	if ( elementID != '' && this.css ) {
	makeObj( elementID );
	}
    if( ns ) { 
			diffY = self.pageYOffset; 
			diffX = self.pageXOffset; 
	}
    else {
			diffY = document.body.scrollTop; 
			diffX = document.body.scrollLeft;
	}
		
	if ( yScroll == 1 ) {
	    if(diffY != lastScrollY) {
	    	percent = .1 * (diffY - lastScrollY);
	        if(percent > 0) percent = Math.ceil(percent);
	        else percent = Math.floor(percent);
			this.css.top = parseInt(this.css.top) + percent; 
	        lastScrollY = lastScrollY + percent;
	    }
 	}
	if ( xScroll == 1 ) {
	    if (diffX != lastScrollX) {
	       	percent = .1 * (diffX - lastScrollX);
	        if(percent > 0) percent = Math.ceil(percent);
	        else percent = Math.floor(percent);
			this.css.left = parseInt(this.css.left) + percent;
	        lastScrollX = lastScrollX + percent;
    }
	}       
}

function moveLayerUp( elementID, pix ) {
	makeObj( elementID );
	pix = parseInt(this.css.top) - pix;
	this.css.top = pix;
}

function moveLayerDown( elementID, pix ) {
	makeObj( elementID );
	pix = parseInt(this.css.top) + pix;
	this.css.top = pix;
}

function moveLayerRight( elementID, pix ) {
	makeObj( elementID );
	pix = parseInt(this.css.left) + pix;
	this.css.left = pix;
}

function moveLayerLeft( elementID, pix ) {
	makeObj( elementID );
	pix = parseInt(this.css.left) - pix;
	this.css.left = pix;
}
function showLayer( elementID ) {
	makeObj( elementID );
	this.css.visibility = "visible";
}

function hideLayer( elementID ) {
	makeObj( elementID );
	this.css.visibility = "hidden";
}
function getLayerLeftPos( elementID ) {
	makeObj( elementID );
	pos = layerXY[0];
	return pos;
}

function getLayerTopPos( elementID ) {
	makeObj( elementID );
	pos = layerXY[2];
	return pos;
}

function getLayerVisibility( elementID ) {
	makeObj( elementID );
	var vis = this.css.visibility;
	switch(vis)
	{
	 case "visible":
	 return true;
	 break;
	 case "show":
	 return true;
	 break;
	 case "hidden":
	 return false;
	 break;
	 case "hide":
	 return false;
	 break;
	 default:
	 break;
	}
}

function getLayerWidth( elementID ) {
	makeObj( elementID );
	var w = parseInt(this.css.width);
	return w;
}

function getLayerHeight( elementID ) {
	makeObj( elementID );
	var h = parseInt(this.css.height);
	return h;
}
function setLayerLeftPos( elementID, leftPos ) {
	makeObj( elementID );
	this.css.left = leftPos;
}

function setLayerTopPos( elementID, topPos ) {
	makeObj( elementID );
	this.css.top = topPos;
}

function setLayerPos( elementID, leftPos, topPos ) {
	setLayerLeftPos( elementID, leftPos )
	setLayerTopPos( elementID, topPos )
}
