var isMinNN4  = document.layers         ? true : false;
var isMinIE4  = document.all            ? true : false;
var isW3C     = document.getElementById ? true : false; // W3C stands for the W3C standard, implemented in Mozilla (  and Netscape 6  ) and IE5
var isMinIE5  = isW3C;
var mouseLeft = 0;
var mouseTop  = 0;

function setMouseCoordinate( e ) {
	var newLeft = 0;
	var newTop  = 0;
	
	if ( isMinIE4 ) {
		newLeft = document.body.scrollLeft + event.clientX
		newTop  = document.body.scrollTop  + event.clientY
	} else if ( isMinNN4 || isW3C ) {
		newLeft = e.pageX;
		newTop  = e.pageY;
	}
	
	if ( Math.abs( newLeft - mouseLeft ) > 10 ) mouseLeft = newLeft;
	if ( Math.abs( newTop  - mouseTop  ) > 10 ) mouseTop  = newTop;
}

document.onmousemove = setMouseCoordinate;

function findElementPos( obj ) {
	var curleft = 0;
	var curtop  = 0;
	if ( obj.offsetParent ) {
		curleft = obj.offsetLeft;
		curtop  = obj.offsetTop;
		while ( obj = obj.offsetParent ) {
			curleft += obj.offsetLeft;
			curtop  += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function layerDisplay( pObj, pLayer, pMode, pLeft, pTop ) {
	var newLeft = 10;
	var newTop  = 10;

	if ( pMode == 'a' ) {
		newLeft = Math.abs( pLeft );
		newTop  = Math.abs( pTop  );
	} else {
		var leftTop = ( pObj ? findElementPos( document.getElementById( pObj ) ) : false );
		newLeft = Math.abs( ( leftTop ? ( leftTop[0] + pLeft ) : 10 ) );
		newTop  = Math.abs( ( leftTop ? ( leftTop[1] + pTop  ) : 10 ) );
	}

	layerPosition( pLayer, newLeft, newTop );
	layerShow( pLayer );
}

function layerPosition( pLayer, pLeft, pTop ) {
	if ( isMinIE4 || isW3C ) {
		if ( isW3C ) {
		    document.getElementById( pLayer ).style.left = ( pLeft + 'px' );
		    document.getElementById( pLayer ).style.top  = ( pTop  + 'px' );
		} else {
			document.getElementById( pLayer ).style.pixelLeft = ( pLeft + 'px' );
    		document.getElementById( pLayer ).style.pixelTop  = ( pTop  + 'px' );
    	}
	} else if ( isMinNN4 ) {
		document.getElementById( pLayer ).left = ( pLeft + 'px' );
		document.getElementById( pLayer ).top  = ( pTop  + 'px' );
	}
}

function layerShow( pLayer ) {
	/*
	if ( isMinIE4 || isW3C ) {
		document.getElementById( pLayer ).style.display = "inline";
		document.getElementById( pLayer ).style.visibility = "visible";
	} else if ( isMinNN4 ) {
		document.getElementById( pLayer ).display = "inline";
		document.getElementById( pLayer ).visibility = "show";
	}
	*/

	$( '#' + pLayer ).fadeIn( 'fast' );
}

function layerHide( pLayer ) {
	/*
	if ( isMinIE4 || isW3C ) {
		document.getElementById( pLayer ).style.visibility = "hidden";
	} else if ( isMinNN4 ) {
		document.getElementById( pLayer ).visibility = "hidden";
	}
	*/
	
	$( '#' + pLayer ).fadeOut( 'slow' );
}


