// ==UserScript==
// @name msdn.microsoft.com - MSDN extras
// @author TarquinWJ 
// @namespace http://www.howtocreate.co.uk/ 
// @version 1.0
// @description  Adds some enhancements to the MSDN reference site fix.
// @ujs:category site: enhancements
// @ujs:published 2005-06-16 23:41
// @ujs:modified 2005-09-19 09:19
// @ujs:documentation http://userjs.org/scripts/site/enhancements/msdn-extras 
// @ujs:download http://userjs.org/scripts/download/site/enhancements/msdn-extras.js 
// @include http://msdn.microsoft.com/workshop/*
// ==/UserScript==


/* 
 * Please see
 * http://www.howtocreate.co.uk/operaStuff/userJavaScript.html#terms
 * for License and Terms of Use
 */

//set table compacting option here
// - true compacts tables like MSDN normally does in IE (looks good, but is less accessible)
// - false leaves all tables visible, and just fixes the version notes, and the demo buttons
var canCompactMSDNTables = true;

//if canCompactMSDNTables is 'true', you can also set the following option
// - true allows the tables to be toggled between default and compacted - duplicates table data if CSS is disabled
// - false table remains compacted
var canToggleMSDNTables = true;

//set forced frame option here
// - true allows the page to force the frameset to be displayed
// - false allows pages to be displayed without a frameset (sync toc will not work - if you care ...)
var canForceFrames = false;

// - - - - - begin the main part of the script - - - - -

//remove the fixed script that forces pages to be displayed in a frameset - this is one fix we can do without
if( !canForceFrames ) {
	opera.defineMagicFunction('PreInit',function () {});
}

opera.addEventListener(
	'BeforeScript',
	function (e) {
		var oJs = e.element.text;
		var oSr = e.element.getAttribute('src');

		if( oSr && oSr.match(/members\.js$/) ) {
			//members.js fixes

			//option to disable compacting of tables - this is not part of the fix, it is just nice to have the option
			if( !canCompactMSDNTables ) {
				oJs = oJs.replace(/function\s*initTabbedMembers\s*\(\s*\)\s*{/,'function initTabbedMembers() { return;');
			} else if( canToggleMSDNTables ) {
				window.getAFullListOfDivs = [];
				window.switchCompView = function () {
					for( var i = 0; getAFullListOfDivs[i]; i++ ) {
						getAFullListOfDivs[i].style.display = ( getAFullListOfDivs[i].style.display == 'none' ) ? '' : 'none';
					}
					var oTS = oMT.parentNode.getElementsByTagName('table')[0].style;
					oTS.display = ( oTS.display == 'none' ) ? '' : 'none';
					var oTS = this.parentNode.nextSibling.style;
					this.firstChild.nodeValue = ( oTS.display == 'none' ) ? '[+] Expand tables' : '[-] Collapse tables';
					oTS.display = ( oTS.display == 'none' ) ? '' : 'none';
					return false;
				};
				oJs = oJs.replace(/function\s*initTabbedMembers\s*\(\s*\)\s*{\s*if\(document\.getElementById\(\"oMT\"\)\)\{/,'function initTabbedMembers() {\n\tif(document.getElementById(\"oMT\")){var Pblat = document.createElement(\'p\');oMT.parentNode.insertBefore(Pblat,oMT.parentNode.firstChild);Pblat.appendChild(Pblat=document.createElement(\'a\'));Pblat.appendChild(document.createTextNode(\'[+] Expand tables\'));Pblat.setAttribute(\'href\',\'#\');Pblat.onclick = switchCompView;');
				oJs = oJs.replace(/new CTabber\(div\);/,'new CTabber(div.cloneNode(true));\ngetAFullListOfDivs[getAFullListOfDivs.length]=div;');
			}
		}

	},
	false
);

//the table at the bottom will remain a little bit odd because of an Opera bug
// - colspan ignored on dynamically generated cells
