/* CAP Flowplayer script
 *
 * Copyright (c) 2009-2011 Evan Hensleigh
 * for Center for American Progress
 */

(function() {
	var loc = window.location;
	var h = loc.host.split('.');

	var keys = {
		'americanprogress': '#@b6aaccc400904bab969',
		'techprogress': '#@ef598384bb40b3ccde2'
	}

	var flow_conf = this.flow_conf = {
		defaults: {
			key: '#@fae15a997f67f7892e5',
			clip: {
				autoPlay: true,
				autoBuffering: true,
				onStart: function (clip) {
					_gaq.push(['_trackEvent', 'videos', 'play', clip.url]);
				}
			},
			plugins: {
/*				gatracker: {
					url: '/images/rd2/flash/flowplayer.analytics-3.2.2.swf',
					events: {
						all: true
					},
					accountId: "UA-246439-2"
				}, */
/*				TMPlugin: {
					url: '/images/rd2/flash/flowplayer.tubemogul.swf',
					playerID: 'P-YFD-NID'
				}, */
				sharing: {
					url: '/images/rd2/flash/flowplayer.sharing-3.2.1.swf',
					embed: {
						autoBuffering: false,		// shut off autoPlay
						autoPlay: false				// for embedded videos
					}
				}
			}
		}
	}
	
	flow_conf.defaults.key = keys[h[h.length - 2]];

	jQuery.fn.embedClicker = function(embed_display_name) {
	
		var showEmbed = false;

		return this.each(function() {
			var target = $(this);
			var name = target.attr('id').split('_')[0];
			var embed_display = $(embed_display_name);
			target.click(function() {
				if (showEmbed) {
					target.text('Show Embed Code');
					showEmbed = false;
					embed_display.hide();
					$f().show();
				} else {
					target.text('Hide Embed Code');
					showEmbed = true;
					embed_display.show();
					$f().hide();
				}
			});
		}).hide();				// the "hide" here is because it's legacy functionality
								// but may be restored if/when we switch to iframe embedding
	}
}).call(this);
