if( typeof Y2 == 'undefined' )
	var Y2 = function(){ return { util: function(){} } }();

// note: methods that may have returned a String before will now return an array even when only one element is selected.
Y2.util.Dom = (function(){
	if( !YAHOO || !YAHOO.util.Dom )
		throw new Error( 'Please include both YAHOO and YAHOO.util.Dom first.' );

	var d = YAHOO.util.Dom;
	var adapter;
	if( typeof jDomQuery != 'undefined' ) adapter = jDomQuery;
	else if( typeof jQuery != 'undefined' ) adapter = jQuery;
	else if( typeof Ext.DomQuery != 'undefined' ) adapter = Ext.DomQuery.select;
	else throw new Error( 'Please include the source code for a DOM Querying Engine.' );

	function select( el )
	{
		if( !YAHOO.lang.isString( el ) )
			return el;
		return adapter( el );
	}

	function selectSingle( el )
	{
		if( !YAHOO.lang.isString( el ) )
			return el;

		var selector = select( el );
		if( select.length > 0 ) return selector[ 0 ];
		return [];
	}

	function selector( func, arguments )
	{
		var selector = select( arguments[ 0 ] );
		if( selector.length == 1 ) arguments[ 0 ] = selector[ 0 ];
		else arguments[ 0 ] = selector;
		return func.apply( null, arguments );
	}

	return {
		addClass: function() { return selector( d.addClass, arguments ); },
		batch: function() { return selector( d.batch, arguments ); },
		generateId: function() { return selector( d.generateId, arguments ); },
		get: function() { return selector( d.get, arguments ); },
		getDocumentHeight: function() { return d.getDocumentHeight(); },
		getDocumentWidth: function() { return d.getDocumentWidth(); },
		getRegion: function() { return selector( d.getRegion, arguments ); },
		getStyle: function() { return selector( d.getStyle, arguments ); },
		getViewportHeight: function() { return d.getViewportHeight(); },
		getViewportWidth: function() { return d.getViewportWidth(); },
		getX: function() { return selector( d.getX, arguments ); },
		getXY: function() { return selector( d.getXY, arguments ); },
		getY: function() { return selector( d.getY, arguments ); },
		hasClass: function() { return selector( d.hasClass, arguments ); },
		inDocument: function() { return d.inDocument( selectSingle( arguments[ 0 ] ) ); },
		isAncestor: function() { return d.isAncestor( selectSingle( arguments[ 0 ] ), selectSingle( arguments[ 1 ] ) ); },
		removeClass: function() { return selector( d.removeClass, arguments ); },
		replaceClass: function() { return selector( d.replaceClass, arguments ); },
		setStyle: function() { return selector( d.setStyle, arguments ); },
		setX: function() { return selector( d.setX, arguments ); },
		setXY: function() { return selector( d.setXY, arguments ); },
		setY: function() { return selector( d.setY, arguments ); },

		// Deprecated, use CSS Selectors instead
		getElementsBy: function() { return execute( d.getElementsBy, arguments ); },
		getElementsByClassName: function() { return execute( d.getElementsByClassName, arguments ); }
	}
})();