/*
	mozileLinks.js
	
	Convert links when docs are displayed on the web.
	
	links with a "class" attribute containing the string "ulink" will be converted.
	(Should really extend this to work from chrome AND local directories as well.
	
Mozile www file locations:
http://www.mozdev.org/source/browse/mozile/source/extension/mozile-0.6/content/

Note that skin and locale have special chrome handling.
The subdirectories /classic/ and /en-US/ can't be accessed.

http://www.mozdev.org/source/browse/mozile/source/extension/mozile-0.6/skin/classic/
http://www.mozdev.org/source/browse/mozile/source/extension/mozile-0.6/locale/en-US/
	
*/
function mozileUpdateLinks() {
	var mozileDocsURL = "mozile.mozdev.org/0.6/";
//	var mozileDocsURL = "Mozile625/chrome/mozile/";
	var mozileSrcURL = "http://www.mozdev.org/source/browse/mozile/source/extension/mozile-0.6/";
	var REskin = /\/skin\//;
	var RElocale = /\/locale\//;
	var skin = "/skin/classic/";
	var locale = "/locale/en-US/";
	
	/*
		Convert link href urls when loaded from the Mozile web site.
	*/
	if (this.location.href.indexOf(mozileDocsURL) != -1 ) {
		var anchors = this.document.getElementsByTagName("a");
		var c,href,href2,s,re;
		for ( var i=0; i<anchors.length; i++ ) {
			c = anchors[i].className;
			if ( (c != null) && (c != "") ) {
				if ( c.indexOf( "ulink" ) != -1 ) {
					href = anchors[i].href;
					if ( href ) {
						re = /\\/g;
						href = href.replace( re, "/" );
						s = href.indexOf( mozileDocsURL );
						if ( s != -1 ) {
							href2 = href.slice( s+mozileDocsURL.length );
							if ( href2 != "" ) {
								href2 = mozileSrcURL + href2;
								//Replace chrome paths with real paths.
								href2 = href2.replace( REskin, skin );
								href2 = href2.replace( RElocale, locale );
								anchors[i].href = href2;
							}
						}
					}
				}
			}
		}
	}
}

