videogallery = function(){

	var TrayEvents = {

		/**
			SELECT event
			fired when a tray icon is clicked or programmatically selected
			callback is passed the tray icon index and the info object used to create the icon. this can be
			used to contain extra data you might want to asociate with the icon
		*/
		SELECT: "TrayEvents.SELECT",
		SELECT_NONE: "TrayEvents.SELECT_NONE",

		/**
			PAGE_CHANGED
			Fired when the Tray's slider slides to a new page.
			callback is passed the page index
		*/
		PAGE_CHANGED: "TrayEvents.PAGE_CHANGED"

	};

	/**
		Tray
	*/
	var _Tray = Class.extend(
	{	
		init: function( container, params )
		{
			var scope = this;

			this._currentIconIndex = null;
			this._currentPage = 0;

			this._iconInfos = [];
			this._params = {
				sliderClass: 'Tray_slider',
				iconClass: 'Tray_icon',
				activeClass: 'Tray_icon_active'
			};

			$.extend( this._params, params );

			this._tray = container;
			this._tray.css({
				overflow: 'hidden',
				position: 'relative'
			});

			this._slider = $('<div class="' + this._params.sliderClass + '"></div>' ).css({
				display: 'block',
				position: 'absolute',
				width: '0'
			});

			// if the tray already has contents, adopt them and make them children of the slider
			this._slider.append( this._tray.children() );
			this._slider.children().each( function( idx, icon )
			{
				icon = $(icon);
				icon.css( { position: 'absolute', top: '0' })
				    .click( function(e){ scope.selectIconAtIndex( idx ); })
			})

			this._tray.append( this._slider );
			this._layout(false);

			$(window).resize( function( e )
			{
				scope.setPage( scope.pageIndexForIconIndex( scope.currentIconIndex() ), true ); 
			});
		},

		/**
			remove all icons
		*/
		clear: function()
		{
			this._slider.empty();
			this._iconInfos = [];
			this._currentPage = 0;
			this._layout(); // reset
		},

		/**
			set the slider page
			fires TrayEvents.PAGE_CHANGED event
		*/
		setPage: function( pageIndex, force )
		{
			pageIndex = Math.min( Math.max( pageIndex, 0 ), this.numPages() - 1 );
			if ( pageIndex != this._currentPage || force )
			{
				this._currentPage = pageIndex;
				$(this).trigger( TrayEvents.PAGE_CHANGED, [ pageIndex ] );					
				this._layout();
			}
		},

		/**
			get the current tray page
		*/
		page: function() { return this._currentPage; },

		/**
			get the number of pages possible to display, this is the total width of the slider
			divided by the width of the tray, and rounded up to the next whole integer.
		*/
		numPages: function() { 
			if ( !this._pageIndexOffsets ) this._computePageIndexOffsets();
			return this._pageIndexOffsets.length;
		},

		/**
			move the slider to the next page
		*/
		moveToNextPage: function() { this.setPage( this.page() + 1 ); },

		/**
			move the sldier to the previous page
		*/
		moveToPreviousPage: function() { this.setPage( this.page() - 1 ); },

		/**
			select the icon at a given index.
			to deselect the current icon and not select any others, pass -1
			fires TrayEvents.SELECT to notify the selection of an icon, or TrayEvents.SELECT_NONE to signal
			deselection of any/all icons.
		*/
		selectIconAtIndex: function( iconIndex, silent )
		{
			silent = (silent===undefined) ? false : silent;
			var changed = iconIndex != this.currentIconIndex();
			if ( silent ) changed = false;

			var scope = this;
			this._slider.children().each( function( idx, icon )
			{
				$(icon).toggleClass( scope._params.activeClass, idx == iconIndex );
			});

			if ( iconIndex >= 0 )
			{
				this._currentIconIndex = iconIndex;
				var info = this._iconInfos[iconIndex];
				if ( info == undefined ) info = this._slider.children()[iconIndex];

				if ( changed ) $(this).trigger( TrayEvents.SELECT, [ iconIndex, info ])
				this.setPage( this.pageIndexForIconIndex( iconIndex ));
			}
			else
			{
				this._currentIconIndex = null;
				if ( changed ) $(this).trigger( TrayEvents.SELECT_NONE );
			}
		},

		currentIconIndex: function() { return this._currentIconIndex; },

		selectPreviousIcon: function()
		{
			if ( this._currentIconIndex != null && this._currentIconIndex > 0 )
			{
				this.selectIconAtIndex( this._currentIconIndex - 1 )
			}
			else
			{
				this.selectIconAtIndex( this.numIcons() - 1 )
			}
		},

		selectNextIcon: function()
		{
			if ( this._currentIconIndex != null && this._currentIconIndex < (this.numIcons() - 1) )
			{
				this.selectIconAtIndex( this._currentIconIndex + 1 )
			}
			else
			{
				this.selectIconAtIndex( 0 )
			}
		},

		numIcons: function()
		{
			return this._slider.children().length;
		},

		icons: function()
		{
			return this._slider.children();
		},

		add: function( arg )
		{
			// the argument is an array, so recurse on self to add each entry
			if ( arg instanceof Array )
			{
				for ( var i = 0; i < arg.length; i++ )
				{
					this.add.call( this, arg[i] );
				}

				return;
			}

			this._iconInfos.push( arg );

			// the argument is an antry to add
			var icon = $('<div class="' + this._params.iconClass + '"><img src="' + arg.icon + '" width="' + arg.width + '" height="' + arg.height + '" /></div>' );
			icon.css( {
				position: 'absolute',
				top: 0
			});

			var iconIndex = this._slider.children().length;

			this._slider.append( icon );

			icon.click( function( scope )
			{
				return function(e){ scope.selectIconAtIndex( iconIndex ); }
			}(this))

			this._layout( false );
		},

		pageIndexForIconIndex: function( iconIndex )
		{
			var icon = $(this._slider.children()[iconIndex]);
			var pageWidth = this._tray.innerWidth();
			if ( icon[0] )
			{
				var left = icon.position().left,
				    right = left + icon.outerWidth(),
				    pageIndex = 0;

				// find the offset

				for ( var i = 0; i < this._pageIndexOffsets.length; i++ )
				{
					var offset = this._pageIndexOffsets[i];
					if ( right > offset ) pageIndex = i;
				}

				return pageIndex;
			}

			return 0;
		},

		_computePageIndexOffsets: function()
		{
			this._pageIndexOffsets = [0];

			if ( this._tray.innerWidth() < this._slider.outerWidth() )
			{
				var scope = this;
				var pageBoundary = this._tray.innerWidth();
				var page = 0;

				this._slider.children().each( function( idx, icon )
				{
					icon = $(icon);
					var left = icon.position().left,
					    right = left + icon.outerWidth();

					if ( left <= pageBoundary && right > pageBoundary )
					{
						scope._pageIndexOffsets.push( Math.floor(left) );

						pageBoundary -= ( right - pageBoundary );
						pageBoundary += scope._tray.innerWidth();
						pageBoundary = Math.round( pageBoundary );
					}	
				});
			}
		},

		_layout: function( animate )
		{
			if ( animate == undefined ) animate = true;

			//
			// lay out children from left to right, and sum up width to resize the slider
			//

			var x = 0;
			this._slider.children().each( function( idx, icon )
			{
				icon = $(icon);
				icon.css( {
					top: 0,
					left: x + 'px'
				});

				x += icon.outerWidth();
			});

			this._slider.css( "width", x + "px" );

			this._computePageIndexOffsets();
			this._slider.clearQueue();
			

			if ( this.numPages() > 1 )
			{
				//
				//	now move to slider to match our current page.
				//


				if ( animate )
				{
					this._slider.animate(
					{
						left: - this._pageIndexOffsets[this._currentPage] + 'px'
					});
				}
				else
				{
					this._slider.css(
					{
						left: - this._pageIndexOffsets[this._currentPage] + 'px'
					});
				}
			}
			else
			{
				//
				//	the slider is narrower than the display area, so keep it centered
				//

				this._slider.css({
					left: (this._tray.innerWidth() - this._slider.outerWidth())/2 + 'px'
				});
			}


		}	
	});
	
	var _VideoControls = {

		// Show the Play/Pause button
		PLAY_PAUSE_CONTROL: 1,

		// Show the video scrubber bar
		SCRUBBER_CONTROL: 2,

		// Show the current time and total video duration
		TIME_CONTROL: 4,

		// Show the volume control
		VOLUME_CONTROL: 8,

		FULLSCREEN_CONTROL: 16,

		// Show all controls
		ALL_CONTROLS: 31,

		// show just playpause/scrubber/fullscreen
		COMPACT: 19

	};

	var _VideoScaleMode = {

		// Fit the video to available area, retaining aspect and showing all
		FIT: "fit",

		// Fill the available area, retaining aspect but possibly cutting off the edges
		FILL: "fill",

		// Show the video at native resolution, centered
		NATURAL: "natural",

		// Stretch the video to fill the available area
		STRETCH: "stretch"
	};

	var _VideoPlayer = Class.extend({

		init: function( videoURL, posterURL, width, height, videoControlMask, videoScaleMode )
		{
			this._playerURL = "SZVideoPlayer.swf";
			this._width = width;
			this._height = height;
			this._flashvars = {
				VideoURL: videoURL,
				PosterURL: posterURL,
				VideoControlMask: videoControlMask || _VideoControls.ALL_CONTROLS,
				VideoScaleMode: videoScaleMode || _VideoScaleMode.FIT,
				ControlBarWidth: 0
			};

			// compute ID for this instance
			this._playerID = "_VideoPlayerEmbed_" + String( Math.round(Math.random() * 999999) );
		},

		setPlayerURL: function( su )
		{
			this._playerURL = su;
		},

		playerURL: function(su)
		{
			return this._playerURL;
		},

		id: function()
		{
			return this._playerID;
		},

		embed: function( container, callback )
		{
			var scope = this;
			// clear any existing instance
			this.remove();

			// SWFObject will obliterate 'proxy'
			var proxy = $('<div></div>').attr( 'id', this.id() );

			this._wrapper = $('<div></div>').css( 
			{
				position: "relative",
				width: "100%",
				height: "100%"
			} );
			
			this._wrapper[0].__player = this;
			
			this._wrapper.append( proxy );
			container.append( this._wrapper );
			
			var params = { wmode: "opaque", allowFullScreen: "true" };
			var attributes = 
			{ 
				id: this.id(),
				style: "position: absolute; left: 0; top: 0; right: 0; bottom: 0; width: 100%; height: 100%"
			};
			
			swfobject.embedSWF( this._playerURL, this.id(), "100%", "100%", "9.0.0", null, this._flashvars, params, attributes, function(e)
			{
				if ( e.success )
				{
					e.ref.__player = scope;
				}

				if ( callback !== undefined ) callback(e);
			} );
		},

		remove: function()
		{
			if ( this.player() )
			{
				swfobject.removeSWF( this.id() );
			}
			
			if ( this._wrapper )
			{
				this._wrapper.remove();
				delete this._wrapper;
			}			
		},

		player: function()
		{
			return document.getElementById( this.id() );
		},
		
		/**
			Get the div wrapping the video player. This is useful if you
			want to fade in or fade out the player, since jquery at least 
			can't fade in/out the flash object itself.
		*/
		wrapper: function() { return this._wrapper; }

	});
	
	_VideoPlayerForDOMNode = function( obj )
	{
		return obj.__player;
	}

	var _AudioPlayer = _VideoPlayer.extend({

		init: function( audioURL, posterURL, width, height )
		{
			this._playerURL = "SZVideoPlayer.swf";
			this._width = width;
			this._height = height;

			this._flashvars = {
				AudioURL: audioURL,
				PosterURL: posterURL,
				ControlBarWidth: 0
			};

			// compute ID for this instance
			this._playerID = "_AudioPlayerEmbed_" + String( Math.round(Math.random() * 99999 ) );
		}

	});	
	

	///////////////////////////////////////////////////////////////////
	
	var _VideoGalleryOverlay = Class.extend({
		
		init: function( params )
		{
			this._created = false;
			
			this._params = 
			{
				initialVideoIndex: 0,
				shieldClass: 'vg_shield',
				galleryClass: 'vg_window',
				closeClass: 'vg_window_close',
				presenterClass: 'vg_presenter',
				carouselClass: 'vg_thumbnail_carousel',
				videos: [],
				videoThumbSize: 48,
				videoCarouselTitleClass: 'vg_carousel_title',
				videoCarouselSubtitleClass: 'vg_carousel_subtitle',
				videoCarouselThumbClass: 'vg_carousel_thumb',
				carouselIteratorClass: 'vg_carousel_iterator',
				carouselPageIndicatorClass: 'vg_carousel_page_indicator',
				carouselPageIndicatorActiveImg: 'assets/page_dot_active.png',					
				carouselPageIndicatorInactiveImg: 'assets/page_dot_inactive.png',
				videoPlayerSWFURL: 'videos/SZVideoPlayer.swf',
				trayParams: 
				{
					sliderClass: 'slider',
					iconClass: 'vg_carousel_item',
					activeClass: 'active'						
				}					
			};

			$.extend( true, this._params, params );
		},
		
		videos: function() { return this._params.videos; },
		
		available: function(){ return this._params.videos && this._params.videos.length },
		
		show: function( videoIndex )
		{
			if ( !this._created ) 
			{
				this._create();
				this._created = true;
			}
			
			videoIndex = (videoIndex === undefined) ? this._params.initialVideoIndex : videoIndex;

			// hide overflow, and make certain the shield and gallery are at the end of the document
			$(document.body).css( 'overflow', 'hidden' ).append( this._shield ).append( this._gallery );
			if ( $.browser.msie ) document.body.scroll = "no";

			this._shield.css( 'top', this._scroll() + 'px' ).fadeIn();
			this._gallery.stop(true).fadeIn()
						
			this._layout();
			this._trayMovedToPage();
			this.showVideoAtIndex( videoIndex );
		},
		
		hide: function()
		{
			$(document.body).css( 'overflow', 'auto' );
			if ( $.browser.msie ) document.body.scroll = "yes";

			this._shield.fadeOut();
			this._gallery.fadeOut();
			
			if ( this._player )
			{
				this._player.remove();
				this._player = null;
			}
		},
		
		showVideoAtIndex: function( index )
		{				
			// our internal _params.videos array is already in the format required by SlideRenderer
			this._layout();
			this._tray.selectIconAtIndex( index, true );

			if ( this._player )
			{
				this._player.remove();
				this._player = null;
			}
			
			var info = this._params.videos[index];
			this._player = new _VideoPlayer( info.video, info.poster, info.width, info.height );
			this._player.setPlayerURL( this._params.videoPlayerSWFURL );
			this._player.embed( this._presenter );
		},
		
		_trayMovedToPage: function( pageIndex )
		{
			pageIndex = pageIndex === undefined ? this._tray.page() : pageIndex;
			
			this._trayPageIndicator.empty();

			if ( this._tray.numPages() > 1 )
			{
				for ( var i = 0; i < this._tray.numPages(); i++ )
				{
					this._trayPageIndicator.append( $('<img/>').attr( 'src', 
						i == pageIndex ? this._params.carouselPageIndicatorActiveImg : this._params.carouselPageIndicatorInactiveImg
					))
				}
			}

			if ( this._tray.page() > 0 ) this._trayPagePrev.show();
			else this._trayPagePrev.hide();

			if ( this._tray.page() < this._tray.numPages() - 1 ) this._trayPageNext.show();
			else this._trayPageNext.hide();
			
			
		},
		
		_create: function()
		{
			var scope = this;
			
			/*
			<div class="vg_shield"></div>
			<div class="vg_window">

				<div class="vg_presenter"></div>
				<div class="vg_thumbnail_carousel">

					<div class="icon" id="vg_asset0">
						<img src="demo_assets/1.png" width="60" height="60"/>
						<p class="title">This is Asset One</p>
						<p class="subtitle">1hr 30min</p>
					</div>
					...
				</div>
				
				<div class="vg_carousel_iterator previous">Previous</div>
				<div class="vg_carousel_iterator next">Next</div>
				<div class="vg_carousel_page_indicator">
					<span class="vg_page_indicator_active"></span>
					<span class="vg_page_indicator_inactive"></span>
					<span class="vg_page_indicator_inactive"></span>
					...
				</div>

				<div class="vg_window_close">Close</div>
			</div>
			*/
			
			this._shield = $('<div></div>').addClass( this._params.shieldClass );
			$(document.body).append( this._shield );
			
			this._gallery = $('<div></div>').addClass( this._params.galleryClass );
			this._presenter = $('<div></div>').addClass( this._params.presenterClass );
			this._trayNode = $('<div></div>').addClass( this._params.carouselClass );
			this._gallery.append( this._presenter );
			this._gallery.append( this._trayNode );
			
			// tray page iterator buttons
			this._trayPagePrev = $('<div></div>').addClass( this._params.carouselIteratorClass ).addClass( 'previous' );
			this._trayPageNext = $('<div></div>').addClass( this._params.carouselIteratorClass ).addClass( 'next' );
			this._gallery.append( this._trayPagePrev );
			this._gallery.append( this._trayPageNext );

			// tray page indicator display
			this._trayPageIndicator = $('<div></div>').addClass( this._params.carouselPageIndicatorClass );
			this._gallery.append( this._trayPageIndicator );
			
			this._closeButton = $('<div></div>').html( "Close" ).addClass( this._params.closeClass );
			this._gallery.append( this._closeButton );				
			
			$(document.body).append( this._gallery );
			
			// now add videos to the _tray
			// the input format is:

			/* 
				{ 
					title: 'Boys Beware', 
					subtitle: 'Ridiculous anti-gay video from the 50s', 
					video: 'assets/BoysBeware.flv', 
					poster: 'assets/BoysBeware.jpg', 
					height: 240,
					width: 320
				}
			*/

			for ( var i = 0; i < this._params.videos.length; i++ )
			{
				var videoInfo = this._params.videos[i];
				var item = $('<div></div>').addClass( this._params.trayParams.iconClass );
				item.append( $('<img />' ).addClass( this._params.videoCarouselThumbClass ).attr({
					src: videoInfo.poster,
					height: this._params.videoThumbSize,
					width: (this._params.videoThumbSize * videoInfo.width)/videoInfo.height
				}))
				
				if ( videoInfo.title && videoInfo.title.length ) 
				{
					item.append( $('<p></p>').addClass( this._params.videoCarouselTitleClass ).html( videoInfo.title ));
				}
				
				if ( videoInfo.subtitle && videoInfo.subtitle.length ) 
				{
					item.append( $('<p></p>').addClass( this._params.videoCarouselSubtitleClass ).html( videoInfo.subtitle ));
				}
				
				item.find( 'img' ).bind( 'load complete', function(e)
				{
					if ( scope._tray ) scope._tray._layout();
				})
				
				this._trayNode.append( item );					
			}
			
			// now create the tray				
			this._tray = new _Tray( this._trayNode, this._params.trayParams );

			this._player = null;
			
			// bind events
			this._shield.click( function(){ scope.hide(); });				
			this._trayPagePrev.click( function(){ scope._tray.moveToPreviousPage() } );
			this._trayPageNext.click( function(){ scope._tray.moveToNextPage() } );
			
			$(this._tray).bind( TrayEvents.SELECT, function( event, iconIndex, icon )
			{
				scope.showVideoAtIndex( iconIndex );
			});

			$(this._tray).bind( TrayEvents.PAGE_CHANGED, function( event, pageIndex )
			{
				scope._trayMovedToPage( pageIndex );
			});	
			
			this._closeButton.click( function(e)
			{
				e.preventDefault();
				scope.hide();
			})

			$(window).resize( function(){ scope._layout(); } );
			this._layout();				
		},
		
		_layout: function()
		{
			this._tray._layout();
			
			var totalHeight = this._gallery.outerHeight() + this._trayPageIndicator.outerHeight();
			
			this._gallery.css( {
				
				left: (this._shield.innerWidth()-this._gallery.outerWidth())/2 + 'px',
				top: this._scroll() + (this._shield.innerHeight()-totalHeight)/2 + 'px'
				
			});
						
			var carouselPosition = this._trayNode.aPosition();
			
			this._trayPagePrev.css( {
				position: "absolute",
				left: carouselPosition.left,
				top: carouselPosition.top + (this._trayNode.outerHeight()-this._trayPagePrev.outerHeight())/2
			});

			this._trayPageNext.css( {
				position: "absolute",
				left: carouselPosition.left + this._trayNode.outerWidth() - this._trayPageNext.outerWidth(),
				top: carouselPosition.top + (this._trayNode.outerHeight()-this._trayPageNext.outerHeight())/2
			});
			
			this._trayPageIndicator.css( {
				position: 'absolute',
				left: carouselPosition.left,
				top: carouselPosition.top + this._trayNode.outerHeight(),
				width: this._trayNode.outerWidth()					
			});		
		},
		
		_scroll: function()
		{
			if ( window.scrollY !== undefined ) return window.scrollY;

			// FUCKING IE
			return Math.max( document.body.scrollTop, document.body.parentNode.scrollTop );
		}
	});
	
	var _EmbedVideo = function( container, videoURL, posterURL, width, height, swfPath )
	{
		container.empty().css( { width: width + 'px', height: height + 'px' });
		var vp = new _VideoPlayer( videoURL, posterURL, width, height );
		if ( swfPath !== undefined ) vp.setPlayerURL( swfPath );
		vp.embed( container );
	}


	///////////////////////////////////////////////////////////////////

	
	return {		
		Gallery: _VideoGalleryOverlay,
		VideoPlayer: _VideoPlayer,
		VideoScaleMode: _VideoScaleMode,
		VideoControls: _VideoControls,
		EmbedVideo: _EmbedVideo		
	}
}()

///////////////////////////////////////////////////////////////////////

$(document).ready( function()
{
	//
	// Flash Video is pretty weird about absolute vs relative paths, so let's just go with absolute
	//
	
	var base = '/content/viewpoints/reputation/';
	var full = 'http://' + document.domain + base;
	
	window.gallery = new videogallery.Gallery({
		videoThumbSize: 72,
		carouselPageIndicatorInactiveImg: base + '_assets/images/video_gallery/page_dot_inactive.png',
		carouselPageIndicatorActiveImg: base + '_assets/images/video_gallery/page_dot_active.png',
		videoPlayerSWFURL: base + 'videos/SZVideoPlayer.swf',		
		
		
		videos: [
			{ 
				title: 'Introducing ROR Indicator: State of the Retail Industry', 
				subtitle: 'Sandy Kennedy<br/>president, RILA', 
				video: full + 'videos/Sandy_to_cam.flv', 
				poster: full + 'videos/Sandy_to_cam.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'Community Activism and Social Media', 
				subtitle: 'Evan Kraus<br/>director, APCO Online', 
				video: full + 'videos/Evan_Kraus.flv', 
				poster: full + 'videos/Evan_Kraus.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'Building Reputation Capital and the Litigation Environment', 
				subtitle: 'Mike Hotra<br/>senior vice president, APCO Worldwide', 
				video: full + 'videos/Mike_Hotra.flv', 
				poster: full + 'videos/Mike_Hotra.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'Community Engagement: How Reputation is Built on a Local Level', 
				subtitle: 'Sandy Kennedy<br/>president, RILA', 
				video: full + 'videos/Sandy_community_involvement.flv', 
				poster: full + 'videos/Sandy_community_involvement.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'How the ROR Indicator Can Help Retail Companies', 
				subtitle: 'Sandy Kennedy<br/>president, RILA', 
				video: full + 'videos/Sandy_how_ROR_can_help.flv', 
				poster: full + 'videos/Sandy_how_ROR_can_help.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'Importance of Retail\'s Reputation to Investors', 
				subtitle: 'Sandy Kennedy<br/>president, RILA', 
				video: full + 'videos/Sandy_importance_of_reputation.flv', 
				poster: full + 'videos/Sandy_importance_of_reputation.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'The Impact of Reputation on Consumer Behavior', 
				subtitle: 'Sandra Taylor<br/>former SVP, corporate social responsibility, Starbucks', 
				video: full + 'videos/Sandra1.flv', 
				poster: full + 'videos/Sandra1.jpg', 
				width: 640, 
				height: 360 
			},
			{ 
				title: 'What Consumers Care About', 
				subtitle: 'Sandra Taylor<br/>former SVP, corporate social responsibility, Starbucks', 
				video: full + 'videos/Sandra2.flv', 
				poster: full + 'videos/Sandra2.jpg', 
				width: 640, 
				height: 360 
			},		
			{ 
				title: 'How Policy Makers Respond to Reputation', 
				subtitle: 'Former Sen. Donald W. Riegle, Jr. (D-Mich.)<br/>chairman, government affairs, APCO Worldwide', 
				video: full + 'videos/Riegle.flv', 
				poster: full + 'videos/Riegle.gif', 
				width: 640, 
				height: 360 
			}
		]
	});
	
	//
	//	if the gallery has videos, watch for a.video links and use their rel attr to show a video
	//

	if ( window.gallery && window.gallery.available() )
	{
		$("a.video").live( 'click', function(e)
		{
			e.preventDefault();
			var videoIdentifier =  $(this).attr( 'rel' );
			var videoIndex = parseInt( videoIdentifier, 10 );
			if ( isNaN(videoIndex))
			{
				var videoIdentifierLC = videoIdentifier.toLowerCase();
				var keys = ["title","subtitle", "video", "poster"];
				// then let's try some barely pseudo-fuzzy matching
				for ( var i = 0; i < window.gallery.videos().length; i++ )
				{
					var info = window.gallery.videos()[i];
					
					for ( var j = 0; j < keys.length; j++  )
					{
						var key = keys[j];
						if ( info[key].toLowerCase().indexOf( videoIdentifierLC ) >= 0 )
						{
							videoIndex = i;
							break;
						}
					}
					
					if ( !isNaN(videoIndex)) break;
				}
			
				// no dice
				if ( isNaN(videoIndex))
				{
					videoIndex = 0;
				} 
			}
			
			window.gallery.show( videoIndex );
		})
	}
	else
	{
		$('a.video').hide();
	}	
});
