/* EMP embedding. 

Exports global variable: 
	rw_video

*/

/* Requires Glow, /emp/swfobject.js & /emp/embed.js */

window.rw_video = (function() {

	function write_emp(emp_id, playlist_url) {

		var emp = new embeddedMedia.Player();
		emp.setWidth("448"); 
		emp.setHeight("287");
		emp.setDomId(emp_id); 
		emp.set("config_settings_skin", "silver"); 
		emp.setPlaylist(playlist_url);
		emp.write();
	}
	//-----

	return {

		// show video, then re-display error message text if not replaced
		display_video: function (

			playlist_url // playlist url
			, emp_id // id of video container
			, no_content_classname // class of "no video" message
			, b_fit_to_446 // if true, EMP is in a 446px container, so tweak sizes

			) {

			var ns_message = [] // nodeset of 'no video' message
				ns_emp = glow.dom.get('#'+emp_id)

				;

			try	{	
				if (b_fit_to_446) {
					// Now, video is 448 but likely to be in column 446px wide - so adjust video & caption to fit each other
					ns_emp.css("margin-left", "-2px");
					ns_emp.parent().get(".caption").css("margin-left", "-2px");
				}

				write_emp(emp_id, playlist_url);  		
			}
			finally {
				// If JS and Flash are both enabled, we don't want to flash up the error message before loading the video.
				// So use CSS to blank out error message (using 'visibility') if JS is enabled, then re-enable using JS. 
				ns_message = glow.dom.get('#'+emp_id+' .'+no_content_classname);
				if (ns_message.length > 0) 
					ns_message.css("visibility", "visible");
			}

		},
		//-----

		dummy_field: null // so all other field values can end in ","

	};

})();

/* end of script */