YUI().use('node', 'event-custom', function(Y) {
	var hasFont = function(sFont) {
		// this function working with XHTML 1.0 *strict* mode
		// tested in Win IE6, Opera 9, Firefox 1.5; Mac Safari 2.03
		// -haven't tested in browser quirks mode
		// Function can not match Courier since that is
		// the control font for comparison

		/* Create an element (id=tp_fillFont) if doesn't
		exist yet so I can paste some hidden content inside */   
		var ns = "com_tp_"; 
		var d = document; var b = d.body;
		var o; // object holder
		var eWriteDiv = d.getElementById(ns + 'fillFont');
		if (!eWriteDiv) {
			o = d.createElement('div');
			o.setAttribute('id', ns + 'fillFont');
			eWriteDiv = b.appendChild(o);
		}	// ================================================
		var oSpan = [];
		// can't use Courier or STFangsong as test fonts, as they are acting
		// as the control fonts.  This function needs to be updated when new
		// browsers and OSes are realeased as it's hard to know what Unicode Tibetan
		// font the browser will default to.

		// it appears that I don't need to have space-having fontnames in quotes
		// when I do this in JavaScript

		// improved for Leopard's 2 built in Tibetan fonts
		var sMacControlFont = "Kokonor, Kailasa, STFangsong";	
		if (sFont == "Kokonor") {
			sMacControlFont = "Kailasa, STFangsong";
		}
		if (sFont == "Kailasa") {
			sMacControlFont = "Kokonor, STFangsong";
		}

		// CHANGE THINGS SO THAT I DO NOT ADDED TIBETAN STYLING TO THIS WITH LATER FUNCTIONS!
		var aFontFamilies = [ sMacControlFont + ', Courier', (sFont + ", " + sMacControlFont + ", Courier")];
		var aFontIds = [ns + 'fontControl', ns + 'fontTest'];
		var testString = '\u0F4C\u0F66\u0F90\u0F4E\u0F54\u0F55\u0F56\u0F58\u0F5Babcdefghijklmnopqrstuvwxyz';
		var sCssText;
		// Safari doesn't take style properties set in BOM way after adding to XHTML tree,
		// (at least display= & position= properties, it seems)
		// so make sure to set them before adding to tree
		for (var i=0; i<aFontFamilies.length; i++) {
			o = d.getElementById(aFontIds[i]);
			if (!o) {
				o = d.createElement('span');
				o.id = aFontIds[i];
				// change the two lines below to positive 200 to see on screen
				o.style.left = '-200px';
				o.style.top = '-' + ((i+1)*(200)) + 'px';
				o.style.backgroundColor = ((i===0)?'red':'green');
				o.style.fontSize = '24pt';
				o.style.display = 'block';		
				o.style.position = 'absolute';			
				eWriteDiv.appendChild(o);
			} else {
				o.innerHTML = '';
				o.style.display = 'block';		 // just in case not set in real page
				o.style.position = 'absolute'; // ""               ""
			}
			o.style.fontFamily = aFontFamilies[i];
			o.appendChild(d.createTextNode(testString));		
		} // =======================================================
		// retrieve the widths of the two new font-relevant elements
		var nWidthControl = d.getElementById(ns + 'fontControl').offsetWidth;
		var nWidthTest = d.getElementById(ns + 'fontTest').offsetWidth;    
		// if the two widths are different, this means the fonts 
		// must be different, return TRUE to tp_hasFont question
		return (nWidthControl != nWidthTest);   
	};

	function initAudioButton() {
		$('nm_audioButtonLink').observe('click', function(e) {
			// button changes background image using classnames:
			if (this.className == "off") {
				// start playing js code here, delete next line example:
				Sound.play('http://stevecutler.tripod.com/sitebuildercontent/sitebuilderfiles/unavoce.mp3', {replace:true});
				// leave the next line intact:
				this.className = "on";
			}
			else {
				// stop playing js code here, delete next line example:
				Sound.enable(); Sound.play('', {replace: true});			
				// leave the next line intact:
				this.className = "off";
			}
			e.stop(); // this just stops the bubbling of the click event (not about stopping music)
		});
	}
	function initFastCheck() {
		$$('#menublock > ul > li').each( function(li) {
			li.observe("mouseover", function(e) {
				var current = this.className.substring(3);
				document.body.className = "nm_currentPage_" + current;
			});
		});
	}
	function initFont() {
		// font names can (and often will) have spaces in them
		// list font names in order of first priority if found

		// no js default: georgia, bitstream charter
		// windows -> cambria, *georgia*, constantia, palatino linotype 
		// mac     -> baskerville, palatino, *georgia*
		// linux   -> bitsream charter, norasi, *georgia*, liberation serif, times new roman

		var fonts = [
			'garamond premier pro',
			'chaparral pro',
			'baskerville',
			'palatino',
			'cambria',
			'bitstream charter',
			'norasi',
			'georgia', /* no js default */
			'constantia',		
			'palatino linotype',
			'liberation serif',
			'times new roman',
			'endoffontlist'
		];

		for (var i=0; i<fonts.length; i++) {
			if ( hasFont( fonts[i] ) ) {
				$(document.body).addClassName( 'tp-' + fonts[i].replace(/\s+/g,'') );
				break;
			}
		}
	}
	function initCustomElementMethods() {
		var ownMethods = {
			refactor : function(element, sNode) {
				var newNode = new Element(sNode);
				//newNode.id = element.id
				newNode.className = element.className;
				newNode.update( element.innerHTML );
				$(element).replace( newNode );
				return newNode;
			},
			copyClassAndId : function(element, source) {
				if (source.id) {
					element.id = source.id;
				}
				if (source.className) {
					element.className = source.className;
				}
				return element;
			}
		}; 
		Element.addMethods(ownMethods);
	}
	function ietable(tableLike) {
		var d = document;
		var table = d.createElement('table');
		$(table).copyClassAndId( tableLike ).removeClassName('make-table');
		$(tableLike).select('.make-caption').each( function(captionLike) {
			var newCaption = table.createCaption();
			newCaption.innerHTML = captionLike.innerHTML;
			$(newCaption).copyClassAndId( captionLike ).removeClassName('make-caption');
		});
		$(tableLike).select('.make-tbody').each( function(tbodyLike) {
			var tbody = table.appendChild( d.createElement('tbody') );
			$(tbody).copyClassAndId(tbodyLike).removeClassName('make-tbody');
			tbodyLike.select('.make-tr').each( function(trLike) {
				var tr = $(tbody.insertRow(-1)).copyClassAndId(trLike).removeClassName('make-tr');
				$(trLike).select('.make-td').each( function(tdLike) {
					$(tr.insertCell(-1)).copyClassAndId(tdLike).removeClassName('make-td').update( tdLike.innerHTML );
				});
			});
		});
		$(tableLike).replace(table);
	}

	function makeManualTableElements() {
		$$('.ny-roles').invoke( 'addClassName', 'make-table');
		$$('.ny-type').invoke( 'addClassName', 'make-caption');
		$$('.ny-tbody').invoke( 'addClassName', 'make-tbody');
		$$('.ny-stint').invoke( 'addClassName', 'make-tr' );
		$$('.ny-desc').invoke( 'addClassName', 'make-td' );
	}


	initCustomElementMethods();
	//initAudioButton();
	//initFastCheck();
	initFont();
	if (window.browserIsIELessThan8) {
		makeManualTableElements();
		$$('.make-table').each( function(tableLike) {
			ietable(tableLike);
		});
	}
	$$('.ny-roles').each( function(table) {
		table.select('.ny-stint').each( function(tr, index) {
			tr.addClassName( (index%2) ? 'even' : 'odd' );
		});
	});

	if ($(document.body).hasClassName('nm_currentPage_home')) {
		webkit.initNewsCrawl('quotes')
	}
	else if ($(document.body).hasClassName('nm_currentPage_contact')) {
		$('contactnina').observe('click', function(e) {
			MBcontact('/contact.php','Contact Nina',600,false,'nina');
			e.stop();
		});
		$('contactneil').observe('click', function(e) {
			MBcontact('/contact.php','Contact Neil Funkhouser',600,false,'neil');
			e.stop();
		});
		$('contactalex').observe('click', function(e) {
			MBcontact('/contact.php','Contact Alex Fletcher',600,false,'alex');
			e.stop();
		});
	}
	else if ($(document.body).hasClassName('nm_currentPage_media')) {
		webkit.modinit('ytgallery');
		webkit.modinit('galleryrotate');
	}

	function ninascroll(anchor) {
		new Effect.ScrollTo(anchor);
	}	
});


