var gnID;
var gnLev;
var gnParentID;
var gnL = -1
var gnLastID;
var gnLastParentID;
var gnLevelOneID;
var gnLastL = -1
var gnUrlUID = -1;
var gnShowMenuID = -1;
var gnTimeoutID;
var gaoMenus = new Array();
var gnWindow = 0;
var goBODYMENU = null;
var goTotalBODYMENU = null;

function SET_gnID( nID ) {
	gnID = nID;
}
function SET_gnL( nL ) {
	if( arguments.length > 0 )
		gnL  = nL;
}
function SET_gnLev( nLev ) {
	if( arguments.length > 0 )
		gnLev  = nLev;
}
function SET_gnParentID( nID ) {
	if( arguments.length > 0 )
		gnParentID  = nID;
}
function SET_gnLevelOneID( nID ) {
	if( arguments.length > 0 )
		gnLevelOneID  = nID;
	else
		gnLevelOneID  = 0;
	if( pgMiddleTop.updateMenuVS ) pgMiddleTop.updateMenuVS( nID );
}

function SET_gnUrlUID(nUrlUID) {
	if( arguments.length > 0 )
		gnUrlUID = nUrlUID;
}

function ContentOnLoad() {
	var e1, e, eTop, new_url, loc, id;
 	gnLastID = gnID;
 	gnLastL = gnL;
	/*
	 *	20061207, __DT__:
	 *
	 * 	race-condition: ggf. kann es passieren dass der content schon geladen ist aber pgBottom noch leer
	 *	 				ist. Dann enthaelt pgBottom.location ggf. 'about:blank' !!!
	 */
	// achtung simulatedDocs, geht jetzt nicht mehr:	pgBottom.location.replace(pgBottom.location+'&id='+gnID+'&type=301&L='+gnL);
	if(top.pgBottom.gLoadedComplete) {  // wird gesetzt wenn pgBottom geladen ist ...
		loc = pgBottom.location;
		id = gnID;
		if (String(loc.search).search(/\id=\d+/)!=-1) {
			new_url = String(loc);
			if (new_url && (id>-1)) {
				new_url = new_url+'&id='+id+'&type=301'; 
			}
		} else {
			if(id>-1) {
				new_url = String(loc).replace(/\d+\.\d+\.html/, String(id)+".301.html");
			} else {
				new_url = String(loc).replace(/\.\d+\.html/, ".301.html");
			}
		}
		new_url = String(new_url);
		new_url = new_url.replace(/&L=\d*/g, '&L='+gnL); 
		pgBottom.location.replace(new_url);
	} 
	//pgBottom.location.replace(pgBottom.location+'&id='+gnID+'&type=301&L='+gnL);
	// eTop = pgContent.document.getElementById( 'TopImage' );
   	// if( eTop ) eTop.focus();		
}

function ContentOnUnload() {
	HideAll( -1 );
//	alert( 'beppi' );
}

function NotInMenuContentOnLoad() {
    var oMyBODYMENU;
	var oParent = null;
	var e1;
	//alert(goTotalBODYMENU);
	if( gnL >= 0 ) 
		parent.pgBottomMessage.location.replace('index.php?id='+gnID+'&type=301&L='+gnL);
	else 
		parent.pgBottomMessage.location.replace('index.php?id='+gnID+'&type=301');

	if( !goTotalBODYMENU ) return false;
	try{
		oMyBODYMENU = parent.pgContent.document.getElementById( 'BODYMENU' );
		//alert( oMyBODYMENU );
		if( oMyBODYMENU ) oParent = oMyBODYMENU.parentNode;
	}
	catch(e1) {return false;}
	//alert(oParent);
	if( oParent ) oParent.replaceChild( goTotalBODYMENU, oMyBODYMENU );		
}

function HideSubmenu( nUseTimeout, nMenuID, nWindow ) {
 	var e, e1, elem;
	if( nMenuID == -1 )
		HideAll( -1 );
	else {
	    if( nWindow != gnWindow && gnWindow != 0 )
			return;
		if( nUseTimeout == 0 ) {
//  	    alert( 'Timeout Ended' );
			if( gaoMenus[nMenuID] ) {
				if( gaoMenus[nMenuID].timoutID )
			 		clearTimeout( gaoMenus[nMenuID].timoutID );
	    		try{
      				elem = pgContent.document.getElementById( 'MENU'+nMenuID );
					elem.style['visibility'] = 'hidden';
					elem.style['opacity']    = '.95';
					elem.style['filter']     = 'alpha(opacity=95)';
					// elem.style['MozOpacity']  = '0.8'; /* f. NS 6+ */
				} catch(e){ ; }			
/*				if( pgContentNavi && pgContentNavi.outVS )
					pgContentNavi.outVS(1,nMenuID); */
/*				if( gaoMenus[nMenuID].onmouseout ) {
					try{
						elem = pgContentNavi.document.getElementById( 'MENUITEM'+nMenuID );
						elem.firstChild.onmouseout = gaoMenus[nMenuID].onmouseout;
 						gaoMenus[nMenuID].onmouseout = null;
						elem.firstChild.onmouseout.call();
					} catch(e1)	{ ; }			
				}*/
				gaoMenus[nMenuID].visible  = 0;
				gaoMenus[nMenuID].timoutID = null;
				gnShowMenuID = -1;
			} 		
		}
   		else {
			if( gaoMenus[nMenuID] ) {
				gaoMenus[nMenuID].timoutID = setTimeout('HideSubmenu( 0,'+nMenuID+','+nWindow+')', nUseTimeout * 1000);
	    		try{
      				elem = pgContent.document.getElementById( 'MENU'+nMenuID );
					elem.style['opacity'] = '.95';
					elem.style['filter']  = 'alpha(opacity=95)';
					// elem.style['MozOpacity']  = '0.8'; /* f. NS 6+ */
				} catch(e){ ; }
			}
   		}
   }
}

function StopTimeout( nWindow, nMenuID ) {
	var elem, eTop;
	var e1;
	for( n = 0; n < gaoMenus.length; n++ ) {
		if( gaoMenus[n] ) {
			if( gaoMenus[n].timoutID )
			 	clearTimeout( gaoMenus[n].timoutID );
			gaoMenus[n].timoutID = null;
		}
	}
	gnWindow = nWindow;
	if( nMenuID ) {
		try{
			elem = pgContent.document.getElementById( 'MENU'+nMenuID );
			elem.style['opacity'] = '1.0'; /* css3 */
			elem.style['filter']  = 'alpha(opacity=100)'; /* f. IE 6 */
			// elem.style['-moz-opacity']  = '1.0'; /* f. NS 6+ */
			// elem.style['MozOpacity']  = '1.0'; /* f. NS 6+ */
			eTop = pgContent.document.getElementById( 'TopImage' );
          	if( eTop ) eTop.focus();		  
		} catch(e1) {;}
	}
//	alert(nWindow);
}


function ShowSubmenu( e, nMenuID, nHeight ) {
  	var elem, elemMaster;
	var e1, e2;
	var nOffsetX = e.srcElement ? e.srcElement.offsetLeft : e.target.offsetLeft;
	var nY, nX, nMenuOffset;
//	alert('URL'+parent.locationbar.URL);
	if( e.srcElement && e.srcElement.offsetLeft == 0 && e.srcElement.parentNode )
		// nOffsetX = e.srcElement.parentNode.offsetLeft;
		nOffsetX = e.srcElement.offsetParent.offsetLeft;
	nY = pgContent.document.body.scrollTop;
	nX = nOffsetX + 100 + pgContent.document.body.scrollLeft;
//	alert( nX );
	StopTimeout( 0 );
	HideAll( nMenuID );
	try{
		/* */
		/* geht leider nicht im IE */
/*		focuscatcher = pgContent.document.getElementById('focuscatcher');
		if (focuscatcher) {
			// focuscatcher.focus();
			// focuscatcher.onclick();
		}  */
		/**/
		/*************/
		elem = pgContent.document.getElementById( 'MENU'+nMenuID );
		if(elem) {	
			elem.style['visibility'] = 'visible';
			elem.style['top']  		 = nY + 'px';
			elem.style['left']  	 = nX + 'px';
		}
		/* */
		/* ll = elem.getElementsByTagName("a");
		if(ll) {
			ll[0].focus();
		}*/
		/*****/
		if( ! gaoMenus[nMenuID] )
			gaoMenus[nMenuID] = new Object(); 
		gaoMenus[nMenuID].visible  = 1;
		gaoMenus[nMenuID].top      = nY;
		gaoMenus[nMenuID].timoutID = null;
		gnShowMenuID = nMenuID;
/*		try{
			elem = pgContentNavi.document.getElementById( 'MENUITEM'+nMenuID );
			if( !gaoMenus[nMenuID].onmouseout )
				gaoMenus[nMenuID].onmouseout = elem.firstChild.onmouseout;
			elem.firstChild.onmouseout = elem.firstChild.onmouseover;
		} catch(e2)	{ ; }	*/		
	} catch(e1)	{
		gnShowMenuID = -1;
	}
	gnWindow = 2;
}

function HideAll( nMenuNohide ) {
	for( n = 0; n < gaoMenus.length; n++ ) {
		if( n != nMenuNohide && gaoMenus[n] ) 
			HideSubmenu( 0, n, gnWindow );
	}
}

function dumpDebugInfos() {

// ----------------------
var sDump = new String();
confirm( ' gaoMenus[] = '+gaoMenus.toString() );
 
for( s in gaoMenus ) {
    sDump = sDump + ' ['+s+'] = '+gaoMenus[s];
}
confirm( sDump );
// ----------------------

}

