/* =========================================================================
[ Datum      ]   09.09.01
[ Autor      ]   Johannes Gamperl <info@jg-webdesign.de>
[ Website    ]   http://www.jg-webdesign.de || http://www.devshare.de
[ Skriptname ]   DevContext v1.0d
[ Browser    ]   netscape [4.51, 4.7, 6.1], explorer [5.5, 6.0], opera [n/a]
============================================================================
[ Info       ]
   Sie können diesen Skript frei für Ihre Zwecke verwenden, solange 
   alle darin enthaltenen Kommentare erhalten bleiben. 
   Copyright (c) 2001 Johannes Gamperl, Alle Rchte vorbehalten
========================================================================= */



// Konstruktor für die Menüeigenschaften des Contextmenüs
// --------------------------------------------------------------------------	
function menuPanel(titel,icon,status,href,color1,color2) {
// --------------------------------------------------------------------------	
	this.titel  = titel;
	this.icon   = icon;
	this.status = status;
	this.href   = href;
	this.color1 = color1;
	this.color2 = color2;
}

// Konstruktor für den Menü-Array des Contextmenüs
// --------------------------------------------------------------------------	
function setMenuPanel(width,color,status) {
// --------------------------------------------------------------------------	
	this.width  = width;
	this.color  = color;
	this.status = status;
	this.menuArray = new Array();
}	


// setMenu pusht die einzelnen Menüs des Contextmenüs in ein Array
// --------------------------------------------------------------------------	
setMenuPanel.prototype.setMenu = function(titel,icon,status,href,farbe1,farbe2) {
// --------------------------------------------------------------------------	
  this.menuArray[this.menuArray.length] = new menuPanel(titel,icon,status,href,farbe1,farbe2);
}


// printMenuPanel zeichnet das Contextmenü in eine unsichtbare Ebene
// --------------------------------------------------------------------------	
setMenuPanel.prototype.printMenuPanel = function() {
// --------------------------------------------------------------------------	
  var html = '<TABLE WIDTH="' +this.width+ '" BORDER="0" CELLSPACING="3" CELLPADDING="0" BGCOLOR="' +this.color+ '">\n';
  for (i in this.menuArray) {
    var icon = (this.menuArray[i].icon) ? this.menuArray[i].icon : "dummy"; 
	html += (!this.menuArray[i].titel) 
	        ?
	        '<TR><TD><IMG SRC="images/pixel.gif" WIDTH="' +this.width+ '" HEIGHT="1" BORDER="0"></TD></TR>'
	        :
            '<TR>\n'+
	        '  <TD NOWRAP onmouseover="context.zelleAktiv(this,' +i+ ')" onmouseout="context.zellePassiv(this,' +i+ ')">\n'+
	        '  <ILAYER WIDTH="100%">'+
		    '  <LAYER NAME="__cell' +i+ '__" WIDTH="100%" onmouseover="context.zelleAktiv(this,' +i+ ');" onmouseout="context.zellePassiv(this,' +i+ ')">'+
		    '  <IMG SRC="images/' +icon+ '.gif" WIDTH="12" HEIGHT="12" VSPACE="0" BORDER="0" ALT="' +this.menuArray[i].status+ '"> <A '+
			'  HREF="' +this.menuArray[i].href+ '" TITLE="' +this.menuArray[i].status+ '">'
		       +this.menuArray[i].titel+ '</A></LAYER>'+
		    '  </ILAYER>'+
		    '  </TD>\n'+
		    '</TR>\n';
  } html += '</TABLE>';
  return html;
}


// Zellenfarbe eines Menüeintrages bei mouseover setzen 
// --------------------------------------------------------------------------
setMenuPanel.prototype.zelleAktiv = function(zelle,i) {
// --------------------------------------------------------------------------
  zelle.bgColor = this.menuArray[i].color1;
  status = this.menuArray[i].status;
}


// Zellenfarbe eines Menüeintrages bei mouseout setzen 
// --------------------------------------------------------------------------
setMenuPanel.prototype.zellePassiv = function(zelle,i) {
// --------------------------------------------------------------------------
  zelle.bgColor = this.menuArray[i].color2;
  status = this.menuArray[i].status;
}


// Rechte Maustaste deaktivieren und eigenes Contextmenü zeigen
// --------------------------------------------------------------------------		  
function menu(e) {
// --------------------------------------------------------------------------
  if (document.all) {
    if (event.button==2||event.button==3) { // IE 4.x
        var x = event.clientX;
	    var y = event.clientY;
    	topm.style.left  = x;		
	 	topm.style.top = y;
	    topm.style.visibility = "visible";
        return false;
    }
  }
  
  if (document.layers) {
    if (e.which==2||e.which==3) {
        status = context.status;             // Text für Statuszeile setzen	
        var x  = e.pageX+2;                  // akt. Mausposition auslesen (x);
		var y  = e.pageY+2;                  // akt. Mausposition auslesen (y);
        if (x+ context.width > window.innerWidth) x = x-context.width-10;
	    document.topm.moveTo(x,y);           // Eigenes Contextmenü positionieren
	    document.topm.visibility = "show";   // Eigenes Contextmenü anzeigen
		return false;                        // Echtes Contextmenü unterdrücken
	}
  }
  
  if (document.getElementById && !document.all) {
    if (e.which==2||e.which==3) {
        status = context.status;             // Text für Statuszeile setzen	
        var x  = e.pageX-2;                  // akt. Mausposition auslesen (x);
		var y  = e.pageY-2;                  // akt. Mausposition auslesen (y);
        if (x+ context.width > window.innerWidth) x = x-context.width-10;
    	document.getElementById("topm").style.left  = x;		
	 	document.getElementById("topm").style.top = y;
	    document.getElementById("topm").style.visibility = "visible";   // Eigenes Contextmenü anzeigen
		return false;                        // Echtes Contextmenü unterdrücken
	}
  }  
}


// Eigenes Contextmenü zum Verbergen vorbereiten
// --------------------------------------------------------------------------
function menuClose() {
// --------------------------------------------------------------------------
  if (document.layers) document.topm.visibility = "hide"; 
  if (document.all) topm.style.visibility = "hidden";
  if (document.getElementById && !document.all) document.getElementById("topm").style.visibility = "hidden";
  status = "";
}
function menuCloseIE() {
  setTimeout('menuClose()',100);
}


// Events setzen 
// --------------------------------------------------------------------------
  document.onmousedown = menu;
  (document.layers) ? document.onclick = menuClose : document.onclick = menuCloseIE;
  (document.layers) ? window.onblur  = menuClose : window.onblur  = menuCloseIE;
