$(function() {
	$('fieldset.search input:image').hover( function() {
		this.src = this.src.replace( '.gif', '-hover.gif' );
	}, function() {
		this.src = this.src.replace( '-hover.gif', '.gif' );
	} );
	$('fieldset.search input:text').focus( function() {
		$(this).data( 'value', this.value );
		this.value = '';
	} ).blur( function() {
		if( !this.value ) this.value = $(this).data( 'value' ) || '';
		$(this).removeData( 'value' );
	} );
	$('a[href^="http://www.youtube.com/watch?v="]').click( function( e ) {
		e.preventDefault();
		$('#movie-wrapper').remove();
		var url = this.href.replace( '/watch?v=', '/v/' ) + '&hl=en&fs=1&autoplay=1';

		// This was very elegant but IE choked on it.
		// After a few hours of debugging, now it is ugly but works in IE.

		var movieWrapper = $._div_( { 'id': 'movie-wrapper' } )
		.click( function( e ) {
			$(this).fadeOut( 'slow', function() { $(this).remove(); } );
		} );

		var movie = $._div_( { 'id': 'movie' } )
		.click( function( e ) {
			e.stopImmediatePropagation();
		} );

		movie.append( $._div_( { 'id': 'movie-placeholder' } ) );
		
		movieWrapper.append( movie );

		movieWrapper.append(
			$._a_( { 'href': '#' } )
			.click( function( e ) {
				e.preventDefault();
				$('#movie-wrapper').click();
			} ).text( 'Close' )
		);

		movieWrapper.hide();
		$('#main').before( movieWrapper );
		swfobject.embedSWF( url, 'movie-placeholder', '100%', '100%', '9.0.0', null, null, { 'quality': 'highest', 'wmode': 'transparent' }, {} );
		movieWrapper.fadeIn( 'slow' );
	} );
	$('.vote-cell a img').load( function() {
		$(this).css(
			{ 'margin-top': ( 200 - $(this).height() ) * 0.5 + 'px',
			  'margin-bottom': ( 200 - $(this).height() ) * 0.5 + 'px' }
		);
	} );
});
