// The main function, that fleexes the page
function fleexTab (tab) {
	// Get server base url from settings
	$.getJSON(chrome.extension.getURL('config.json'), function(settings) {
		var serverBaseUrl = settings.serverBaseUrl;

		// Inject local js dependencies
		chrome.tabs.executeScript(tab.id, { file: 'scripts/jquery-1.8.3.js' });

		// Fetch (remote) or (static + dynamic) js dependencies
		$.when.apply($, [
			$.ajax(chrome.extension.getURL('scripts/google-analytics.js')),
			$.ajax(serverBaseUrl+'/Scripts/libs/underscore-1.5.1.js'), 
			$.ajax(serverBaseUrl+'/Scripts/libs/jquery/jquery.tokenize.js'), 
			$.ajax(serverBaseUrl+'/Scripts/libs/jquery/jquery.highlight.js'), 
			$.ajax(serverBaseUrl+'/Scripts/libs/twitter-bootstrap/bootstrap-tooltip.js'), 
			$.ajax(serverBaseUrl+'/Scripts/libs/twitter-bootstrap/bootstrap-popover.js'), 
			$.ajax(serverBaseUrl+'/Scripts/libs/twitter-bootstrap/plugins/bootstrap-classyTooltip.js'), 
			$.ajax(serverBaseUrl+'/Scripts/libs/twitter-bootstrap/plugins/bootstrap-classyPopover.js'), 
			$.ajax(serverBaseUrl+'/Scripts/shared/Tracker.js'),
			$.ajax(serverBaseUrl+'/Scripts/app/shared/BrowserDetect.js'),
			$.ajax(serverBaseUrl+'/Scripts/app/shared/LanguageCodes.js'),
			$.ajax(serverBaseUrl+'/Scripts/app/shared/MicrosoftTranslator.js'),
			$.ajax(serverBaseUrl+'/Scripts/app/shared/WordAnalyzer.js'),
			$.ajax(serverBaseUrl+'/Scripts/app/shared/VocabularyManager.js')
		]).done(function() {
			// Inject remote js dependencies
			for (var i = 0; i < arguments.length; i++) {
				// Replace relative urls to absolute urls
				var code = arguments[i][0].replace(/url(( )*)?:(( )*)?'\//g,"url: '"+serverBaseUrl+"/");
				// Jsonp calls are not supported in chrome, and we don't need them
				code = code.replace(/(')?dataType(')?(( )*)?:(( )*)?'jsonp'(( )*)?,/, '')
				chrome.tabs.executeScript(tab.id, { 'code': code });
			};

			// Inject css styles into page
			$.ajax(serverBaseUrl+'/Content/less/extension/styles.less').done(function(res){
	            chrome.tabs.insertCSS(tab.id, { code: res[0] })
			})
			
			// Execute content script to actually fleex the page
			chrome.tabs.executeScript(tab.id, { file: 'scripts/fleex-page.js' });

			// Close popup (if needed)
			// window.close();
		});
	})
}
@@ -1066,16 +1066,20 @@
 Scripts/
+app/
 shared/T
@@ -1464,18 +1464,8 @@
 ect 
-remote js 
 depe
@@ -1808,16 +1808,48 @@
 ?,/, '')
+;%0A%09%09%09%09// Inject script into page
 %0A%09%09%09%09chr
@@ -1918,16 +1918,23 @@
  Inject 
+remote 
 css styl
@@ -1935,26 +1935,16 @@
 s styles
- into page
 %0A%09%09%09$.aj
@@ -2017,13 +2017,181 @@
 ion(
-res)%7B
+code)%7B%0A%09%09%09%09// Replace relative urls to absolute urls%0A%09%09%09%09var code = code.replace(/url%5C((.*)%5C)/g,%22url(%22+serverBaseUrl+%22$1)%22).replace(/'/g, '');%0A%09%09%09%09// Inject styles into page
 %0A%09  
@@ -2236,20 +2236,20 @@
 , %7B 
+'
 code
+'
 : 
-res%5B0%5D
+code
  %7D)%0A

Replace relative url to abs urls in img declarations (css)