var movideoplayerutil = {
	autoPlayQueryNames: [ 'movideo_m', 'movideo_p', 'movideo_c', 'movideo_ml', 'movideo_st', 'movideo_stl' ],
	
	/**
	 * Embed the movideo player, setting the autoPlay flag to true if URL query has been set
	 * for media, playlist or channel
	 */
	embedPlayer: function(element, alias, apiKey, width, height, customVars) {
		var query = window.location.search.substring(1);
		var pairs = query.split("&");
		var name;
		
		// Loop through query params
		for (var i = 0; i < pairs.length; i++)
		{
			name = pairs[i].substring(0, pairs[i].indexOf("="))
			if (movideoplayerutil.isAutoPlayQueryName(name))
			{
				if (typeof customVars == 'undefined')
					customVars = {};
				
				customVars.autoPlay = true;
				break;
			}
		}
		
		return movideoplayer.embedPlayer(element, alias, apiKey, width, height, customVars);
	},
	
	/**
	 * Checks if the given name param matches any of the possible auto play query names
	 */
	isAutoPlayQueryName: function(name) {
		var pos = movideoplayerutil.autoPlayQueryNames;
		var poslength = pos.length;
		for (var i = 0; i < poslength; i++)
		{
			if (pos[i] == name)
				return true;
		}
		return false;
	}
};
