;var AttachedVideo = (function($) {
	var me = {};
	
	/* The UI dialog that will house the video */
	me.dialog = null;
	
	/* A list of flash video <object> providers. */
	me.providerObjects = {
		'youtube' : '<object width=":width" height=":height"><param name="movie" value="http://www.youtube.com/v/:video&amp;hl=en&amp;fs=1" /><param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /><embed src="http://www.youtube.com/v/:video&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width=":width" height=":height"></embed></object>'			
	};
	
	/**
	 * Pops up the embedded video.
	 * @param obj The <a> that was clicked
	 */
	me.popup = function(obj) {
		//Read the metadata from the <a>
		var data = $(obj).metadata();
		//Populate the <object> code
		var video = me.providerObjects[data.provider]
          .replace(/:width/g,  data.width)
          .replace(/:height/g, data.height)
          .replace(/:video/g,  data.video);
		//Show the video in a dialog
		me.dialog.dialog('option', 'width', parseInt(data.width) + 28);
		if ($.browser.msie || $.browser.opera) {
		  me.dialog.dialog('option', 'height', parseInt(data.height) + 80);
		}
		else {
          me.dialog.dialog('option', 'height', parseInt(data.height) + 60);
		}
		me.dialog.dialog('open');
		me.dialog.html(video);
	};
	
	return me;
}
)(jQuery); 
;jQuery(function($) {
	if (0 == $('div#AttachedVideoDialog').length) {
		$('body').append('<div id="AttachedVideoDialog"></div>');
	}
	AttachedVideo.dialog = $('div#AttachedVideoDialog');
	AttachedVideo.dialog.dialog({ autoOpen:false, height: 410, width: 630, modal:true, closeOnEscape:true, resizable:false, beforeclose:function() { AttachedVideo.dialog.html(''); }});
	$('a.video-embed-url, a.video-embed-img').click(function(e) {
		AttachedVideo.popup(this);
		e.preventDefault();
	});	
});
