function uvdrag_attach( element ) {
	/**
	 *	@browser IE
	 *	Dragging behavior is unintutive (mouse down, drag 1px, mouse up, drag, 
	 *	click to release drag).
	 *
	 *	@browser Safari
	 *	Provide positioning styles inline to workaround this "bug": https://mootools.lighthouseapp.com/projects/2706/tickets/462-positioning-in-safarichromewebkit
	 */
/*	if( isIE( ) ) {
		return;
	}*/
	
	var draggables = $$( [ element, '.uvDraggable' ].pick( ) );
	var cookie = new Hash.Cookie( 'uvDraggables', { path: AURI } );
	
	var undo = function( e ) {
		draggables.each( function( node ) {
			node.drag.fireEvent( 'reset', node );
		} );
	}
	var keyboard = new Keyboard( {
		  active: false
		, preventDefault: true
		, events: {
			 'meta+z': undo
			,'ctrl+z': undo
		  }
	} );
	
	draggables.each( function( node ) {
		var origin = node.getPosition( node.getOffsetParent( ) );
		node.store( 'origin', origin );
		node.setPosition( [ cookie.get( node.id ), origin ].pick( ) );
		node.addClass( 'placed' );
		node.setStyles( { right: 'auto', bottom: 'auto' } );
		
		if( node.getPosition( ).x != origin.x || node.getPosition( ).y != origin.y ) {
			keyboard.activate( );
			node.setStyle( 'cursor', 'move' );
		}
		
		node.drag = new Drag(
			  node
			, {
				  snap: 0
				, onStart: function( node ) {
					node.setStyle( 'cursor', 'move' );
				  }
				, onComplete: function( node, event ) {
					keyboard.activate( );
					cookie.set( node.id, node.getPosition( ) );
				  }
				, onReset: function( node ) {
					keyboard.deactivate( );
					var origin = node.retrieve( 'origin' );
					node.morph( { top: origin.y, left: origin.x } );
					cookie.set( node.id, origin );
				  }
			  }
		);
	} );
}

function uvflash_attach( ) {
	if( typeof( flashUpshift ) != "undefined" ) {
		for( var ii = 0; ii < flashUpshift.length; ii++ ) {
			var d			= flashUpshift[ii];
			var hardpoint	= d[0];
			var flashObj	= d[1];
			var version		= d[2];
			var dx			= d[3];
			var dy			= d[4];
			var flashVars	= d[5] ? d[5] : '';
			
			if( getFlashVersion( ) < version )
				return uvflash_prompt();
				
			var obj = getObj( hardpoint );
			
			if( obj ) {
				clearNode( obj );
				
				var params = {
					 allowScriptAccess	: 'sameDomain'
					,movie				: flashObj
					,quality			: 'high'
					,bgcolor			: '#FFFFFF'
					,flashVars			: flashVars
					/**
					 *	@browser IE
					 *	Allows drop-downs to work.
					 */
					,wmode				: 'transparent'
					};
				
/*				This approach doesn't work so well for FF3. Might as well just use innerHTML for everything (even though it's not in the standard).
				
				if( !isIE() && !isOpera() ) {
					var fbase = obj.appendChild(
						document.createElement( 'object' )
					);

					fbase.classid
						= 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';

					fbase.codebase
						= 'http://fpdownload.macromedia.com/'
						+ 'pub/shockwave/cabs/flash/swflash.cab'
						+ '#version=7,0,0,0'
						;

					fbase.width 	= dx;
					fbase.height	= dy;
					fbase.wmode		= 'transparent';
					
					var p;
					
					for( var k in params ) {
						p = fbase.appendChild(
							document.createElement( 'param' )
							);
						p.name	= k;
						p.value	= params[ k ];
					}
					
					var emb = fbase.appendChild(
						document.createElement( 'embed' )
					);
					
					emb.src			= flashObj;
					emb.quality		= 'high';
					emb.bgcolor		= '#FFFFFF';
					emb.type		= 'application/x-shockwave-flash';
					emb.pluginspage	= 
						'http://www.macromedia.com/go/getflashplayer';
					emb.width		= dx;
					emb.height		= dy;
					emb.wmode		= 'transparent';
				} else {*/
					
					phtml = '';
					for( var k in params ) {
						phtml = phtml + '<param name="' + k
							+ '" value="' + params[k] + '" />'
							;
						}
				
					obj.innerHTML =
'<object	classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
'			codebase="http://download.macromedia.com/pub/shockwave/cabs/flash' +
		   '/swflash.cab#version=' + version +',0,0,0"' +
'			width="' + dx + '"' +
'			height="' + dy + '">' +
'	' + phtml +
'	<embed	src="' + flashObj + '"' +
'			quality="high"' +
'			width="' + dx + '"' +
'			height="' + dy + '"' +
'			flashVars="'+ flashVars +'"' +
'			type="application/x-shockwave-flash"' +
'			pluginspage="http://www.macromedia.com/go/getflashplayer"' +
'			wmode="transparent" />' +
'</object>';
//				}
			}
		}
	}
}

function uvflash_prompt() {
	obj = getObj( 'uvPromptFlash' )
	
	if( !obj )
		return;
	
	obj.style.display = 'block';
}
	
var _flashVersion = null;
function getFlashVersion( ) {
	if( _flashVersion !== null ) return _flashVersion;
	
	if( navigator.plugins
	&&	navigator.plugins.length ) {
		var p = navigator.plugins;
		for( var ii = 0; ii < p.length; ii++ ) {
			if( p[ ii ].name.indexOf( 'Shockwave Flash' ) != -1 ) {
				_flashVersion = p[ ii ].description.split(
					'Shockwave Flash' )[1];
				break;
				}
			}
		}
	else
	if( window.ActiveXObject ) {
		for( var ii = 12; ii--; ) {
			try {
				if( eval(	
					 'new ActiveXObject('
					+'"ShockwaveFlash.ShockwaveFlash.' + ii + '"'
					+');'
					) ) {
					_flashVersion = ii;
					break;
					}
				}
			catch( e ) { }
			}
		}
		
	_flashVersion = parseInt( _flashVersion );
	return _flashVersion;
	}

function uvqt_attach( video ) {
    if( video ) {
        qtUpshift = video;
    }
    
	if( typeof( qtUpshift ) != 'undefined' ) {
		for( var ii = 0; ii < qtUpshift.length; ii++ ) {
			var d			= qtUpshift[ii];
			var hardpoint	= d[0];
			var qtObj		= d[1];
			var dx			= d[2];
			var dy			= d[3];
			
			var obj = getObj( hardpoint );
			
			if( obj ) {
				classid = ( isIE() ) ? 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"' : '';
				
				obj.innerHTML
					=	'<object	' + classid +
						'			data="' + qtObj + '" ' +
						'			width="' + dx + '" ' +
						'			height="' + dy + '">' + "\n" +
						'	<param	name="src" ' +
						'			value="' + qtObj + '" />' +
						'</object>';
			}
		}
	}
	
}
	

function uvhoverable_attach( imgs ) {
	var imgArr	= imgs ? imgs : document.getElementsByTagName( 'img' );
	var inptArr	= imgs ? [] : document.getElementsByTagName( 'input' );
	
	arr = new Array( imgArr, inptArr );
	
	if( arr ) {
		for( var ii = 0; ii < arr.length; ii++ ) {
			
			for( var kk = 0; kk < arr[ ii ].length; kk++ ) {
				if( arr[ ii ][ kk ].className
				&&	arr[ ii ][ kk ].className.indexOf( 'uvHoverable' ) != -1 ) {
	
					var p = arr[ ii ][ kk ].src.split( '.' );
					if( p.length > 1 ) {
						p[ p.length - 2 ] += '_h';
						}
					l = p.join( '.' );
	
					arr[ ii ][ kk ].uvhoverable_off	= arr[ ii ][ kk ].src;
					arr[ ii ][ kk ].uvhoverable_on	= l;
					
					arr[ ii ][ kk ]._preload			= new Image( );
					var _t = arr[ ii ][ kk ]._preload;

					arr[ ii ][ kk ]._preload.onerror	= bind(
						 null
						,function( _t ) {
							uv_error(
								'Unable to load image: ' + _t.src
								);
							}
						,arr[ ii ][ kk ]
						);
					
					arr[ ii ][ kk ]._preload.src 	= l;
	
					arr[ ii ][ kk ].onmouseover =
						chainHandlers(
							 uvhoverable_activate
							,arr[ ii ][ kk ].onmouseover
							);
	
					arr[ ii ][ kk ].onmouseout =
						chainHandlers(
							 uvhoverable_deactivate
							,arr[ ii ][ kk ].onmouseout
							);
	
					arr[ ii ][ kk ].onfocus =
						chainHandlers(
							 uvhoverable_activate
							,arr[ ii ][ kk ].onfocus
							);
	
					arr[ ii ][ kk ].onblur =
						chainHandlers(
							 uvhoverable_deactivate
							,arr[ ii ][ kk ].onblur
							);
					}
				}
			}
		}
	}
	
function uvhoverable_activate( ) {
	this.src = this.uvhoverable_on;
	}
	
function uvhoverable_deactivate( ) {
	this.src = this.uvhoverable_off;
	}
	
function uv_error( err ) {
/*	uv_log(
		 'error'
		,err
		,window.location
		);
*/	}

function uv_log( what, which, where ) {
	if( typeof( uvUniq ) == "undefined" ) {
		uvUniq = null;
		}
	
	if( typeof( uvWho ) == 'undefined' )
		uvWho = null;
	
	(new Image()).src = s = auri(
		 'resource/ultraviolet/'
		+ Math.random( )+'.gif'
		+'?who='+escape( uvWho )
		+'&which='+escape( which )
		+'&what='+escape( what )
		+'&where='+escape( where )
		+'&referrer='+escape( document.referrer )
		+'&uniq='+escape( uvUniq )
		);
	
	setCookie( '_uv', uvUniq );
	}
	
function uv_attach_links( obj ) {
	var dom = $( [ obj, document.body ].pick( ) );
	
	var regloc	= new RegExp(
		 '^(javascript:|http(s)?://'+window.location.host+')'
		,'i'
	);
	var regkey	= new RegExp( 'uvk_([a-z0-9_\.:&\-]+)', 'i' );
	var regtyp	= new RegExp( 'uvt_([a-z0-9_\.:&\-]+)', 'i' );
	
	dom.getElements( 'a' ).each( function( _t, i ) {
		var trackRef = false;
		var category	= '';
		var action		= '';
		var label		= '';
		var metric		= 0;
			
		var sourceLoc = loc_uri( );
		
		if( uvk = _t.className.match( regkey ) ) {
			category = uvk[1].replace( /_/g, ' ', '' );
		}
		
		if( uvt = _t.className.match( regtyp ) ) {
			action = uvt[1].replace( /_/g, ' ', '' );
		}
		
		// Internal links
		if( regloc.test( _t.href ) ) {
			if( category && action ) {
				var targetLoc = project_uri( _t.pathname );
				if( targetLoc == '' ) {
					targetLoc = '/';
				}
				
				switch( category ) {
					case 'Font Control':
					case 'Search Tabs':
					case 'Share your Memories Promo':
					case 'My Trip Planner':
						label = sourceLoc;
						break;
					
					case 'banner':
						category = 'Proximity Banner';
						
						switch( action ) {
							case 'click:search':
								action = 'click';
								label = targetLoc+' < '+sourceLoc+' ("'+_t.getChildren( 'img' )[0].alt.replace( /:[^:]*$/, '' )+'")';
								break;
						}
						
						break;
					
					case 'gateway':
						category = 'Nav. Gateways';
						
						switch( action ) {
							case 'click':
								// Don't attach tracking for tabbed gateways during the "domready" pass. Litetab.js will call uv_attach_links() itself.
								if( obj || !isset( 'GatewayTabs' ) ) {
									var tabLoc = '';
									
									// If called from litetab.js
									if( this.label ) {
										tabLoc =
											 ' ("'
											+ this.label
											+'" > "'
											+ _t.get( 'text' )
												.match( /[^\(]+/ )[0].trim( )
											+'")';
									}
									
									label = targetLoc+' < '+sourceLoc+tabLoc;
								}
								else {
									category = null;
									action = null;
								}
								break;
						}
						
						break;
					
					case 'home':
						category = 'Homepage';
						
						switch( action ) {
							case 'gateway click':
							case 'upcoming events':
								label = targetLoc;
								break;
							case 'logo click':
								label = sourceLoc;
								break;
						}
						
						break;
					
					case 'interior':
						category = 'Interior Page Body Area';
						trackRef = true;
						
						switch( action ) {
							case 'featured links':
								label = targetLoc+' < '+sourceLoc;
								break;
							default:
								label = sourceLoc;
								break;
						}
						
						switch( action ) {
							case 'email':
								action = 'email this page';
								break;
							case 'view all listings':
								action = 'view all "..." listings';
								break;
						}
						break;
					
					case 'listing':
					case 'Article':
						if( category == 'listing' ) {
							category = 'Listing Detail Page';
						}
						
						switch( action ) {
							case 'ati':
							case 'con':
							case 'fwd':
							case 'prt':
							case 'map':
							case 'drv':
							case 'pweb':
							case 'pfwd':
							case 'pmap':
							case 'pdrv':
								switch( action ) {
									case 'ati': break;
									default:
										trackRef = true;
										break;
								}
								
								switch( action ) {
									case 'pweb':
										label = targetLoc+' < '+sourceLoc;
										break;
									default:
										label = sourceLoc;
										break;
								}
								
								switch( action ) {
									case 'pweb':
										action = 'getaway referral';
										break;
									default:
										action = _t.getElements( 'img' )[0]
											.get( 'alt' );
										break;
								}
								break;
						}
						break;
					
					case 'search popup':
						category = 'Listing Pop-up Window';
						trackRef = true;
						sourceLoc = loc_uri( )+' ('+this.retrieve( 'adminPopupID' )+')'
						label = targetLoc+' < '+sourceLoc;
						break;
					
					case 'Search':
						targetLoc = project_uri(
							 // Atrocious hack
							_t.getParent( ).getNext( ).getFirst( )
								.get( 'href' )
						);
						label = targetLoc+' < '+sourceLoc;
						break;
					
					default:
						label = targetLoc+' < '+sourceLoc;
						break;
				}
				
				// For events that result in a page jump, delay the jump so the event has time record. FYI, category may have been altered in the previous switch block.
				switch( category ) {
					case 'Homepage':
					case 'Left Navigation':
					case 'My Trip Planner':
					case 'Search Tabs':
					case 'Share your Memories Promo':
					case 'Sticky Footer':
					case 'Breadcrumb Trails':
						trackRef = true;
						break;
					
					case 'Nav. Gateways':
					case 'Proximity Banner':
						switch( action ) {
							case 'click':
								trackRef = true;
								break;
						}
						break;
				}
			}
		}
		
		// Exit links
		else {
			var targetLoc = _t.href.replace( /http:\/\/(www\.)?/i, '' );
			
			if( !_t.hasClass( 'ignore_external' ) ) {
				_t.set( 'title', 'Opens in a new window' );
				_t.set( 'target', '_blank' );
				
				// Insert `external' icon
				if( _t.childNodes.length == 1
				&&  _t.childNodes[ 0 ].nodeType == Node.TEXT_NODE ) {
					/* Special case this out because IE is incapable of 
					 * correctly positioning an inline bg image.
					 * The fix is to insert the icon img at the end of link.
					 */
					if( isIE( ) ) {
						if( _t.currentStyle.backgroundImage == 'none' ) {
							var extIcon = new Image( );
							extIcon.src = auri( 'resource/image/layout/external.gif' );
							
	//						var extLink = cloneNode( _t, false );
							var extLink = new Element( 'a', { href:_t.href } );
							extLink.appendChild( extIcon );
							
							appendSibling( _t, extLink );
							addClass( extLink, 'ieExternal' );
						}
					}
					else {
						addClass( _t, 'external' );
					}
				}
			}
			
			category = category ? category : 'Exit';
			action = action ? action : 'interior';
			
			label = targetLoc+' < '+sourceLoc;
			
			// Special links
			if( uvt ) {
				switch( uvt[1] ) {
					case 'eweb':	action = 'event';					break;
					case 'oweb':	action = 'organization';			break;
					case 'pweb':	action = 'package';					break;
					case 'sweb':	action = 'special';					break;
					case 'relweb':	action = 'related sites';			break;
					case 'res':		action = 'online reservation';		break;
				}
			}
		}
		
		if( category && action ) {
			_t.addEvent(
				 'click'
				, function( ) {
					var args = [ category, action, label, metric ];
					
					if( trackRef ) {
/*						_t.set(
							 'href'
							, get_ref_uri.attempt( [ _t.href ].append( args ) )
								.toString( )
						);*/
					}
					else {
						track.attempt( args );
					}
				  }
			);
			
			_t.addEvent( 'keypress', function( e ) { fireClickOnEnterKeyPress( this, e ); } );
		}
		
	}, this );
	
	return;	
}

/*
function uvAttachReports( ) {
	var linkArr = document.getElementsByTagName( 'a' );
	if( linkArr ) {
		for( var ii = 0; ii < linkArr.length; ii++ ) {
			var div = document.createElement( 'div' );
			div.className = 'uvLinkReport';
			div.style.left = (getObjWidth( linkArr[ ii ] ) + 5) + 'px';
			
			var key = 'h_' + hex_md5( linkArr[ii].href );
			var N = 0;
			var P = 0;
			
			if( uvExit
			&&	uvExit[ key ] ) {
				var N = uvExit[ key ][ 0 ];
				var P = parseInt((parseFloat( uvExit[ key ][ 1 ] ) * 100));
				}
			
			setHTML( div, '&laquo; (' + N + '; ' + P + '%)' );
			linkArr[ii].insertBefore( div, linkArr[ii].firstChild );
			linkArr[ii].style.position = 'relative';
			}
		}
	}
*/

function track( category, action, label, metric ) {
	action = category+' > '+action;
	label = Array.pick( [ label, loc_uri( ) ] );
	metric = Array.pick( [ metric, 0 ] );
	
//	console.log( "_gaq.push( '"+category+"', '"+action+"', '"+label+"', '"+metric+"' )" );
	_gaq.push( [ '_trackEvent', category, action, label, metric ] );
}

// Add ref tracking to uri.
function get_ref_uri( href, category, action, label, metric ) {
	var uri = href.toURI( );
	var utmQuery = _gat._getTrackerByName( )._getLinkerUrl( '' );
	
	if( utmQuery ) {  // Empty if cookies are disabled
		utmQuery = utmQuery.replace( /^\?/, '' );
		
		var refQuery = Object.toQueryString(
			  { c: category, a: action, l: label, m: metric }
			,'ref'
		);
		
		uri.set( 'query', utmQuery+'&'+refQuery+'&'+uri.get( 'query' ) );
	}
	
	return uri;
}

// Set default submit button
function uv_attach_submitter( ) {
    var forms = document.forms;
    for( var i = 0; i < forms.length; i++ ) {
        
        var form        = forms[ i ];
        var elements    = form.getElementsByTagName( 'input' );  // inputs of type image are mysteriously missing from forms.elements
        var element;
        for( var j = 0; j < elements.length; j++ ) {
            
            element = elements[ j ];
            if( element.className.search( /uvSubmitter/ ) != -1 ) {
                
                form._viSubmitter   = element;
                form.onkeypress     = function( e ) {
                    e = getEvent( e );
                    if( getKeyPressed( e ) == 13 ) {  /* "\r" */
                        if( isIE( ) ) {
                            var clone = cloneNode( this._viSubmitter );
                            clone.style.position    = 'absolute';
                            clone.style.width		= '1px';
                            clone.style.left        = '-500px';
                            insertBefore( clone, form.firstChild );
                        }
                        else {
                            return this._viSubmitter.click( );
                        }
                    }
                    return true;
                }
                
                // But not for textareas
                var nonSubmitters = new Array(
                	  form.getElementsByTagName( 'textarea' )
                	, form.getElementsByTagName( 'option' )  // Safari discriminates correctly here.
                	, ( isFirefox( ) )
                	  ? form.getElementsByTagName( 'select' )
                	  : new Array( )
                );
                for( var k = 0; k < nonSubmitters.length; k++ ) {
					for( var kk = 0; kk < nonSubmitters[ k ].length; kk++ ) {
						nonSubmitters[ k ][ kk ].onkeypress = function( e ) {
							e = getEvent( e );
							if( getKeyPressed( e ) == 13 ) {
								abortEvent( e );
							}
						}
					}
				}
            }
        }
    }
}

function uvattach_alpha_bg( alphas, sizingMethod ) {
	if (sizingMethod == null) {
		sizingMethod = 'scale';
	}
	if( !isIE( ) || !isAtMostVersion( 6 ) ) {
		return;
	}
	
	if( !alphas ) {
		error( 'No alpha backgrounds to filter!' );
	}
	
	for( var id in alphas ) {
		alpha = document.getElementById( id );

		if( alpha == null ) {
			warn( 'No element found for alpha id: ' + id );
			continue;
		}
		alpha.style.filter = 
			 'progid:DXImageTransform.Microsoft.AlphaImageLoader( '
				+'  src="' + auri( alphas[ id ] ) + '"'
				+', sizingMethod="'+sizingMethod+'"'
			+' )';
		if ( alpha.href ) {
			alpha.style.cursor = 'pointer';
		}
	}
}

// Remember: set a css style for .uvTransparent such that visibility = 'hidden'
function uvattach_alpha_img( in_img ) {
	
	if( in_img ) {
		var imgs = ( is_array( in_img ) ) ? in_img : new Array( in_img );
	}
	else {
		var imgs = document.images;
	}
	
	if( !isIE( ) || isAtLeastVersion( 7 ) ) {
		return imgs;
	}
	
	var alpha	= new Array( );
	var links	= new Array( );
	var spans	= new Array( );
	
	if( !imgs ) {
		return;
	}
	
	for( var i = 0; i < imgs.length; i++ ) {
		img = imgs[ i ];
		
		if( in_img
		|| (   img.className
			&& img.className.indexOf( 'uvTransparent' ) != -1 ) ) {
			
			img._s = document.createElement( 'span' );
			
			var keys = new Array(
				 'id'
				,'className'
				,'title'
				,'src'
				,'style'
				,'currentStyle'
				,'alt'
			);
			
			for( var j = 0; j <= keys.length; j++ ) {
				key = keys[ j ];
				
				switch( key ) {
					case 'src':
						img._s.style.filter =
							'progid:DXImageTransform.Microsoft.AlphaImageLoader('
								+'  src="' + img.src + '"'
								+', sizingMethod="image"'
							+' )';
						break;
					case 'style':
						img._s.style.visibility = 'visible';
						img._s.style.display = 'inline-block';
						
						var width	= getObjWidth( img );
						var height	= getObjHeight( img );
						img._s.style.width = ( width ) ? width : getStyle( img, 'width' );
						img._s.style.height = ( height ) ? height : getStyle( img, 'height' );
						
						if( img.parentNode.href ) {
							img._s.style.cursor = 'pointer';
						}
						break;
					case 'alt':
						if( !img[ 'title' ] ) {
							img._s[ 'title' ] = img[ key ];
						}
						break;
					case 'currentStyle':
						for( style in img.currentStyle ) {
							if( in_array( style, [ 'filter', 'display' ] ) ) {
								continue;
							}
							img._s.style[ style ] = img.currentStyle[ style ];
						}
						break;
					default:
						if( img[ key ] ) {
							img._s[ key ] = img[ key ];
						}
					break;
				}
			}
			
			if( img.parentNode.href ) {
				links.push( img );
			}
			else {
				alpha.push( img );
			}
			
			spans.push( img._s );
		}
	}
	
	if( isAtLeastVersion( 7 ) ) {
		return imgs;//spans;
	}
	
	for( var i = 0; i < alpha.length; i++ ) {
		img = alpha[ i ];
		replaceNode( img, img._s );
	}
	
	var pad;
	for( var i = 0; i < links.length; i++ ) {
		img				= links[ i ];
		pad				= document.createElement( 'div' );
		pad.style.width	= getStyle( img._s, 'width' );
		
		pad.appendChild( img._s );
		img.parentNode.appendChild( pad );
		removeNode( img );
	}
	
	return spans;
}
				
				

function uvbootstrap( ) {
	if( isIE( )
	&& isAtMostVersion( 6 ) ) {
		try {
			document.execCommand( 'BackgroundImageCache', false, true );	
		}
		catch( e ) { }
	}
	
	// FIXME: deprecated in favor of HTML5's "placeholder" attribute.
	// Add auto-clear function to search
	if( getObj( 'searchInput' ) ) {
		var go		= getObj( 'GlobalSearchGo' );
		var search	= getObj( 'searchInput' );
		var def		= { 'text': search.value };
		
		search.value	= def.text;
		search.onfocus	= bind(
			  search
			, function( ) {
				if( this.value == def.text ) {
					this.value = '';
				}
			  }
		);
		search.onblur	= bind(
			  search
			, function( ) {
				if( this.value == '' ) {
					this.value = def.text;
				}
			  }
		);
		
		go.onclick		= bind(
			  search
			, function( ) {
				if( this.value == def.text ) {
					this.value = '';
				}
			  }
		);
	}
	
	// Admin controls
	var sitePreview = $( 'SitePreview' );
	if( sitePreview ) {
		var sitePreviewMenu = $$( '#SitePreview .menu' )[0];
		sitePreview.addEvent( 'contextmenu', function( e ) {
			e.stop( );
			sitePreviewMenu.setStyles( { top: e.client.y, left: e.client.x } );
			sitePreviewMenu.addClass( 'show' );
		} );
		
		sitePreviewMenu.addEvent( 'click', function( e ) {
			this.removeClass( 'show' );
		} );
		
		sitePreview.addEvent( 'click', function( e ) {
			sitePreviewMenu.removeClass( 'show' );
		} );
		
		window.addEvent( 'click', function( e ) {
			if( !e.target.getParent( '#SitePreview' ) ) {
				sitePreviewMenu.removeClass( 'show' );
			}
		} );
		
		$$( '#SitePreview .menu li' ).each( function( node, i ) {
			switch( node.get( 'class' ) ) {
				case 'publish':
					node.getElement( 'a' ).addEvent( 'click', function( e ) {
						node.addClass( 'waiting' );
						$( document.body ).addClass( 'wait' );
						
						document.location = this.get( 'href' )+'?jump='+document.location;
						
						if( e ) {
							e.stop( );
						}
						else {
							return false;
						}
					} );
					
					node.addEvent( 'click', function( e ) {
						node.getElement( 'a' ).fireEvent( 'click' );
					} );
			}
		} );
	}
	
	// Font resizing controls
	if( $( 'FontSizeControl' ) ) {
		var fontData = new Hash.Cookie( 'FontControl', { path: AURI, domain: 'visitmaine.com', duration: 90 } );
		var fontSize = [ fontData.get( 'size' ), '12px' ].pick( );
		
		$$( '#FontSizeControl a' ).each( function( node, i ) {
			node.addEvent( 'click', function( e ) {
				if( e ) { e.stop( ); }
				
				$( 'uvBodyCopy' ).setStyle(
					 'font-size'
					, this.getStyle( 'font-size' )
				);
				$$( '#FontSizeControl a.selected' )[0].removeClass( 'selected' );
				this.addClass( 'selected' );
				fontData.set( 'size', this.getStyle( 'font-size' ) );
				
				if( !e ) { return false; }
			} );
			
			if( node.getStyle( 'font-size' ) == fontSize ) {
				node.fireEvent( 'click' );
			}
		} );
		
	}
	
	// Fixed footer
	var footer = $( 'Slidebar' );
	if( footer && document.cookie ) {
		if( Browser.ie ) {
			footer.getElements( 'img.social' ).removeClass( 'hoverable' );
		}
		
		if( Browser.ie6 || isMobile( ) ) {
			footer.setStyle( 'display', 'none' );
		}
		else
		if( Browser.ie7 ) {
			// ok
		}
		else {
			var slidebarData = new Hash.Cookie( 'Slidebar', { path: AURI, domain: 'visitmaine.com', duration: 90 } );
			var kClosedOpacity = .3;
			var duration = 'short';
			
			var state = footer.hasClass( 'opened' ) ? 'opened' : 'closed';
			var close = footer.getElements( 'a.close' )[0];
			var open = footer.getElements( 'a.open' )[0];
			
			close.set( 'tween', { duration: duration } );
			open.set( 'tween', { duration: duration } );
			
			footer.set( 'morph', { duration: duration } );
			footer.get( 'morph' ).addEvents( {
				  start: function( ) {
					footer.removeClass( 'opened' );
					footer.removeClass( 'closed' );
					footer.setStyle( 'width', '100%' );
				  }
				  
				, complete: function( ) {
					switch( state ) {
						case 'closed':
							footer.removeClass( 'opened' );
							footer.addClass( 'closed' );
							footer.setStyle( 'width', footer.getSize( ).x );
							break;
						
						case 'opened':
							footer.removeClass( 'closed' );
							footer.addClass( 'opened' );
							break;
					}
					slidebarData.set( 'state', state );
				  }
			} );
			
			if( footer.hasClass( 'closed' ) ) {
				footer.setStyles( {
					  left: ( $( document.body ).getSize( ).x - footer.getComputedSize( { mode: 'horizontal' } ).width ) * -1
					, width: $( document.body ).getSize( ).x
					, display: 'block'
				} );
			}
			
			footer.addEvents( {
				  mouseenter: function( ) {
					if( footer.hasClass( 'closed' ) ) {
						footer.fade( 1 );
					}
				  }
				, mouseleave: function( ) {
					if( footer.hasClass( 'closed' ) ) {
						footer.fade( kClosedOpacity );
					}
				  }
			} );
			
			close.addEvent( 'click', function( e ) {
				e.stop( );
				track( 'Sticky Footer', 'Hide' );
				
				state = 'closed';
				open.fade( 'in' );
				footer.morph( {
					  left: ( footer.getSize( ).x - open.getDimensions( ).x ) * -1
					, opacity: kClosedOpacity
				} );
			} );
			
			open.addEvent( 'click', function( e ) {
				e.stop( );
				track( 'Sticky Footer', 'Show' );
				
				state = 'opened';
				open.fade( 'out' );
				footer.morph( { left: 0, opacity: 1 } );
			} );
		}
	}
}

function uvgateway_attach( ) {
	// Gateway expand/collapse toggles
	var gateways = $$( '.gateways' );
	if( gateways ) {
		var Expander = new Class( {
			  node: null
			, control: null
			, state: ''
			, height: 0
			
			, initialize: function( control, node ) {
				this.node = node;
				this.control = control;
				this.state = 'collapsed';
				this.height = node.getSize( ).y;
			  }
			
			, hide: function( ) {
				this.node.setStyle( 'height', 0 );
				return this;
			  }
			
			, isCollapsed: function( ) {
				return this.state == 'collapsed';
			  }
			, isExpanded: function( ) {
				return this.state == 'expanded';
			  }
			
			, collapse: function( ) {
//				this.state = 'collapsing';
				this.node.tween( 'height', 0 );
				this.control.set( 'text', 'See More' );
				this.control.removeClass( 'expanded' );
				this.state = 'collapsed';
				this.control.getParent( ).setStyle( 'margin-top', '0' );
				
				track( 'Nav. Gateways', 'show fewer' )
			  }
			, expand: function( ) {
//				this.state = 'expanding';
				this.node.tween( 'height', this.height );
				this.control.set( 'text', 'See Fewer' );
				this.control.addClass( 'expanded' );
				this.state = 'expanded';
				this.control.getParent( ).setStyle( 'margin-top', '1em' );
				
				track( 'Nav. Gateways', 'show more' )
			  }
			
			, toggle: function( ) {
			  	if( this.isCollapsed( ) ) {
			  		this.expand( );
			  	}
			  	else
			  	if( this.isExpanded( ) ) {
			  		this.collapse( );
			  	}
			  }
		} );
		
		gateways.each( function( n ) {
			var collapse = n.getElement( '.collapsable' );
			var toggler = n.getElement( '.toggler a' );
			
			if( collapse && toggler ) {
				n.gateway = new Expander(
					  toggler
					, n.getElement( '.collapsable' )
				).hide( );
				
				toggler.getParent( ).setStyle( 'display', 'block' );
				toggler.addEvent(
					 'click'
					, function( e ) {
						n.gateway.toggle( );
						e.stop( );
					  }
				)
			}
		} );
	}
}

window.addEvent( 'domready', uvbootstrap );
window.addEvent( 'domready', uvdrag_attach );
window.addEvent( 'domready', uvgateway_attach );
window.addEvent( 'domready', uvattach_alpha_img );
window.addEvent( 'domready', uvflash_attach );
window.addEvent( 'domready', uvqt_attach );
window.addEvent( 'domready', uvhoverable_attach );
window.addEvent( 'domready', uv_attach_links );
window.addEvent( 'domready', uv_attach_submitter );

