Index: typo3/alt_db_navframe.php
===================================================================
--- typo3/alt_db_navframe.php	(revision 2834)
+++ typo3/alt_db_navframe.php	(working copy)
@@ -139,9 +139,9 @@
 			$this->doc->backPath = $BACK_PATH;
 			$this->doc->docType = 'xhtml_trans';
 
-				// Adding javascript code for AJAX (prototype), drag&drop and the pagetree
-			$this->doc->loadJavascriptLib('contrib/prototype/prototype.js');
-			$this->doc->loadJavascriptLib('tree.js');
+				// Adding javascript code for AJAX (prototype), drag&drop and the pagetree as well as the click menu code
+			$this->doc->getDragDropCode('pages');
+			$this->doc->getContextMenuCode();
 
 			$this->doc->JScode .= $this->doc->wrapScriptTags(
 			($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
@@ -149,10 +149,6 @@
 			Tree.thisScript    = "'.$this->pagetree->thisScript.'";
 			'.($this->doHighlight ? 'Tree.highlightClass = "'.$hlClass.'";' : '').'
 
-			DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
-			DragDrop.backPath  = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
-			DragDrop.table     = "pages";
-
 			// Function, loading the list frame from navigation tree:
 			function jumpTo(id, linkObj, highlightID, bank)	{ //
 				var theUrl = top.TS.PATH_typo3 + top.currentSubScript + "?id=" + id;
@@ -168,8 +164,6 @@
 			'.($this->cMR?"jumpTo(top.fsMod.recentIds['web'],'');":'').'
 			');
 
-				// Click menu code is added:
-			$this->doc->getContextMenuCode();
 			$this->doc->bodyTagId = 'bodyTag';
 		}
 	}
@@ -255,7 +249,7 @@
 		$this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH']);
 
 			// Adding javascript for drag & drop activation and highlighting
-		$this->content .=$this->doc->wrapScriptTags('
+		$this->content .= $this->doc->wrapScriptTags('
 			'.($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '').'
 			'.(!$this->doc->isCMlayers() ? 'Tree.activateDragDrop = false;' : 'Tree.registerDragDropHandlers();')
 		);
Index: typo3/alt_file_navframe.php
===================================================================
--- typo3/alt_file_navframe.php	(revision 2834)
+++ typo3/alt_file_navframe.php	(working copy)
@@ -118,10 +118,9 @@
 			$this->doc->backPath = $BACK_PATH;
 			$this->doc->docType = 'xhtml_trans';
 
-				// Adding javascript code for AJAX (prototype), drag&drop and the pagetree
-			$this->doc->JScode  = '
-			<script type="text/javascript" src="'.$this->backPath.'contrib/prototype/prototype.js"></script>
-			<script type="text/javascript" src="'.$this->backPath.'tree.js"></script>'."\n";
+				// Adding javascript code for AJAX (prototype), drag&drop and the filetree as well as the click menu code
+			$this->doc->getDragDropCode('folders');
+			$this->doc->getContextMenuCode();
 
 				// Setting JavaScript for menu.
 			$this->doc->JScode .= $this->doc->wrapScriptTags(
@@ -129,9 +128,6 @@
 
 			// setting prefs for pagetree and drag & drop
 			Tree.thisScript    = "'.$this->foldertree->thisScript.'";
-			DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
-			DragDrop.backPath  = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
-			DragDrop.table     = "folders";
 
 			// Function, loading the list frame from navigation tree:
 			function jumpTo(id, linkObj, highlightID, bank)	{
@@ -147,9 +143,6 @@
 			}
 			'.($this->cMR ? " jumpTo(top.fsMod.recentIds['file'],'');" : '')
 			);
-
-				// Click menu code is added:
-			$this->doc->getContextMenuCode();
 		}
 	}
 
Index: typo3/template.php
===================================================================
--- typo3/template.php	(revision 2834)
+++ typo3/template.php	(working copy)
@@ -1275,11 +1275,33 @@
 			       Clickmenu.clickURL = "'.$this->backPath.'alt_clickmenu.php";
 			       Clickmenu.ajax     = '.($this->isCMLayers() ? 'true' : 'false' ).';';
 
-			       // return array deprecated since 4.2
+		       // return array deprecated since 4.2
 	       return array('','','');
 	}
 
+	/**
+	 * Includes the necessary javascript file (tree.js) for use on pages which have the
+	 * drag and drop functionality (usually pages and folder display trees)
+	 *
+	 * @param	string		indicator of which table the drag and drop function should work on (pages or folders)
+	 * @return	array		If values are present: [0] = A <script> section for the HTML page header, [1] = onmousemove/onload handler for HTML tag or alike, [2] = One empty <div> layer for the follow-mouse drag element
+	 */
+	function getDragDropCode($table)	{
+		$this->loadJavascriptLib('contrib/prototype/prototype.js');
+		$this->loadJavascriptLib('tree.js');
 
+			// setting prefs for drag & drop
+		$this->JScodeArray['dragdrop'] = '
+			DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
+			DragDrop.backPath  = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
+			DragDrop.table     = "'.$table.'";
+		';
+
+		       // return array deprecated since 4.2
+	       return array('','','');
+	}
+
+
 	/**
 	 * Creates a tab menu from an array definition
 	 *
