if ( !self.SMM ) { self.SMM = new Object(); self.SMM.wcomp = new Object(); }
self.SMM.wcomp.gen = {
 DOMok: false,

 setup: function () {
	var o = this;
	o.DOMok = o.domtest();
	if ( o.DOMok && 'test'.match ) {
		o.suppXHTML = navigator.mimeTypes && ( navigator.mimeTypes['application/xhtml+xml'] != null );
		o.isXHTML = location.host && ( location.host.match( /^xhtml/ ) != null );
		var ua = navigator.userAgent;
		var res = ua.toLowerCase().match( 'msie ([567])');
		if ( ua && res ) {
			var IEver = res[1];
			var links = document.getElementsByTagName( 'a' );
			for ( var i = 0; i < links.length; i++ ) {
				var a = links[i];
				var rel = a.getAttribute( 'rel' );
				if ( rel && rel == 'external' && a.firstChild && a.firstChild.style ) {
					if ( IEver != 7 ) { a.onmouseover = o.onmouseover_link; a.onmouseout = o.onmouseout_link; }
					else {
						a.style.display = 'inline';
						if ( !a.getElementsByTagName( 'img' ) ) { a.style.verticalAlign = 'bottom'; }
						else { a.style.paddingBottom = '2px' }
					}
				}
			}
		}
	}
	for ( var prop in self.SMM.wcomp ) {
		var p = self.SMM.wcomp[ prop ];
		if ( p && p.run ) p.run();
	}
	if ( o.DOMok ) o.textify();
	var qs = location.search;
	if ( o.DOMok && !o.noHL && qs && qs.length > 1 && 'test'.match && 'test'.replace ) {
		var h = document.getElementsByTagName('head')[0];
		if ( !h ) return;
		var script = o.cElt( 'script' );
		script.setAttribute( "type", "text/javascript" );
		script.setAttribute( "src", "/js/highlight.js" );
		h.appendChild( script );
	}
 },

 domtest: function () {
	if ( !document.createElement && !document.createElementNS ) { return false }
	if ( !document.getElementById || !document.getElementsByTagName || !document.createTextNode ) { return false }
	var mm = document.getElementById( 'mm' );
	if ( !mm || !mm.className || mm.className != 'jstest' || !mm.getElementsByTagName || !mm.appendChild ||
		!mm.removeAttribute || !mm.setAttribute || !mm.getAttribute || !mm.firstChild ||
		!mm.firstChild.parentNode || mm.firstChild.parentNode != mm ) { return false }
	var uls = mm.getElementsByTagName( 'ul' );
	if ( !uls || !uls[1] || uls[1].tagName.toLowerCase() != 'ul' ) { return false }
	var testelt = uls[1];
	if ( testelt.getAttribute( 'id' ) ) { return false }
	testelt.id = 'testid';
	if ( !document.getElementById( 'testid' ) ) { return false }
	testelt.removeAttribute( 'id' );
	if ( document.getElementById( 'testid' ) ) { return false }
	if ( !document.documentElement ) { return false }
	this.ns = document.documentElement.getAttribute( 'xmlns' );
	if ( !this.ns ) return false;
	return true;
 },

 textify: function () {
	var o = this;
	var div = document.getElementById( 'adcont' );
	if ( !div || !div.cloneNode || !div.removeChild ) return;
	var p = div.getElementsByTagName( 'p' )[0];
	if ( !p ) return;
	var links = p.getElementsByTagName( 'a' );
	if ( !links ) return;
	var txtarr = new Array();
	for ( var i = 0; i < links.length; i++ ) {
		var a = links[i];
		var img = a.getElementsByTagName( 'img' )[0];
		if ( a.title && a.href && ( !img || ( window.getComputedStyle && window.getComputedStyle( img, null ).display == 'none' ) || img.height == 0 ) ) {
			txtarr[ txtarr.length ] = [ a.href, a.title ];
		}
	}
	if ( txtarr[0] ) {
		var extc = links[0].getElementsByTagName( 'span' )[0];
		var par = p.parentNode;
		par.removeChild( p );
		var p2 = o.cElt( 'p' );
		for ( var j = 0; j < txtarr.length; j++ ) {
		    var a = o.cElt( 'a' );
		    a.setAttribute( 'rel', 'external' );
		    a.appendChild( extc.cloneNode(1) );
		    a.href = txtarr[j][0];
		    o.aTxt( a, txtarr[j][1] );
		    p2.appendChild( a );
		    if ( j < ( txtarr.length - 1 ) ) { o.aTxt( p2, ', ' ); }
		    else { o.aTxt( p2, '.' ); }
		}
		par.appendChild( p2 );
	}
 },

 cElt: function ( eltname, id, cls, txt ) {
	var o = this;
	var elt;
	if ( document.createElementNS && o.ns ) { elt = document.createElementNS( o.ns, eltname ) }
	else { elt = document.createElement( eltname ) }
	if ( id ) { elt.id = id }
	if ( cls ) { elt.className = cls }
	if ( txt ) { o.aTxt( elt, txt ) }
	return elt;
 },

 aTxt: function ( elt, txt ) {
	elt.appendChild( document.createTextNode( txt ) );
 },

 norm_ws: function ( inp ) {
	if ( inp == null ) return '';
	var val = inp;
	if ( inp.tagName ) val = inp.value;
	if ( val.replace ) {
		val = val.replace( /\s+/g, ' ' );
		val = val.replace( /^ /, '' );
		val = val.replace( / $/, '' );
		if ( inp.tagName ) inp.value = val;
	}
	return val;
 },

 onmouseover_link: function () {
	var ss = this.firstChild.style;
	ss.color= '#fff';
	ss.backgroundColor = '#900';
 },

 onmouseout_link: function () {
	var ss = this.firstChild.style;
	ss.color= '#000';
	ss.backgroundColor = '#fff';
 },

 onload_window:	function () { if ( arguments.callee.done ) { return }; arguments.callee.done = true; self.SMM.wcomp.gen.setup(); },
 onload_fallback: function () { window.setTimeout( 'self.SMM.wcomp.gen.onload_window()', 100 ); },
 set_onload_window: function () {
	if ( window.addEventListener ) { window.addEventListener( 'DOMContentLoaded', this.onload_window, false ); window.addEventListener( 'load', this.onload_fallback, false ) }
	else if ( window.attachEvent ) { window.attachEvent( 'onload', this.onload_window ) }
 }
};
self.SMM.wcomp.gen.set_onload_window();
