/***** en_US/components/video/javascripts/players/flash.js *****/
Syn.VideoPlayersFlash = Syn.VideoPlayers.extend({
	/**
	 * Constructor.
	 * @param {Object} config
	 */
	init: function(config)
	{
		this._super(config);

		var url = config.url;
		var ads = config.ads;
		var cdn = config.cdn;
		var category = config.category;
		var id = config.id;
		var title = config.title;
		var flashreport_url = config.flashreport_url;

		if (!url)
		{
			return;
		}

		var video_config = new Syn.VideoPlayer.Config();

		video_config.item = {
			url:url,
			type:"video",
			ads:ads,
			cdn:cdn,
			tags:category,
			title:title,
			flashreport_url:flashreport_url,
			id:id
		};
		video_config.plugins = { ads:true, controls:{share:true} };

		var video_player = new Syn.VideoPlayer({
			videoConfig: video_config,
			targetdiv: this.uniqueKey(config.targetdiv, true)
		});

		video_player.addCallback("complete", this, this.videoDidFinishPlaying);
		video_player.addCallback("showBannerAd", this, this.showBannerAd);
		video_player.addCallback("hideBannerAd", this, this.hideBannerAd);
		video_player.addCallback("noAdLoaded", this, this.showSwapAd);
		video_player.addCallback("email", this, this.email);

		this.video_player = video_player;
		this.title = title;
	},

	/**
	 * Override the parent method to prevent this class from logging to
	 * flashreport.  The Synacor player does its own flashreport-ing and
	 * we don't want to duplicate hits.
	 *
	 * @return {bool} Whether JavaScript flashreport-ing is enabled for this player.
	 */
	shouldLogFlashreport: function()
	{
		return false;
	},

	/**
	 * Show the banner ad.
	 * @param {String} display_url
	 * @param {String} click_url
	 */
	showBannerAd: function(display_url, click_url)
	{
		this.video_player.insertAd(this.uniqueElmt("ad_container"), display_url, click_url, 300, 250);
	},

	/**
	 * Hide the banner ad.
	 */
	hideBannerAd: function()
	{
		// Currently do nothing. Maybe do something later.
	},

	/**
	 * Show a swap ad if video ad requests are not filled.
	 */
	showSwapAd: function()
	{
		var swap_ad_fn = function(res)
		{
			if (res.content)
			{
				this.uniqueElmt("ad_container").html(res.content);
			}
		};

		this.getComponent('component://Synacor/Sa/Components/AdPlacement/video_main_atf_300x250/', '', {}, this, swap_ad_fn);
	},

	/**
	 * Called when a user clicks the "email" button in the video player.
	 */
	email: function()
	{
		//Strip any current url params and add one for an email referral
		var video_url = String(window.location).replace(/\?.*/, "").concat("?referrer=email");

		var subject = "Check out this video";
		var body = "Here is a video I thought you would enjoy:\n\n" + this.title + "\n" + video_url;
		var email = "mailto:?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);

		//This should not actually change the location. Since it is a mailto:
		//url, it opens the email client, leaving the user on the video page.
		Syn.Helpers.redirect(email);
	}
});
;
/***** en_US/components/video/javascripts/browse.js *****/
Syn.VideoBrowse = Syn.Component.extend({
	/**
	 * Constructor.
	 * @param {Object} config
	 */
	init: function(config)
	{
		this._super(config);
		this.bindEvents();
	},

	/**
	 * Bind the various events.
	 * We are using this method instead of liveconnect due to the various
	 * issue we've (the portal team) have encountered using live bindings.
	 */
	bindEvents: function()
	{
		this.hrefToAjax(this.find("div.video_nav a"));
		this.hrefToAjax(this.find("div.pagination a"));
		this.find("div.video_nav a").connect("click", this, "showLoading", [{ target: this.find("div.vb_body") }]);
		this.find("div.pagination a").connect("click", this, "showLoading", [{ target: this.find("div.vb_body") }]);
		this.find("form.filter_form").connect("submit", this, "submitFilter");
		this.find("form.filter_form select").connect("change", this, "filterChanged");
		this.find("form.search_form").connect("submit", this, "submitSearch");

		// Add in placeholder text
		this.container().find("input").each(function()
		{
			var alt = $(this).attr("alt");
			if (alt)
			{
				var set_label_fn = function()
				{
					if ($(this).val() === "")
					{
						$(this).val(alt);
						$(this).addClass("placeholder");
					}
				};

				var remove_label_fn = function()
				{
					if ($(this).val() == alt)
					{
						$(this).val("");
						$(this).removeClass("placeholder");
					}
				};

				set_label_fn.apply(this);
				$(this).bind("focus", remove_label_fn); 
				$(this).bind("blur", set_label_fn);
			}
		});
	},

	/**
	 * The filter (subcategory) has changed.
	 * @param {Object} element
	 */
	filterChanged: function(element)
	{
		$(element).parents("form").eq(0).submit();
	},

	/**
	 * Change the subcategory.
	 * @param {Object} element
	 */
	submitFilter: function(element)
	{
		var qs = $(element).attr("action");
		var data = this.queryStrToObject(qs);
		var subcat = $(element).find("select").val();
		if (subcat)
		{
			data.subcategory = subcat;
		}

		this.submit(data);
		return false; 
	},

	/**
	 * Callback after ajax has updated.
	 * @param {Object} config
	 */
	onAjaxUpdate: function(config)
	{
		this.config = config;
		this.bindEvents();
	},

	/**
	 * Submit the search.
	 * @param {Object} element
	 */
	submitSearch: function(element)
	{
		var url = $(element).attr("action");
		var parameters = this.queryStrToObject(url);
		var search_field = $(element).find("input[name=search]");
		var search_string = search_field.val();

		// If search string is blank, or the search string is the same string
		// as the placeholder text, do not perform the ajax request.
		if (!search_string || search_field.attr("alt") == search_string)
		{
			return false;
		}

		// Show loading indicator
		this.showLoading({ target: this.find("div.vb_body") });

		parameters.action = "search";
		parameters.search = search_string;

		this.submit(parameters);
		return false;
	}
});
;
/***** en_US/components/tabbed/scripts/tabbed.js *****/
/**
 * The Syn.Tabbed Component Class
 */

/**
 * Create a Syn.Tabbed component instance
 * @constructor
 */
Syn.Tabbed = Syn.Component.extend(
{
	/**
	 * Initialize the component class. This is called automatically by the default constructor.
	 * @member Syn.Tabbed
	 * @param {Object} config The configuration data structure
	 */
	init: function(config)
	{
		//Init parent class
		this._super(config);
		var cache = (config.cache === undefined) ? true : config.cache;
		this.hrefToAjax($('#' + this.uniqueKey('tabs') + ' li > a'), "changeTabSetup", {cache:cache});
	},

	/**
	 * Called before ajax update.
	 * @member Syn.Tabbed
	 * @param {DOM} dom The Document Object Model
	 * @param {event} event The current event
	 */
	changeTabSetup: function(dom, event)
	{
		this.showLoading({target: this.find('.tabbed_body')});
	},

	/**
	 * Called on ajax update.
	 * @member Syn.Tabbed
	 * @param {Object} config The configuration data structure
	 */
	onAjaxUpdate: function(config)
	{
		//Recalculate column heights in case we need to grow larger or shrink the page
		this.resizeColumns();
	},

	/**
	 * Used to resize columns after the component has changed its size
	 */
	resizeColumns: function()
	{
		var cdr = Syn.ComponentMgr.getInstancesByClass('Syn.ComponentDiscoveryReveal');

		if (cdr[0])
		{
			cdr[0].resizeColumns();
		}
	}
});
;
