/**
* Class DateLayer
* Author: Stefan Theusner <theusner@slienceapi.com>
* param string xLayer (name oder id des Layers)
* param int x (x-pos der Maus)
* param int y (y-pos der Maus)
*/

function myLayer(xLayer, x, y) {

  /* SET BROWSER AND SCRIPTING */
  this.NS4=(navigator.appName.indexOf('Netscape')>=0 && !document.getElementById)? true : false;
  this.IE4=(document.all && !document.getElementById)? true : false;
  this.IE5=(document.getElementById && document.all)? true : false;
  this.NS6=(document.getElementById && navigator.appName.indexOf('Netscape')>=0 )? true: false;
  this.W3C=(document.getElementById)? true : false;
  this.OPERA=(document.getElementById && navigator.appName.indexOf('Opera')>=0 )? true: false;

  this.mx = x;
  this.my = y;

  // Get HTLM-Layer-Object from name or from id
  this.obj = (this.NS4)? document.layers[xLayer] : (this.IE4)? document.all[xLayer] : (this.W3C)? document.getElementById(xLayer) : null;
  this.obj.width = parseInt(this.obj.style.width.substring(0,(this.obj.style.width.length - 2)),10) + 15; // Breite des Scrollbalken addieren.
  
  // Show, hide layer
  this.show_hide = function(){
    this.moveToKlickPos();
    if(this.W3C || this.IE4)
      this.obj.style.visibility = this.obj.style.visibility == 'visible' ? 'hidden' : 'visible';
    if(this.NS4)
      this.obj.visibility = this.obj.visibility == 'visible' ? 'hidden' : 'visible';

  }; // end show_hide


  // Show layer
  this.show = function(){
    this.moveToKlickPos();
    if(this.W3C || this.IE4)
      this.obj.style.visibility = 'visible';
    if(this.NS4)
      this.obj.visibility = 'visible';
  }; // end show


  // hide layer
  this.hide = function(){
    this.moveToKlickPos();
    if(this.W3C || this.IE4)
      this.obj.style.visibility = 'hidden';
    if(this.NS4)
      this.obj.visibility = 'hidden';
  }; // end hide


  // Move layer to mouse click position
  this.moveToKlickPos = function() {
    
    if(this.NS4){
     if((this.mx + this.obj.width) > window.innerWidth){
      	this.mx = window.innerWidth - this.obj.width;
      }
      this.obj.moveTo(this.mx + xoffset, this.my + yoffset);
    }
    
    if(this.W3C || this.IE4){
	   innerWidth = (document.body.offsetWidth-15);
		// Korrektur der Rechtspositionierung, damit das Popup nicht aus dem Fenster l?uft
	   if((this.mx + this.obj.width) > innerWidth){
      	this.mx = innerWidth - this.obj.width;
      }

      this.obj.style.left=(this.mx+xoffset)+'px';
      this.obj.style.top=(this.my+yoffset)+'px';
    }

  }; // end moveToKlickPos
  
  
  // Changes the Iframe location
  this.changeIFrame = function(xIFrame, xLocation){
		  ele = document.getElementsByName(xIFrame);
		  ele[0].src = xLocation;
		  
		  if(ele[0].src != ''){
			  return true;
		  }
		
		  return false;
		
  }; // end changeIFrame
  
} //end class DateLayer

var DLmx = 0;
var DLmy = 0;
var layObj = null;
var xoffset = 10;
var yoffset = 10;


/* Main Methode */
function showHide(xlayer) {
  layObj = new myLayer(xlayer, DLmx, DLmy);
  layObj.show_hide();
}

function show(xlayer) {
  layObj = new myLayer(xlayer, DLmx, DLmy);
  layObj.show();
}

function hide(xlayer) {
  layObj = new myLayer(xlayer, DLmx, DLmy);
  layObj.hide();
}


/* Alternativ Main Method */
function showHide2(xLayer, xIFrame, xLocation){
	layObj = new myLayer(xLayer, DLmx, DLmy);		
	if(layObj.changeIFrame(xIFrame, xLocation)){
		layObj.show_hide();
	}
}


//** Funktionen zu MouseEvent Stuerung **//
function scriptSniffer() {
  //Standard detection
  NS4=(navigator.appName.indexOf('Netscape')>=0 && !document.getElementById)? true : false;
  IE4=(document.all && !document.getElementById)? true : false;
  IE5=(document.getElementById && document.all)? true : false;
  NS6=(document.getElementById && navigator.appName.indexOf('Netscape')>=0 )? true: false;
  W3C=(document.getElementById)? true : false;
  OPERA=(document.getElementById && navigator.appName.indexOf('Opera')>=0 )? true: false;

  document.onmousedown=mouseClick;
}


function mouseClick(evt) {
  DLmx =(NS4||NS6||OPERA)? evt.pageX : (IE5||IE4)? (event.clientX + window.document.body.scrollLeft) : 0;
  DLmy =(NS4||NS6||OPERA)? evt.pageY : (IE5||IE4)? (event.clientY + window.document.body.scrollTop) : 0;
  if(layObj != null){
    if(layObj.obj.style.visibility == "visible") {
      layObj.mx = DLmx;
      layObj.my = DLmy;
      layObj.show_hide();
    }
  }
}// mouseClick

