Index: typo3/sysext/cms/tslib/media/scripts/tmenu_layers.php
===================================================================
--- typo3/sysext/cms/tslib/media/scripts/tmenu_layers.php	(revision 9210)
+++ typo3/sysext/cms/tslib/media/scripts/tmenu_layers.php	(working copy)
@@ -353,9 +353,12 @@
 			$this->divLayers['iframe'] = '<iframe id="Iframe'.$this->WMid.'" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; background-color:transparent; layer-background-color:transparent; display:none;"></iframe>';
 		}
 		$GLOBALS['TSFE']->applicationData['GMENU_LAYERS']['WMid']=array_merge($this->WMtempStore,$GLOBALS['TSFE']->applicationData['GMENU_LAYERS']['WMid']);
-		$GLOBALS['TSFE']->additionalHeaderData['gmenu_layer_shared']='<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath('cms').'tslib/media/scripts/jsfunc.layermenu.js"></script>';
-		$GLOBALS['TSFE']->JSCode.= '
 
+		$jsFuncLayerFile = t3lib_extMgm::siteRelPath('cms') . 'tslib/media/scripts/jsfunc.layermenu.js';
+		$pageRender = $GLOBALS['TSFE']->getPageRenderer();
+		$pageRender->addJsFile($jsFuncLayerFile, $type='text/javascript', $compress=TRUE, $forceOnTop=FALSE, $allWrap='');
+
+		$this->JScode .= '
 GLV_curLayerWidth["'.$this->WMid.'"]=0;
 GLV_curLayerHeight["'.$this->WMid.'"]=0;
 GLV_curLayerX["'.$this->WMid.'"]=0;
@@ -378,7 +381,7 @@
 '.$this->WMrestoreVars;
 
 		if ($this->mconf['freezeMouseover'])	{
-			$GLOBALS['TSFE']->JSCode.= '
+			$this->JScode .= '
 // Alternative rollover/out functions for use with GMENU_LAYER
 function GL'.$this->WMid.'_over(mitm_id)	{
 	GL'.$this->WMid.'_out("");	// removes any old roll over state of an item. Needed for alwaysKeep and Opera browsers.
@@ -395,7 +398,7 @@
 }
 ';
 		}
-		$GLOBALS["TSFE"]->JSCode.= '
+		$this->JScode .= '
 function GL'.$this->WMid.'_getMouse(e) {
 	if (GLV_menuOn["'.$this->WMid.'"]!=null && !GLV_dontFollowMouse["'.$this->WMid.'"]){
 '.implode(LF,$GLV_menuOn).'
@@ -430,6 +433,13 @@
 		$GLOBALS['TSFE']->JSeventFuncCalls['onmouseup'][$this->WMid]= 'GL_mouseUp(\''.$this->WMid.'\',e);';
 
 		$GLOBALS['TSFE']->divSection.=implode($this->divLayers,LF).LF;
+		
+		if ($this->mconf['layer_menu_id']) {
+			$inline2TempFile = TSpagegen::inline2TempFile($this->JScode,'js');
+			$pageRender->addJsFile($inline2TempFile, $type='text/javascript', $compress=TRUE, $forceOnTop=FALSE, $allWrap='');
+		} else {
+			$GLOBALS['TSFE']->JSCode .= $this->JScode;
+		}
 
 		return parent::extProc_finish();
 	}
Index: typo3/sysext/cms/tslib/media/scripts/gmenu_layers.php
===================================================================
--- typo3/sysext/cms/tslib/media/scripts/gmenu_layers.php	(revision 9210)
+++ typo3/sysext/cms/tslib/media/scripts/gmenu_layers.php	(working copy)
@@ -353,9 +353,12 @@
 			$this->divLayers['iframe'] = '<iframe id="Iframe'.$this->WMid.'" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; background-color:transparent; layer-background-color:transparent; display:none;"></iframe>';
 		}
 		$GLOBALS['TSFE']->applicationData['GMENU_LAYERS']['WMid']=array_merge($this->WMtempStore,$GLOBALS['TSFE']->applicationData['GMENU_LAYERS']['WMid']);
-		$GLOBALS['TSFE']->additionalHeaderData['gmenu_layer_shared']='<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath('cms').'tslib/media/scripts/jsfunc.layermenu.js"></script>';
-		$GLOBALS['TSFE']->JSCode.= '
 
+		$jsFuncLayerFile = t3lib_extMgm::siteRelPath('cms') . 'tslib/media/scripts/jsfunc.layermenu.js';
+		$pageRender = $GLOBALS['TSFE']->getPageRenderer();
+		$pageRender->addJsFile($jsFuncLayerFile, $type='text/javascript', $compress=TRUE, $forceOnTop=FALSE, $allWrap='');
+
+		$this->JScode .= '
 GLV_curLayerWidth["'.$this->WMid.'"]=0;
 GLV_curLayerHeight["'.$this->WMid.'"]=0;
 GLV_curLayerX["'.$this->WMid.'"]=0;
@@ -378,7 +381,7 @@
 '.$this->WMrestoreVars;
 
 		if ($this->mconf['freezeMouseover'])	{
-			$GLOBALS['TSFE']->JSCode.= '
+			$this->JScode .= '
 // Alternative rollover/out functions for use with GMENU_LAYER
 function GL'.$this->WMid.'_over(mitm_id)	{
 	GL'.$this->WMid.'_out("");	// removes any old roll over state of an item. Needed for alwaysKeep and Opera browsers.
@@ -395,7 +398,7 @@
 }
 ';
 		}
-		$GLOBALS["TSFE"]->JSCode.= '
+    	$this->JScode .= '
 function GL'.$this->WMid.'_getMouse(e) {
 	if (GLV_menuOn["'.$this->WMid.'"]!=null && !GLV_dontFollowMouse["'.$this->WMid.'"]){
 '.implode(LF,$GLV_menuOn).'
@@ -430,6 +433,13 @@
 		$GLOBALS['TSFE']->JSeventFuncCalls['onmouseup'][$this->WMid]= 'GL_mouseUp(\''.$this->WMid.'\',e);';
 
 		$GLOBALS['TSFE']->divSection.=implode($this->divLayers,LF).LF;
+		
+		if ($this->mconf['layer_menu_id']) {
+			$inline2TempFile = TSpagegen::inline2TempFile($this->JScode, 'js');
+			$pageRender->addJsFile($inline2TempFile, $type='text/javascript', $compress=TRUE, $forceOnTop=FALSE, $allWrap='');
+		} else {
+			$GLOBALS['TSFE']->JSCode .= $this->JScode;
+		}
 
 		return parent::extProc_finish();
 	}
