(function(){
	
	if(window.__fvdSingleDownloaderContentScriptInserted)	return;
	window.__fvdSingleDownloaderContentScriptInserted = true;

	const BUTTON_TITLE = "Download";
	const BUTTON_TOOLTIP = "Download";
	const ADDON_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACg0lEQVQ4jY2RW0iTYRzGn2/v+73fYYdv7jxtbnNmiXO5TheKQZCSIEJEXUrQZQXSlUJFRHgRXQUVRPeBBGInyouMgihBQUsNa6Lo5mEz3dS5fW77uvCiPNLv+nng+f3/HHbjZEeFUeKrVhJ5HWEExKXnsJocVz8lxoAnG/9G6S51ndPEt7uCjtZMMpknJj0ExnSzg5meudBaG4YxsyW8o17SUUQpV1mYihKppJgJTM+0yQSVbEoIcPi3x3cusKh2csDt1HJpcOPTgI5A85ZCUJkJkZgTAAdA23MBFfQeSV23aQ478kVWFNzF0BkU6NMZxSQZPUAT21eBMepnKjWwLAC3C5zFBjFbgMh4kfJ8Kco84r4KPBMqjALlCkRETlRACA8hnQIvcRBk2QeqMwBI7q1gtwaIzw9Z1UHijZA1EbLGgGA1qMvlQWxF2b6Ag69Nkf3OQDqV9ZDVVChbcgKCTYM5lgATGXLhINLZPLREyqcPVzWvsXtWzKV/YmQkTgAA7sb6spbTL8qb687lp5Zd+ehvrqiuBlazBL3XiQLhoH7oh/2wTy6/1FgncNKFhYnIR8QeRzYVUpODE6++vEOWKtVXznMOiwHC5wGYy1wwGXmIA8MoDXoRvlgL9Vdc/vH2ay+W0kMAtM0FK0Prhaj5zfx0XPQGA7VHm46Ai8VBZ2ZBFxZh8TsROBvCUN8oXj/sfpTvT1zD0v1lACB/zzGaK8y+742OOzOBmtL6Y2eqqTqdgOJQcKihEv293za6HjzvzA1+bweeZrcffwtiuPPy9ZeRVNd8Qete1LSrz8bWhZo7bbt9bU/k8o6W230z8Rs9E0skfLP1v4tbOHj3FD1+q2G/yB+MJNSfSgtbTQAAAABJRU5ErkJggg==";

	const EXT_I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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAg1O7SAAAAHB0Uk5T////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ALdhYtIAAADdSURBVHjaYsjPz5fkE8sRy8nJkQkFchiA2C4jTMtJ0FaH3VoIKBDs68PGIu9vGu1gn8ZuKZTPEK/naa4Qy8ZiExeZlsae48iQLMfPz2bM4i5hIisi4qXJwyCVCQW64iGGfoFWDOrMzInMDEBgEGXGmMATzuAmLMwtyMrKqpEUwejBxcUHsjYlIxUIVBmNvFNFc8AC2Wkcos6MipwCGRxQgfT0NBcmTiWBjAy4gCuTfhpHKkJAmkklAKgsOxsqkMukpp0LBHl5YIGg7FwoyMuzAAnE8GZBgTIvN0CAAQCCX0cVtLCG1QAAAABJRU5ErkJggg==",
		"3gp":  "data:image/png;base64, ",		
	    "set":  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYA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1V//1l/q39HGkzXClEfx15H73ofw2aP07N7Io3D68dz48uX+9+HjuVb+/f3myIby0Hbvxl3/3FT/9cn++On++erw2aLszon48ub+9+D++OXhw4383ofZqUn84ov/7pT9+/r944vkulj+64bjxYTkxob/44D/3nTVqUzXwqTXqknrzYfHom/003X69/P/9s7HpHD734jGlDa7hzazilLFoGzTp0vZqk3Oqm/Yw6by2qb/7rH/3VX7+fbuyF7GkjPUvZr37+GwhUb844vp28b74YnRrWm9jD3sxF2pfUDHlTmofUDku1fRrWrjw4CwhkXXwaTHlTjz0HPy0HP734f07N/yz3T/2m3iuVfz0XapfELMnEC7ijm4jk7s4tXrzof/3nD/7rPmyYe0iEPgzbLwzXTgvGbp28Xiz7X/33Xiw4D68t368t770FDSsnzFoWuqfUDLp2y/jzy4jEzGkzmofULGkzby3Kjz0nTkulfiz7Tx15D/9cr/9cvMnEH+7JT/5IH7z1DEn2r/9s3fzLHwyGX/9cyrfkDhxYzy1pC0hkXClUbsxFz68d3/3m7+/fzGlTbOqnC2jVP9/Prxy2XivmjYqkvy2JT38OP/+eTixYO8ijvkxoX96oT/2W3kvFr///98qdT8AAAAsXRSTlP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wDX9FxkAAAA9klEQVR42mLYsGH5nJkbwEA0gnvDBgYp9fWaGfzVGzbUWMfIdLIzM5iqKRf2tssbLC7ymubNKh7HsGKBHq+jv0RQfKqwIa9OCxsDw+oOq8w6SyYmT2dbXQWPDQwbWCaVLGpt7tfPzXKZYsMBFNiwIaFsLecEM07jpQFADkjAt2FqQfq6eUum20EFVPNm8QgI8hQLqUAEuP1MZivVTvQRWaXYDRSYm2+k5dbUFx2ZzWexUhbosDVcPYz2M2Ll5odpT2Zk5apiCEwMNU9xkt6wQaMtuFIsCuiw8ORlaY0g03KS3EsXghxWXyEZAvIsh2uXQ/kGgAADAAD4XjTtv1M+AAAAAElFTkSuQmCC",
		"bet":  "data:image/png;base64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PHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6MEVFNjI5RTU0MkI5MTFFMzgyMkFDRTg0NkNBQUM0MDMiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6MEVFNjI5RTY0MkI5MTFFMzgyMkFDRTg0NkNBQUM0MDMiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6N9LxFAAAAzUlEQVR42mL8//8/AyWAiYFCMPAGsMAYzs72YHrfvkMYipyc7EAUMxT/37v34G8MA4CAEah5JpBWRDfg0KGjbEBpoGv///vz5+8NoFA6XBIUC0gxsREkhIyZmJj+MzMzg2mo2AaYHrA+NANATlyHR/NaULjhMwDmrbVYNC+DBTpeA0ABZm1tJsHCwrIeSfMSqOsY0A1ghGlmZGSEhTYIsH7+/EXq9OlzXUD2PyCOA+LfyAZgxAKSZhD4zcvL8whIh+OIUkTUjeYFBoAAAwA5BYNkgcxwUgAAAABJRU5ErkJggg==",		
	};
	
	const RATE_MESSAGE_ID = "fvd-single-rate-message";

	
	// ======================  DOWNLOAD  ==============================================================
	function startDownload( media ){

		chrome.extension.sendRequest( 
			{
				command:"startDownload",
				media: media
			},	function(  ) { 		
		});
	
	}
	
	function downloadMediaItem( media ){
	
		var a = document.createElement("a");
		
		a.setAttribute( "download", media.downloadName );
		a.setAttribute( "href", media.url );			
		document.body.appendChild( a );

		var theEvent = document.createEvent("MouseEvent");
		
		theEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		
		a.dispatchEvent(theEvent);
				
		document.body.removeChild( a );
	}

	// ======================  DAILYMOTION  ==============================================================
	function buttonDailyMotion( mainMedia, port ){

		const BUTTON_ID_DM = "GetThemAll_dm_button";
					
		var clickTimer = null;
		var clickMenu = false;
		
		// ------------------------------------	
		function createButtonElementDM( buttonId ){

			var button = document.createElement("button");
			button.setAttribute("class", "tool_addto icn_right button action:toggleOrUpdate action:arg0:#moveto_container");
			button.setAttribute("data-tooltip",  BUTTON_TOOLTIP);					
			button.setAttribute("title",  BUTTON_TOOLTIP);					
			button.setAttribute("type", "button");
			button.setAttribute("style", "padding:5px; margin-top:20px");
			button.setAttribute("id", BUTTON_ID_DM);

			var div1 = document.createElement("div1");
			div1.setAttribute("style",  "margin-right:5px; float:left");					
			var img = document.createElement("img");
			img.setAttribute("src",  ADDON_IMAGE );					
			img.setAttribute("align",  "left");					
			div1.appendChild( img );
			button.appendChild( div1 );

			var div2 = document.createElement("div");
			div2.setAttribute("style",  "float:left; margin-top: -7px;");					
			div2.textContent = chrome.i18n.getMessage("button_download");
			button.appendChild( div2 );

			var div3 = document.createElement("div");
			div3.setAttribute("class",  "icn_wrap");					
			div3.setAttribute("style",  "float:left; border-left:1px solid; margin-left:5px; width:20px; padding-left:5px; height:14px");					
			var img1 = document.createElement("img");
			img1.setAttribute("src",  EXT_IMAGES["arrow_down"]);					
			img1.setAttribute("style",  "width:10px; margin:3px");					
			img1.setAttribute("align",  "left");					
			div3.appendChild( img1 );
			button.appendChild( div3 );
			
			button.addEventListener( "click", function( event ){
						
							var elem = document.getElementById('download_container');
							
							var x = elem.getAttribute("style");
							if( x.indexOf( "none" ) != -1 )
							{
								elem.setAttribute("style", "display: block; z-index: 30; position:relative;  margin-left:200px");
	
								chrome.extension.sendRequest({command:"getVideoData"  },	function( media ) { 		
								
																buildMediaListDM( media, elem );						
								
															}	);
															
								document.addEventListener("click",  click_document, true);
							}
							else 
							{
								elem.setAttribute("style", "display: none; z-index: 30; position:relative;  margin-left:200px");
								document.removeEventListener("click", click_document, true);
							}	
							
						}, false );
						
			return button;
						
		}
		
		// ------------------------------------	
		function click_document( media, parent ){
			var elem = document.getElementById('download_container');
			if (elem.style.display == 'none') return;
			if ( clickMenu )
			{
				clickMenu = false;
				return;
			}	

			clickMenu = false;
			clickTimer = setTimeout(function() {   
											elem.style.display = 'none';
										},  100 );
		}
					
		// ------------------------------------	
		function buildMediaListDM( media, parent ){

			var menus = document.getElementById('download_menu'); 
												
			var menu = null;
			if( menus )		{
				while( menus.firstChild )	{
					menus.removeChild( menus.firstChild );
				}
				menu = menus;
			}
			else   {
				menu = document.createElement( "div" );
				menu.setAttribute( "class", "dm_button_container" );
				menu.setAttribute( "style", "position: absolute; top: -1px; left: 0; border: 1px solid #ddd; -webkit-box-shadow: rgba(0,0,0,0.3) 0 0 1px; -moz-box-shadow: rgba(0,0,0,0.3) 0 0 1px; margin-right: 0; padding: 8px 0 4px;" );
				menu.setAttribute("id", "download_menu");
				parent.appendChild(menu);
							
			}
				
			for( var k in media )	{
				var m = media[k];

				var imageUrl = "";
				if( "ext" in m && m.ext in EXT_IMAGES  )	imageUrl = EXT_IMAGES[m.ext];
		
				var spani = document.createElement( "span" );
		
				var img = document.createElement("img");
				img.setAttribute("align","left");
				img.setAttribute("src", imageUrl);
				spani.appendChild(img);

				var txt = document.createElement( "span" );
				txt.setAttribute("style", "margin-left:5px;");
				if (m.format)	{
					txt.textContent = m.format + '.'+m.ext;
				}
				else	{
					if (m.title.length > 25)		{
						txt.textContent = m.title.substr(0,23) + '... .'+m.ext;
					}
					else	{
						txt.textContent = m.title + ' .'+m.ext;
					}
				}	
			
				var span = document.createElement("a");
				span.setAttribute( "class", "dm_button_select_item" );
				span.setAttribute("style", "width:150px; height: 30px; padding: 6px 6px 6px 10px !important;");
				span.setAttribute("id", "download_menu_"+k);
				span.appendChild( spani );					
				span.appendChild( txt );					
				
				(function( medToDownload, span ){
								span.addEventListener("click", function(){
									startDownload( medToDownload );
								}, true);
							})( m, span );
							
				menu.appendChild( span );					
			}
						
			menu.addEventListener( "click", function( event ){
								clickMenu = true;
								window.clearTimeout(clickTimer);
							});
					
			if( media.length == 0 )
			{
				var spani = document.createElement( "span" );
			
				var img = document.createElement("img");
				img.setAttribute("align","left");
				img.setAttribute("src", EXT_IMAGES['set']);
				spani.appendChild(img);
			
				var txt = document.createElement( "span" );
				txt.setAttribute("style", "margin-left:5px;");
				txt.textContent = 'Settings';
				
				var span = document.createElement("a");
				span.setAttribute( "class", "dm_button_select_item" );
				span.setAttribute("style", "width:150px; height: 26px; padding: 6px 6px 6px 10px !important;");
				span.appendChild( spani );					
				span.appendChild( txt );					
				span.addEventListener("click", function(){
								chrome.extension.sendMessage({action:"SettingOptions"  }, function( response ){} 					);
				}, true);
							
				menu.appendChild( span );		
			}											
					

		}	
		
		if( !document.getElementById( BUTTON_ID_DM ) )	{
			var button = createButtonElementDM( BUTTON_ID_DM );
					
			var block = document.querySelector('.pl_video_infos');
			
			var elemFlag_views_share = block.querySelector('.views_and_share');
			
			var elemFlag_media = block.querySelector('.media');
			elemFlag_media.setAttribute("style", "overflow: visible");

			var elemFlag_foreground = block.querySelector('.media-block');
			if (elemFlag_foreground) elemFlag_foreground.setAttribute("style", "width:170px; float:left");
			
			if( elemFlag_media )	{
				var dv = document.createElement("div");
				dv.appendChild( button );	
				elemFlag_media.appendChild( dv );					
				
				var div = document.createElement("div");
				div.setAttribute("style", "display: none; z-index: 30; position:relative; margin-left:150px");
				div.setAttribute("id", "download_container");
				dv.appendChild( div );	
			}	
		}
		
	}
	
	// ======================  VK video ==============================================================
	function buttonVKontakte( mainMedia ) {
	
		console.log('buttonVKontakte', mainMedia);
	
		const BUTTON_ID = "GetThemAll_vk_button";
		var clickTimer = null;
		var clickMenu = false;
		
	
		// -------------------------------------------------------------------------------------------
		function createButtonElementVK( buttonId )	{	
		
			var span1 = document.createElement("span");
			span1.setAttribute("style",  "margin-right:5px; ");					
		
			var img = document.createElement("img");
			img.setAttribute("src",  ADDON_IMAGE);					
			img.setAttribute("align",  "left");					
			span1.appendChild( img );

			var span2 = document.createElement("span");
			span2.setAttribute("style",  "background: url(/images/darr_on.gif) 0px 0px; width: 7px; height: 4px; display: inline-block; margin-bottom: 3px; margin-left: 5px; ");					
			
			var span3 = document.createElement("span");
			span3.setAttribute("style",  "width: 7px; height: 14px; display: inline-block;  position:absolute; top: 3px; left: 90px;  border-color: black; border-style: solid;  border-width: 0px 0px 0px 1px;	");					
			span3.appendChild( span2 );
			
			
			var span = document.createElement("span");
			span.setAttribute("style",  "display: inline-block; position:absolute; top: 2px; left: 25px; ");					
			span.textContent = chrome.i18n.getMessage("button_download");
	
			var button = document.createElement("button");
				
			button.setAttribute("data-tooltip",  BUTTON_TOOLTIP);					
			button.setAttribute("title",  BUTTON_TOOLTIP);					
			button.setAttribute("type", "button");
			button.setAttribute("id", BUTTON_ID);
			button.setAttribute("style",  "width:110px; height: 24px; padding: 0; position: relative");					
						
			button.appendChild( span1 );
			button.appendChild( span );
			button.appendChild( span3 );

			button.addEventListener( "click", function( event ){
						
							var elem = document.getElementById('download_container');
							
							var x = elem.getAttribute("style");
							if( x.indexOf( "none" ) != -1 )	{
								elem.setAttribute("style", "display: block; z-index: 30; position:relative;");
	
								chrome.extension.sendRequest({command:"getVideoData"  },	function( media ) { 	

																	buildMediaListVK( media, elem );						
								
															});
															
								document.addEventListener("click",  click_document, true);
								
							}
							else 
							{
								elem.setAttribute("style", "display: none; z-index: 30; position:relative;");
								document.removeEventListener("click", click_document, true);
							}	
							
						}, false );
			
			return button;
		}
		
		// ------------------------------------	
		function click_document( media, parent ){
			var elem = document.getElementById('download_container');
			if (elem.style.display == 'none') return;
			if ( clickMenu )
			{
				clickMenu = false;
				return;
			}	

			clickMenu = false;
			clickTimer = setTimeout(function() {   
											elem.style.display = 'none';
										},  100 );
		}

		// -------------------------------------------------------------------------------------------
		function buildMediaListVK( media, button  )  {
		
			var parent = document.getElementById( "download_container" );
		
			var menus = document.getElementById('download_menu'); 
												
			var menu = null;
			if( menus )		{
				while( menus.firstChild )				{
					menus.removeChild( menus.firstChild );
				}
				menu = menus;
			}
			else	{
				menu = document.createElement( "div" );
				menu.setAttribute( "style", "position: absolute; top: -1px; left: 0; border: 1px solid #ddd; -webkit-box-shadow: rgba(0,0,0,0.3) 0 0 1px; -moz-box-shadow: rgba(0,0,0,0.3) 0 0 1px; margin-right: 0; padding: 8px 0 4px; z-index: 20; color: #666666; text-align: left;   font: 13px Arial,Helvetica,Clean,Sans-serif; background:white;" );
				menu.setAttribute("id", "download_menu");
				parent.appendChild(menu);
			}
						
			var kk = 0;					
			for( var k in media )	{
				var m = media[k];	
				
				var imageUrl = "";
				if( "ext" in m && m.ext in EXT_IMAGES  )	imageUrl = EXT_IMAGES[m.ext];
		
				var spani = document.createElement( "span" );
		
				var img = document.createElement("img");
				img.setAttribute("align","left");
				img.setAttribute("src", imageUrl);
				spani.appendChild(img);

				var txt = document.createElement( "span" );
				txt.setAttribute("style", "margin-left:5px;");
				txt.textContent = m.format;
			
				var span = document.createElement("a");
				span.setAttribute("class", "mvs_act");
				span.setAttribute("style", "width:120px; padding: 6px 6px 6px 10px !important; display: block;   font-size: 13px;    height: 16px;   white-space: nowrap; cursor:pointer;");
				
				span.setAttribute("id", "download_menu");
				span.appendChild( spani );					
				span.appendChild( txt );					
			
				(function( medToDownload, span ){
								span.addEventListener("click", function(){
												startDownload( medToDownload );
											}, true);
								span.addEventListener("mouseover", function(){
												span.style.background = "#cde0e6";
											}, true);
								span.addEventListener("mouseout", function(){
												span.style.background = "white";
											}, true);
							})( m, span );
							
				menu.appendChild( span );
				kk++;	
			}
			
			if (kk==0) {	
				var spani = document.createElement( "span" );
			
				var img = document.createElement("img");
				img.setAttribute("align","left");
				img.setAttribute("src", EXT_IMAGES['set']);
				spani.appendChild(img);
			
				var txt = document.createElement( "span" );
				txt.setAttribute("style", "margin-left:5px;");
				txt.textContent = 'Settings';
				
				var span = document.createElement("a");
				span.setAttribute( "class", "dm_button_select_item" );
				span.setAttribute("style", "width:150px; height: 22px; padding: 6px 6px 6px 10px !important;");
				span.appendChild( spani );					
				span.appendChild( txt );					
				span.addEventListener("click", function(){
								chrome.extension.sendMessage({action:"SettingOptions"  }, function( response ){} 					);
				}, true);
							
				menu.appendChild( span );		
			}
		}
		
	
		// ----------------------------			
		if( !document.getElementById(BUTTON_ID) ){
				
			var button = createButtonElementVK( BUTTON_ID );
	
			var elemFlag = document.getElementById("mv_controls_line");	
			elemFlag.style.display = "block";
			
			if( elemFlag )
			{
				var dv = document.createElement("div");
				dv.setAttribute("style", "margin-left: 10px; float:right; ");
				dv.appendChild( button );	
				elemFlag.appendChild( dv );
					
				var div = document.createElement("div");
				div.setAttribute("style", "display: none; z-index: 30; position:relative;");
				div.setAttribute("id", "download_container");
				dv.appendChild( div );	
			}
		}
	
	}
	// ======================  VK Audio ==============================================================
	function iconVKontakte( media, port ) {
		
		console.log("iconVKontakte", media);
		
		if (media == null) return;
		
		var elem = document.getElementById('download_' + media.videoId);	
		
		if (elem) return;

		var block = document.getElementById('audio_' + media.videoId);
		add_icon(block)

		// ------------------------------
		function add_icon(block) {
			
			if (!block) return;

			var div = document.createElement("div");
			div.setAttribute("class", "play_btn fl_l");
			div.setAttribute("id", "download" + media.id);
			div.setAttribute("style", "width:20px");
		
			var div1 = document.createElement("div");
			div1.setAttribute("class", "play_btn_wrap");
			div1.setAttribute("style", "padding-left:0px");
			div.appendChild( div1 );	
		
			var div2 = document.createElement("div");
			div2.setAttribute("style", "width:16px; height:16px; float:left; margin-top: 5px;");
			div2.setAttribute("title", "Download");
			div1.appendChild( div2 );	

			var img = document.createElement("img");
			img.setAttribute("src",  EXT_IMAGES["fvd"]);					
			div2.appendChild( img );
			
			block.insertBefore( div, block.querySelector('div') );
			
		}
	
		
	}	
	
	// ======================  FaceBook Video ==============================================================
	function iconFaceBook( media, port ) {

		console.log("iconFaceBook", media);
		
		if (media == null) return;

		if (media && media.length > 0) {
			for (var i=0; i<media.length; i++)		{
				var cont_id = "download_" + media[i].videoId;
				if ( media[i].videoId && !document.getElementById( cont_id ) ) {
					findBlock( media[i], cont_id );
					
				}
			}	
		}	
		
		// ------------------------------
		function findBlock( media, cont_id ) {
			var elems = document.querySelectorAll('div[data-fte]');
			for (var i=0; i<elems.length; i++) {
				var ee = elems[i].querySelector('[data-video-id="'+media.videoId+'"]');
				if (!ee)  ee = elems[i].querySelector('input[value="'+media.videoId+'"]');	
				if (ee) {
					get_title(elems[i], media.tabId, media.videoId);	
					add_icon(find_action(elems[i]), media);
				}
			}	
		}	
		
		function get_title(eee, tabId, videoId) {
			var e = eee.querySelector('h5') || eee.querySelector('h6');
			var title = e.innerHTML;
			title = title.replace(/<span aria-hidden="true">(.?)<\/span>/gm,'' )
						 .replace(/<[^>]*>/gm,'')
						 .replace(/&nbsp;/gm,' ')
						 .replace(/&(.+?);/gm,'');
				
			if (title) {  
				chrome.extension.sendRequest({	akce:"set_FaceBook_Media_title",  
												tabId: tabId,	
												videoId: videoId,	
												title: title  },	
										function( response ){  });
			}

		}
		
		// ------------------------------
 		function find_action( block ) {
			
			var ff = block.querySelector('form.commentable_item');
			if ( !ff ) return null;
			
			var fff = ff.querySelector('div');
			if ( !fff ) return null;
			var fff = fff.querySelector('div._37uu');
			if ( !fff ) return null;
			
			var ee = fff.querySelector('div._42nr');
			if (ee) var sp = ee.querySelector('span');
			if (sp) {
				return sp;
			}	 

			return null;	
		}	 

		// ------------------------------
		function add_icon( elem, m ) {
			
			if (!elem) return;
			
			var id = "download_" + m.videoId;
			
			if ( document.getElementById( id ) ) return;
			
			var span = document.createElement("span");
			span.setAttribute("id", id);
			span.setAttribute("style", "float: left; margin-top: 3px; cursor: pointer;");
			elem.parentNode.insertBefore( span, elem );
			
			var div = document.createElement("div");
			div.setAttribute("title", "Download");
			span.appendChild( div );	

			(function( medToDownload, div ){
							div.addEventListener("click", function(e){
											startDownload( medToDownload );
											e.stopPropagation();
										}, true);
						})( m, div );
			
			var img = document.createElement("img");
			img.setAttribute("src",  EXT_IMAGES["fvd"]);					
			div.appendChild( img );
			
		}
	
	}
	
	// ====================================================================================
	
	chrome.extension.onConnect.addListener(function( port ){				
		
		var pendingRequestLastId = 0;
		var pendingRequests = {};
		
		// --------------------
		function addRequest( message, callback ){
			var requestId = pendingRequestLastId;
			pendingRequestLastId++;
			
			message.requestId = requestId;
			
			pendingRequests[ requestId ] = callback;
						
			port.postMessage( message );
		}
		
		// --------------------
		function downloadMediaItemRequest( media ){
			
			port.postMessage( {
						action: "download",
						media: media
					} );
			
		}
		
		// --------------------
		function getOffset( obj ) {
			var curleft = curtop = 0;
			if (obj.offsetParent) 
			{
				do 
				{
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				}
				while(obj = obj.offsetParent);
			}
			return {	"left": curleft,	"top": curtop	};
		}
		// --------------------
	
	
		port.onMessage.addListener( function( message ){
	
			switch( message.action ){
								
				// ====================================================================================
				case "answer":
				
					var requestId = message.requestId;
					if( pendingRequests[ requestId ] )
					{
						pendingRequests[ requestId ]( message );
						delete pendingRequests[ requestId ];
					}
					else
					{
						console.log( "Undefined answer", message );
					}					
				
				break;
				
				// ====================================================================================
				case "startDownload":
					
					var media = message.media;
					
					console.log( 'startDownload', media.url );
					
					downloadMediaItem( media );

				break;
				
				// ====================================================================================
				case "insertDMButton":
				
					var media = message.media;
					
					buttonDailyMotion( media, port );
				
				break;

				// ====================================================================================
				case "insertVKButton":
				
					var media = message.media;
					
					buttonVKontakte( media );
				
				break;

				// ====================================================================================
				case "insertVK_AudioButton":
				
					var media = message.media;
					
					for (var i=0; i<media.length; i++) {
						iconVKontakte( media[i], port );
					}	
				
				break;

				// ====================================================================================
				case "query_content":
				
					curHref = null;
					getPage_url();
				
				break;
				
				// ====================================================================================
				case "canShowRateDialog":
				
					setTimeout( function() {
					
									displayRateMessage(message.type);			
									
								}, 200 );
				
				break;
				
				// ====================================================================================
				case "insertFaceBook_VideoButton":
				
					var media = message.media;
					
					iconFaceBook( media, port );
				
				break;

				// ====================================================================================

			}
			
		} );

		
	});
	
})();

