<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Discussion on Auto-Colorizer: Colors Facebook | Userscripts.org</title>
    <link>http://userscripts.org/scripts/show/3626</link>
    <description>Recent comments on userscript: Auto-Colorizer: Colors Facebook</description>
    <language>en-us</language>
    <ttl>60</ttl>
    <item>
      <title>Download redirect to 2.7.0 instead of 2.9.3 !?, replied by NeilG</title>
      <description>&lt;p&gt;I'm having the same problem.
&lt;br /&gt;Clicking on &quot;Remotely hosted version&quot; does not update the script.
&lt;br /&gt;I am using Firefox and don't want to switch to Chrome.&lt;/p&gt;

&lt;p&gt;Any suggestions?&lt;/p&gt;</description>
      <pubDate>Tue, 18 Sep 2012 17:32:06 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:113415:461568</guid>
      <author>NeilG</author>
      <link>http://userscripts.org/posts/461568</link>
    </item>
    <item>
      <title>Download redirect to 2.7.0 instead of 2.9.3 !?, replied by PanzerIV</title>
      <description>&lt;p&gt;When I click install it gives me the old 2.70 version instead of 2.93.. wtf?! Also if I click on the remotely hosted version it shows a blank page. If someone get to make it works please tell me... &lt;a href=&quot;mailto:KriegerDerHolle@Gmail.com&quot;&gt;KriegerDerHolle@Gmail.com&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 20 Jun 2012 09:18:12 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:113415:448612</guid>
      <author>PanzerIV</author>
      <link>http://userscripts.org/posts/448612</link>
    </item>
    <item>
      <title>trying to install script, replied by shiriasyyobirin</title>
      <description>&lt;p&gt;i don't get how to change the facebook profile thing.&lt;/p&gt;</description>
      <pubDate>Mon, 11 Jun 2012 19:05:54 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:80422:446683</guid>
      <author>shiriasyyobirin</author>
      <link>http://userscripts.org/posts/446683</link>
    </item>
    <item>
      <title>trying to install script, replied by Justin Ormont</title>
      <description>&lt;p&gt;It seems to be a bug in Greasemonkey under Firefox.  Try using Google Chome.&lt;/p&gt;</description>
      <pubDate>Thu, 28 Jul 2011 23:14:43 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:80422:369735</guid>
      <author>Justin Ormont</author>
      <link>http://userscripts.org/posts/369735</link>
    </item>
    <item>
      <title>trying to install script, replied by Big Timer</title>
      <description>&lt;p&gt;when I try to install the script it just goes to a page with the info of the script I think nothing has been installed&lt;/p&gt;</description>
      <pubDate>Sun, 17 Jul 2011 20:02:38 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:80422:363493</guid>
      <author>Big Timer</author>
      <link>http://userscripts.org/posts/363493</link>
    </item>
    <item>
      <title>Would like to install the latest update..., replied by jessica y</title>
      <description>&lt;p&gt;thanks!&lt;/p&gt;</description>
      <pubDate>Sat, 11 Dec 2010 07:17:05 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:64617:304962</guid>
      <author>jessica y</author>
      <link>http://userscripts.org/posts/304962</link>
    </item>
    <item>
      <title>Would like to install the latest update..., replied by Justin Ormont</title>
      <description>&lt;p&gt;Very sorry.  I fixed the permissions on the file.  You can go back to the &lt;a href=&quot;http://userscripts.org/scripts/show/3626&quot;&gt;main page&lt;/a&gt; and click on the &quot;Remotely hosted version&quot; link.&lt;/p&gt;

&lt;p&gt;When I uploaded the changes I failed to mark it as readable by non-logged in people.&lt;/p&gt;

&lt;p&gt;Thanks so much for noticing for me.&lt;/p&gt;

&lt;p&gt;-Justin&lt;/p&gt;</description>
      <pubDate>Fri, 10 Dec 2010 22:01:33 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:64617:304859</guid>
      <author>Justin Ormont</author>
      <link>http://userscripts.org/posts/304859</link>
    </item>
    <item>
      <title>Would like to install the latest update..., replied by jessica y</title>
      <description>&lt;p&gt;But I keep getting asked to enter a username/password. Is there somewhere public I can download the latest version of the script? 2.9 something...&lt;/p&gt;</description>
      <pubDate>Sun, 05 Dec 2010 08:21:32 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:64617:303310</guid>
      <author>jessica y</author>
      <link>http://userscripts.org/posts/303310</link>
    </item>
    <item>
      <title>Set Colours, replied by Justin Ormont</title>
      <description>&lt;p&gt;I am following the philosophy of simplicity of feature sets.  &lt;/p&gt;

&lt;p&gt;If you would like your page to be certain colors and ambiance, simply choose a photo with those qualities.  The colors and mood of your page will change to match the photo.  If you would like a musty dark brown page, use a night time fall picture.  If you would like a bright cheery red page, use a brightly lit photo of you wearing red.&lt;/p&gt;</description>
      <pubDate>Sat, 06 Nov 2010 09:45:06 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:54004:295881</guid>
      <author>Justin Ormont</author>
      <link>http://userscripts.org/posts/295881</link>
    </item>
    <item>
      <title>more subtle color changer, replied by Justin Ormont</title>
      <description>&lt;p&gt;Yep, I have all the code in place to do that, but really, I'm just trying to do a singular thing and do it extremely well.  &lt;/p&gt;

&lt;p&gt;Keeping it simple and beautiful are not always congruent paths but that is what I'm aiming for.&lt;/p&gt;</description>
      <pubDate>Sat, 06 Nov 2010 09:36:26 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31197:295880</guid>
      <author>Justin Ormont</author>
      <link>http://userscripts.org/posts/295880</link>
    </item>
    <item>
      <title>Set Colours, replied by hi-pr0</title>
      <description>&lt;p&gt;Awesome script, is it possible to set specific colours instead them changing?&lt;/p&gt;</description>
      <pubDate>Sat, 29 May 2010 04:24:44 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:54004:257498</guid>
      <author>hi-pr0</author>
      <link>http://userscripts.org/posts/257498</link>
    </item>
    <item>
      <title>more subtle color changer, replied by linuxsapien</title>
      <description>&lt;p&gt;Im saddened that this has not been answered as it is a very viable idea!&lt;/p&gt;</description>
      <pubDate>Sun, 09 May 2010 17:40:58 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31197:252087</guid>
      <author>linuxsapien</author>
      <link>http://userscripts.org/posts/252087</link>
    </item>
    <item>
      <title>Facebook Icons, replied by Aara Golpad</title>
      <description>&lt;p&gt;I'm having this same problem, it's pretty annoying. I love everything about this script except how it messes with icons.&lt;/p&gt;</description>
      <pubDate>Fri, 23 Apr 2010 05:33:08 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:46680:247050</guid>
      <author>Aara Golpad</author>
      <link>http://userscripts.org/posts/247050</link>
    </item>
    <item>
      <title>Facebook Icons, replied by iq911506</title>
      <description>&lt;p&gt;All my face book icons are messed up when i run this script, ie: newsfeed is a heart, groups have the photos icon...Is there anything that can be done to fix this???&lt;/p&gt;</description>
      <pubDate>Sun, 21 Feb 2010 20:54:44 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:46680:222723</guid>
      <author>iq911506</author>
      <link>http://userscripts.org/posts/222723</link>
    </item>
    <item>
      <title>Problem, replied by Justin Ormont</title>
      <description>&lt;p&gt;Ahh...That's rather more simple than you expect.  The colors of your profile are based on your photo.  If you want your profile with more red, use of picture of you wearing a red shirt.  If you want your profile to be darker, use a darker photo.  Browse around facebook and look at profile colors and compare them to the photos.&lt;/p&gt;</description>
      <pubDate>Mon, 08 Feb 2010 23:20:24 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:45322:217907</guid>
      <author>Justin Ormont</author>
      <link>http://userscripts.org/posts/217907</link>
    </item>
    <item>
      <title>Problem, replied by ROman </title>
      <description>&lt;p&gt;My User Script Commands Menu is grayed out. Tell me how to use this. Please&lt;/p&gt;</description>
      <pubDate>Fri, 05 Feb 2010 00:34:13 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:45322:216194</guid>
      <author>ROman </author>
      <link>http://userscripts.org/posts/216194</link>
    </item>
    <item>
      <title>Top bar, replied by Jamie.ds</title>
      <description>The Facebook menu bar stretches across the screen but has the default facebook colour. Add this to the code; &gt;&gt;&gt;, #menubar_container&amp;lt;&amp;lt;&amp;lt; To make the code like this;

// ==UserScript==
// @name          Facebook Auto-Colorizer
// @version       v2.6.2
// @author	  Justin Ormont
// @namespace     http://wisc.facebook.com/message.php?id=8638838
// @description	  Colorizes facebook based on the user's photo.
// @include       http://*.facebook.com/*
// ==/UserScript==

//
// (c) 2009 Justin Ormont.  All rights reserved.
// Please don't steal my code. But if you do anyway, please credit me.
// Btw, stealing code includes reuse/adaption for another plug-in/script.
//
// Have ideas for new features?  Or want to create a script/plugin based
// on Facebook Auto-Colorizer?  Send me a message with your ideas. 
//
//
// About me: I'm a PhD candidate at the University of Wisconsin - Madison.
//
//
// To Do: 
//
//  On the help page, application icons are being chosen when they should not.
//  Colors will sometimes be cached with the wrong image when loading many color schemes at a time. May be server side issue.  May be a caching issue.
//  Make sure in profile, the profile pic is picked when an event image is also displayed. (done)
//  Check that the image is not already precached in function PreCacheChangedProfilePics. (done)
//  Precache all newly changed friends pictures. (done)
//  Add a separate cache for different types of pictures (profile pics, group picts, etc) to make searching cache faster. (done) 
//	Add a function to check contrast.  If too low, use standard or artificially increasing the contrast.
//	Color the category bars in groups. (done)
//	Make sure on the 'home' and groups pages that the correct image is analyzed. (done) 
//      Quantify 'bad' color schemes.  Likely a voting system fed into a bayesian probability graph.
//      Allow user to choose between the standard color picker and choices of bold, natural, etc.  Store choice on profile or server side.
//	Precache the next photo. (done)
//	Automatically set current page colors to the last viewed page's colors when there is no picture on the page.  (done)
//
//  Write code to ignore current user's image when not on user's profile. 

thisScriptVersion = new Array(2,6,2);
//startingColorArray = new Array(10);
//finalColorArray = new Array(10);
//fadedColorArray = new Array(10);

var timers = new Array();
var timerRecord = &quot;&quot;;
var timersOff = true;
var AjaxInserters = new Array(4);
var lastDocUrl = &quot;&quot;;
var currentImgDom = &quot;&quot;;

//ClearCache();

(function()
{
 	if (CheckForFrames()) return;
 
	var now = new Date();
	try { 
	 if (typeof GM_getValue('lastCheckedForVersion','') != 'undefined') var lastCheckedForVersion = GM_getValue('lastCheckedForVersion','');
	 else lastCheckedForVersion = 0;   
	}
	catch(err) { lastCheckedForVersion = 0; }
	//alert(&quot;Time diff: &quot; + now.getTime() + &quot; &quot; + lastCheckedForVersion + &quot; &quot; + (now.getTime() - lastCheckedForVersion))
	if ((now.getTime() - lastCheckedForVersion) &gt; 86400000) CheckForUpdate(); //check once per day

 
	InitialPageSetup();

	var photoUrl = lookForPhotoUrl();
	
	lookInCacheThenGetColors(photoUrl, true, true);


	//PreCacheAllImagesOnPage();
	
 //alert(&quot;Time spent in InsertCSS = &quot; + typeof(oldTime) + typeof(currentDate.getTime())));  

	
})();

function CheckForFrames() {
	// Check if we are in a frame, and exit if so.
	if (top.location != location) { 
		GM_log(&quot;Executing in a frame: &quot; + location);
		return true; 
	}
	return false
}

function OnPageChange() {
	lastDocUrl = getApparentUrl();	// This is a global variable.
	
	ReplaceUIRoundedImage(true);
	
	lookForPhotoUrl();
	AjaxUpdaterFunction();
	
	if (getApparentUrl().indexOf('/home.php')&gt;-1) PreCacheChangedProfilePics();
	if ((getApparentUrl().indexOf('/album.php?')&gt;-1) || (getApparentUrl().indexOf('/photo_search.php?')&gt;-1)) PreCacheAlbumPics();
	
}

function getApparentUrl() {
	if (window.location.hash.length &gt; 0) return window.location.protocol + '//' + location.host + window.location.hash.substring(1) + window.location.search;
	else return window.location.href;
}

function lookInCacheThenGetColors(photoUrl, applyColors, doFade) {
	
	if (typeof photoUrl == 'undefined') return;  // bail-out
	
	if (typeof photoUrl != 'undefined') cacheType = UrlToCacheType(photoUrl);
	else cacheType = &quot;&quot;;
	
	
	/*
	 if (typeof photoUrl == 'undefined') {  //no images found on page 
	 try{ApplyColorSchemeFromLastPage()}
	 catch(err){}
	 return; 
	 }
	 */
	
	var splitUrl = photoUrl.split(&quot;/&quot;);
	var fileName = splitUrl[splitUrl.length - 1];
	
	
	StartTimer(&quot;Retrieve From Cache&quot;);
	colorArray = RetrieveFromCache(fileName, cacheType);
	RecordTimer(&quot;Retrieve From Cache&quot;);
	
	//alert(&quot;colorArray = &quot; + colorArray);
	
	if (colorArray != null) {
		//alert(&quot;Cache Hit: photoUrl=&quot; + photoUrl + &quot;.&quot;);
		
		StartTimer(&quot;InsertCSS&quot;);
		if (window.document.body.getAttribute('startingColorArray') == null) window.document.body.setAttribute('startingColorArray', colorArray.join('*'));
		window.document.body.setAttribute('finalColorArray', colorArray.join('*'));
		
		try {
			//if (doFade == true)	fadeBetweenTwoColorSchemes(/*currentFadePercent*/ 0,/*fadeStep*/ 0.01,/*endingFadePercent*/ 1.0,/*delay*/ 5);  
			if (doFade == true)	fadeBetweenTwoColorSchemes(/*fadeStartTime*/ null,/*fadeDuration*/ 250);  
			else InsertCSS(colorArray);
		}
		catch(err) {
			InsertCSS(colorArray);
		}
		RecordTimer(&quot;InsertCSS&quot;);
		
	
		
		StartTimer(&quot;preCache&quot;);
		var preCached = AttemptToPreCacheForNextPage();  // note the return that's a few lines below
		RecordTimer(&quot;preCache&quot;);
		
		GetColors(&quot;http://facebook.com&quot;, true, doFade);
		
		return;  //    &amp;lt;---&gt;-1) PreCacheChangedProfilePics();
	if ((getApparentUrl().indexOf('/album.php?')&gt;-1) || (getApparentUrl().indexOf('/photo_search.php?')&gt;-1)) PreCacheAlbumPics();
	
}

function CacheTypeToCacheName(cacheType) {
	if (cacheType == &quot;photoStream&quot;) return &quot;cachedPhotoStreamColors&quot;;
	if (cacheType == &quot;profilePic&quot;)  return &quot;cachedPageColors&quot;;
	if (cacheType == &quot;photoGroupEvent&quot;)  return &quot;cachedGroupColors&quot;;
	if (cacheType == &quot;photoVideoThumb&quot;)  return &quot;cachedVideoColors&quot;;
	return &quot;cachedOtherColors&quot;;	
}

function UrlToCacheType(url) {
	if (url.indexOf('/object')&gt;-1) return &quot;photoGroupEvent&quot;;		// Image from group or event.
	if (url.indexOf('http://photos-')&gt;-1) return &quot;photoStream&quot;;		// Image from photo set.
	if (url.indexOf('http://profile.')&gt;-1) return &quot;profilePic&quot;;		// Image from profile picture.
	if (url.indexOf('http://vthumb.')&gt;-1) return &quot;photoVideoThumb&quot;;	// Image from thumbnail of  videos.
	return &quot;unknown&quot;;
}

function RetrieveFromCache(fileName, cacheType) {
	
	cacheName = CacheTypeToCacheName(cacheType);
	
	var splitFileName = fileName.split(&quot;/&quot;);
	var fileName = splitFileName[splitFileName.length - 1];
	
	//alert(&quot;Attempting to retreive from cacheName: &quot; + cacheName);

	try { var cachedPageColors = GM_getValue(cacheName,''); }
	catch(err) { alert(&quot;Error: Can not read from cache.\n\nabout:config key was reset; Restart firefox.&quot;); }
	//var cachedPageColors = GM_getValue(cacheName,'');
	
	
	if (typeof cachedPageColors != 'undefined') {
		var cachedPageColorsSplit = cachedPageColors.split(',');
		
		//alert(&quot;Num of Cached: &quot; + cachedPageColorsSplit.length);
		
		var foundInCached = false;
		for (var i=0; i&amp;lt;cachedpagecolorssplit&gt;&amp;lt;cachedpagecolorssplit&gt; 1000) { alert('Auto-Colorizer Error: Endless Loop'); return null; }
				}
				GM_setValue(cacheName,cachedPageColorsSplit.join(','));
				
				return colorArray;
			}
		}
	}
	return null;
}


function ClearCache() {
	GM_setValue(&quot;cachedPhotoStreamColors&quot;,&quot;&quot;);
	GM_setValue(&quot;cachedPageColors&quot;,&quot;&quot;);
	GM_setValue(&quot;cachedGroupColors&quot;,&quot;&quot;);
	GM_setValue(&quot;cachedVideoColors&quot;,&quot;&quot;);
}

function ApplyColorSchemeFromLastPage() {
	var cachedPageColors = GM_getValue('cachedPageColors','');
	if (typeof cachedPageColors != 'undefined') {
		var cachedPageColorsSplit = cachedPageColors.split(',');
		var temp = cachedPageColorsSplit[cachedPageColorsSplit.length-1].split('-');
		try{
			var colorArray = temp[1].split('*');
			startingColorArray = colorArray;      
			InsertCSS(colorArray);
		}
		catch(err) {}
	}
}


function InsertCSSOld(colorArray) {
	//ViewPallet(colorArray);

	StartTimer(&quot;Set Style Old&quot;); 
	
	//alert(&quot;typeof &quot; + typeof(colorarray));
	
	GM_addStyle(&quot;div.profilebox { background:&quot; + colorArray[9] + &quot;; }&quot;);
	GM_addStyle(&quot;.profileheader h2 {color:&quot; + colorArray[0] + &quot;;}&quot;);
	GM_addStyle(&quot;#header { background:&quot; + colorArray[5] + &quot;; }&quot;); 
	GM_addStyle(&quot;div.profileheader { background:&quot; + colorArray[6] + &quot;; border-top: solid 1px &quot; + colorArray[4] + &quot;; }&quot;);
	GM_addStyle(&quot;#content { background:&quot; + colorArray[8] + &quot;; }&quot;);
	//GM_addStyle(&quot;body.profile { background:&quot; + colorArray[8] + &quot;; }&quot;);  // enable to reduce some background color
	GM_addStyle(&quot;body { background:&quot; + colorArray[7] + &quot;; }&quot;);
	GM_addStyle(&quot;.info { color: &quot; + colorArray[1] + &quot;; background: &quot; + colorArray[10] + &quot;; }&quot;);
	GM_addStyle(&quot;h4 { color:&quot; + colorArray[0] + &quot;; }&quot;);
	GM_addStyle(&quot;A:link { color:&quot; + colorArray[1] + &quot;; }&quot;);
	GM_addStyle(&quot;A:hover { color:&quot; + colorArray[3] + &quot;; }&quot;);
	GM_addStyle(&quot;A:visited { color:&quot; + colorArray[2] + &quot;; }&quot;);
	GM_addStyle(&quot;input.inputtext { border:1px solid &quot; + colorArray[6] + &quot;; background:&quot; + colorArray[10] + &quot;; color:&quot; + colorArray[5] + &quot;; }&quot;);
	GM_addStyle(&quot;.wallpost .info .header { color: &quot; + colorArray[1] + &quot;; background: &quot; + colorArray[7] + &quot;; border-top: solid 1px &quot; + colorArray[3] + &quot;; border-bottom: dashed 1px &quot; + colorArray[7] + &quot;; }&quot;);
	
	//search specific: also wall post textarea, but the text color doesn't work.
	GM_addStyle(&quot;textarea { border:1px solid &quot; + colorArray[6] + &quot;; color: &quot; + colorArray[1] + &quot;; background:&quot; + colorArray[9] + &quot;; }&quot;); 
	
	//photo specific
	GM_addStyle(&quot;div.photonav { background:&quot; + colorArray[8] + &quot;; }&quot;);
	GM_addStyle(&quot;#comment { background:&quot; + colorArray[4] + &quot;; }&quot;);

    /* START changes due to the addition of &quot;Mini-Feed&quot; */
	// The text color of dates in the mini-feed.
	GM_addStyle(&quot;.minifeed .date_divider  { color:&quot; + colorArray[6] + &quot;; border-bottom: solid 1px &quot; + MixTwoHexColors(colorArray[6],colorArray[4],.5) + &quot;;}&quot;);
	
	GM_addStyle(&quot;.inside_the_box { background:&quot; + colorArray[9] + &quot;; }&quot;);
	GM_addStyle(&quot;.box_head { background:&quot; + colorArray[6] + &quot;; }&quot;);
	GM_addStyle(&quot;.when_open .flex_header, .flex_open .box_head { border-top: solid 1px &quot; + colorArray[3] + &quot;; &quot; + &quot;background-image: url('https://mywebspace.wisc.edu/ormont/web/facebook/flex_arrow_open.png')&quot; + &quot;; }&quot;);
	
	GM_addStyle(&quot;.flex_shut .box_head { background-image: url('https://mywebspace.wisc.edu/ormont/web/facebook/flex_arrow_close.png'); }&quot;);
	
	GM_addStyle(&quot;.box_subhead { background:&quot; + MixTwoHexColors(colorArray[6],colorArray[9],.5) + &quot;; border-top: solid 1px &quot; + MixTwoHexColors(colorArray[6],colorArray[9],.25) + &quot;;&quot; + &quot;}&quot;);
	GM_addStyle(&quot;.box_head h2  { color:&quot; + colorArray[3] + &quot;; }&quot;);
    /* END changes due to the addition of &quot;Mini-Feed&quot; */
	
			
	//global group specific
	GM_addStyle(&quot;.profile .withedit { background: &quot; + colorArray[7] + &quot;; color: &quot; + colorArray[3] + &quot;; border-top: solid 1px &quot; + colorArray[4] + &quot;; }&quot;);
	
	 
	//The top facebook bar
	//GM_addStyle(&quot;#navigator { background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot;; background-image: url(https://mywebspace.wisc.edu/ormont/web/facebook/pageheaderbg-lighten.png); }&quot;);
	GM_addStyle(&quot;#navigator { background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot;; background-image: ; }&quot;);

	GM_addStyle(&quot;#sidebar a.go_home { background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/facebook_logo_trans.png) no-repeat top left; }&quot;);

	GM_addStyle(&quot;#sidebar a.go_home:hover {background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/facebook_logo_trans.png) no-repeat bottom left; }&quot;);
	
	//alert(colorArray[0] + &quot;, &quot; + colorArray[9]);

	RecordTimer(&quot;Set Style Old&quot;);	
}

function InsertCSS(colorArray) {
	//ViewPallet(colorArray);
	
	//InsertCSSOld(colorArray);
	
	var head = document.getElementsByTagName(&quot;head&quot;)[0];
	var styleNode = document.createElement(&quot;style&quot;);
	

	//var styleText = &quot;body{background-color:blue;}&quot;;
	
	var styleText =	&quot; \
		a{cursor:pointer;color:&quot; + ForceContrast(colorArray[6],MixTwoHexColors(colorArray[8], colorArray[9], 0.5) ,.15) + &quot;;} \
		div.profilebox { background:&quot; + colorArray[9] + &quot;; }; \
		.profileheader h2 {color:&quot; + colorArray[0] + &quot;;}; \
		#header { background:&quot; + colorArray[5] + &quot;; }\n \
		div.profileheader { background:&quot; + colorArray[6] + &quot;; border-top: solid 1px &quot; + colorArray[4] + &quot;; }\n \
		#XXXcontent { background:&quot; + colorArray[8] + &quot;; } \
	/* body.profile { background:&quot; + colorArray[8] + &quot;; }  enable to reduce some background color */ \n \
		body { background:&quot; + colorArray[7] + &quot;; }\
		.info { color: &quot; + colorArray[1] + &quot;; background: &quot; + colorArray[10] + &quot;; }\
		h4 { color:&quot; + colorArray[0] + &quot;; }\
		A:link { color:&quot; + colorArray[1] + &quot;; }\
		A:hover { color:&quot; + colorArray[3] + &quot;; }\
		A:visited { color:&quot; + colorArray[2] + &quot;; }  \
		input.inputtext { border:1px solid &quot; + colorArray[6] + &quot;; background:&quot; + colorArray[10] + &quot;; color:&quot; + colorArray[5] + &quot;; } \
		.wallpost .info .header { color: &quot; + colorArray[1] + &quot;; background: &quot; + colorArray[7] + &quot;; border-top: solid 1px &quot; + colorArray[3] + &quot;; border-bottom: dashed 1px &quot; + colorArray[7] + &quot;; } \
		.profileTable .label { color: &quot; + colorArray[3] + &quot;; } \
		\
	/* search specific: also wall post textarea, but the text color doesn't work. */ \
		textarea { border:1px solid &quot; + colorArray[6] + &quot;; color: &quot; + colorArray[1] + &quot;; background:&quot; + colorArray[8] + &quot;; }  \
		.DOMControl_placeholder{color:&quot; + ForceContrast(colorArray[6], colorArray[8], 0.15) + &quot;} \
		\
	/* photo specific */ \
		div.photonav { background:&quot; + colorArray[8] + &quot;; }\
		#comment { background:&quot; + colorArray[9] + &quot;; }\
		\
	/* START changes due to the addition of Mini-Feed */ \
		/* The text color of dates in the mini-feed. */ \
		.minifeed .date_divider  { color:&quot; +  ForceContrast(colorArray[6], colorArray[9], 0.15) + &quot;; border-bottom: solid 1px &quot; + MixTwoHexColors(colorArray[6],colorArray[4],.5) + &quot;;} \
		\
		.inside_the_box { background:&quot; + colorArray[9] + &quot;; } \
		.box_head { background:&quot; + colorArray[6] + &quot;; } \
		.when_open .flex_header, .flex_open .box_head { border-top: solid 1px &quot; + colorArray[3] + &quot;; &quot; + &quot;background-image: url('https://mywebspace.wisc.edu/ormont/web/facebook/flex_arrow_open.png')&quot; + &quot;; } \
		\
		.flex_shut .box_head { background-image: url('https://mywebspace.wisc.edu/ormont/web/facebook/flex_arrow_close.png'); } \
		\
		.box_subhead { background:&quot; + MixTwoHexColors(colorArray[6],colorArray[9],.5) + &quot;; border-top: solid 1px &quot; + MixTwoHexColors(colorArray[6],colorArray[9],.25) + &quot;;&quot; + &quot;} \
		.box_head h2  { color:&quot; + ForceContrast(colorArray[3], colorArray[6], 0.15) + &quot;; } \
	/* END changes due to the addition of Mini-Feed */ \
		\
		\
	/* global group specific */  \
		.profile .header {  background: &quot; + colorArray[6] + &quot;; border-top: solid 1px &quot; + colorArray[5] + &quot;; } /* these colors may need to/should be changed */ \
		.profile .header h2 {  color: &quot; + ForceContrast(colorArray[3], colorArray[6], 0.12) + &quot;; } \
		\
		.profile .withedit { background: &quot; + colorArray[7] + &quot;; color: &quot; + colorArray[3] + &quot;; border-top: solid 1px &quot; + colorArray[4] + &quot;; } \
		\
		\
		#navigator { background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot;; background-image: ; } \
		\
		#sidebar a.go_home { background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/facebook_logo_trans.png) no-repeat top left ! important ; } \
		\
		#sidebar a.go_home:hover {background: &quot; + IncreaseSaturation(colorArray[5],100) + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/facebook_logo_trans.png) no-repeat bottom left ! important ;}\
	    &quot;; 
	
	
	if (typeof GM_getValue('clearChatBar','') != 'undefined') var clearChatBar = GM_getValue('clearChatBar','');
	else var clearChatBar = &quot;colorgel&quot;;
	
	if (clearChatBar == &quot;&quot;) clearChatBar = &quot;colorgel&quot;;
	
	/* chat bar specific */ 
	
	
	if (clearChatBar == &quot;clear&quot;) {
		styleText += &quot;#presence_bar{background: url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;} \
		#presence_popin_bar{background: url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;}  \
		#presence.full #presence_ui{border-left:1px solid &quot; + colorArray[3] + &quot;; background: url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;} \
		\
		#presence_ui{background:url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;! important;} \
		#presence .presence_bar_button{color:&quot; + ForceContrast(colorArray[2], colorArray[6], 0.12) + &quot;;border-left:1px solid &quot; + colorArray[3] + &quot;;border-right:1px solid &quot; + colorArray[6] + &quot;;} \
		\
		#presence_error_bar{border-right:1px solid &quot; + colorArray[3] + &quot;;background-image:url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png);}  \
		&quot;;
	}
	else if (clearChatBar == &quot;colorgel&quot;) {  /* HexColorToRGBA(colorArray[6],0.5) */
		styleText += &quot;#presence_bar{background: &quot; + HexColorToRGBA(colorArray[6],0.5) + &quot;  repeat-x top left;} \
		#presence_popin_bar{background: url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;}  \
		#presence.full #presence_ui{border-left:1px solid &quot; + colorArray[3] + &quot;; background: url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;} \
		\
		#presence_ui{background:url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;! important;} \
		#presence .presence_bar_button{color:&quot; + ForceContrast(colorArray[2], colorArray[6], 0.12) + &quot;;border-left:1px solid &quot; + colorArray[3] + &quot;;border-right:1px solid &quot; + colorArray[6] + &quot;;} \
		\
		#presence_error_bar{border-right:1px solid &quot; + colorArray[3] + &quot;background-image:url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png);}  \
		&quot;;
	}
	else {
		styleText += &quot;#presence_bar{background: &quot; + colorArray[6] + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;} \
		#presence #chat_status_control_tab{border-right:1px solid &quot; + colorArray[3] + &quot;;} \
		#presence_popin_bar{background: &quot; + colorArray[6] + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;}  \
		#presence.full #presence_ui{border-left:1px solid &quot; + colorArray[3] + &quot;; background: &quot; + colorArray[6] + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png) repeat-x top left;} \
		\
		#presence .presence_bar_button{color:&quot; + ForceContrast(colorArray[2], colorArray[6], 0.12) + &quot;;border-left:1px solid &quot; + colorArray[3] + &quot;;border-right:1px solid &quot; + colorArray[6] + &quot;;} \
		\
		#presence_error_bar{border-right:1px solid &quot; + colorArray[3] + &quot;;background-image:url(https://mywebspace.wisc.edu/ormont/web/facebook/chat_bar_bg.png);}  \
		\
		&quot;;
	}
	
	styleText += &quot;#presence_bar .presence_menu_opts h2{background-color:&quot; + colorArray[3] + &quot;;color:#fff;border:1px solid &quot; + ForceContrast(MixTwoHexColors(colorArray[2], colorArray[3], 0.5),colorArray[3], 0.15) + &quot;;border-bottom:1px solid &quot; + colorArray[3] + &quot;;} \
	#presence_bar .presence_menu_opts h2 .presence_minimize{background-color:&quot; + ForceContrast(MixTwoHexColors(colorArray[3], colorArray[8], 0.5), colorArray[3], 0.15) + &quot;;} \
	&quot; ; 

	
	/* New profile layout specific */  /* todo: colorArray[5] is under used. */
	styleText += &quot;#fb_menubar, #menubar_container{background: &quot; + colorArray[2] + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/fb_menubar_gray-trans2.png) } \
	#fb_menubar #fb_menubar_logo a span{background:transparent url(https://mywebspace.wisc.edu/ormont/web/facebook/fb_menubar_logo_gray-trans.png) } \
	.fb95_preview_bar{background:transparent url(https://mywebspace.wisc.edu/ormont/web/facebook/fb95_preview_bar-gray_trans.png) repeat-x 0px 0px;width:auto;margin:0px;height:24px;padding:0px 10px 0px 10px;} \
	\
	/*.minifeedwall .story_body{background:&quot; + colorArray[9] + &quot;; }*/ \
	.minifeedwall .story{background:&quot; + colorArray[9] + &quot;; } \
	.minifeedwall .border .story_body, .minifeedwall .extra_top_border{border-top:1px solid &quot; + ForceContrast(MixTwoHexColors(colorArray[4], colorArray[8], 0.5), colorArray[8], 0.20) + &quot;;} \
	.minifeedwall .border .story_body .from_friend_story_content_container{border-top:1px solid &quot; + ForceContrast(MixTwoHexColors(colorArray[4], colorArray[8], 0.5), colorArray[8], 0.20) + &quot;;padding-top:12px;} \
	.minifeedwall .date_divider_label{background:&quot; + colorArray[8] + &quot; ;display:block;float:left;margin-top:-8px;min-width:50px;padding:2px 7px 0 0;} \
	.minifeedwall .date_divider{color:&quot; +  ForceContrast(MixTwoHexColors(colorArray[4], colorArray[8], 0.5) , colorArray[8], 0.20) + &quot;;font-weight:bold;font-size:9px;border-bottom:solid 1px &quot; + ForceContrast(MixTwoHexColors(colorArray[4], colorArray[8], 0.5) , colorArray[8], 0.20) + &quot;;margin:2px 0px 10px;padding:2px 7px 0px 0px;} \
	.minifeedwall .story .story_time{color:&quot; + MixTwoHexColors(colorArray[4], colorArray[8], 0.5) + &quot;} \
	#profile_top_bar{background:&quot; + colorArray[4] + &quot;;} \
	#profile_name{color:&quot; + ForceContrast(colorArray[3], colorArray[4], 0.20) + &quot;} \
	\
	#feedwall_with_composer{background:&quot; + colorArray[8] + &quot;;} \
	#left_column {background:&quot; + colorArray[8] + &quot;;} \
	\
	.profile .profile_color_bar{background:&quot; + MixTwoHexColors(colorArray[2],colorArray[4],.5) + &quot; url(https://mywebspace.wisc.edu/ormont/web/facebook/fb95_preview_bar-gray_trans.png) repeat-x bottom left;padding-top:50px;} \
	\
	.commentable_item .wallpost{background:&quot; + MixTwoHexColors(colorArray[7], colorArray[9], 0.5) + &quot;;border-bottom:1px solid &quot; + colorArray[7] + &quot;;clear:left;float:none;overflow:hidden;margin-bottom:2px;padding:6px 4px 6px 6px;} \
	.commentable_item .comment_box{background:url(https://mywebspace.wisc.edu/ormont/web/facebook/box_bg-trans.png) no-repeat left 1px;clear:both;font-size:11px;padding:7px 0 0;overflow:hidden;} \
	\
	/* .profile .right_column_container{background:&quot; + colorArray[9] + &quot;;} */ \
	/* .profile_two_columns .right_column{background:&quot; + &quot;#FF0000&quot; + &quot;;} */ \
	.profile .right_column{background:&quot; + colorArray[8] + &quot;;} \
	\
	.profile dl.info dt{background:&quot; + MixTwoHexColors(colorArray[8],colorArray[6],0.35) + &quot;;color:&quot; + colorArray[2] + &quot;;float:left;clear:left;} \
	\
	.profile .top_bar ul.tabs li{background:&quot; + MixTwoHexColors(colorArray[8],colorArray[4],0.5) + &quot;;float:left;margin:0 2px 0 0;overflow:hidden;list-style-type:none;max-width:107px;position:relative;} \
	.profile .top_bar ul.tabs li a:hover.tab_link{background-color:&quot; + MixTwoHexColors(colorArray[8],colorArray[4],0.75) + &quot;;border-color:&quot; + MixTwoHexColors(colorArray[4],&quot;#000000&quot;,0.3) + &quot;;color:#fff;text-decoration:none;} \
	.home_main_item{background:&quot; + MixTwoHexColors(colorArray[5],&quot;#FFFFFF&quot;,0.5) + &quot;;} \
	.feed_item{background-color:&quot; + MixTwoHexColors(colorArray[5],&quot;#FFFFFF&quot;,0.75) + &quot;;} \
	\
	#feedwall_with_composer .pager_next{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[6], 0.2) + &quot;;margin-top:8px;border-top:1px solid #D8DFEA;padding:3px 7px 4px 0;} \
	\
	#pagefooter{background:&quot; + MixTwoHexColors(colorArray[7],colorArray[9],0.25) + &quot;; border-top:solid 1px &quot; + MixTwoHexColors(colorArray[3],colorArray[7],0.25) + &quot;;} \
	#pagefooter .copyright{color:&quot; + ForceContrast(colorArray[3], MixTwoHexColors(colorArray[7],colorArray[9],0.25), 0.20) + &quot;;} \
	\
	.profile .top_bar .mobile_status{color:&quot; + ForceContrast(colorArray[3], colorArray[4], 0.15) + &quot;;} \
	.profile .top_bar .mobile_status a{color:&quot; + ForceContrast(colorArray[5], colorArray[4], 0.15) + &quot;;}  \
	.profile .top_bar .status_source{color:&quot; + ForceContrast(&quot;#999999&quot;, colorArray[4], 0.15) + &quot;;} \
	.profile .top_bar .status_source a{color:&quot; + ForceContrast(colorArray[5], colorArray[4], 0.15) + &quot;} \
	.profile .top_bar .mobile_status .profile_empty_status a{color:&quot; + ForceContrast(colorArray[5], colorArray[4], 0.15) + &quot;} \
	.profile .top_bar .mobile_status small{color:&quot; + ForceContrast(colorArray[6], colorArray[4], 0.15) + &quot;;} \
	.profile .top_bar .mobile_status small a{color:&quot; + ForceContrast(colorArray[5], colorArray[4], 0.15) + &quot;}	\
	.profile .left_column .mobile_status small{color:&quot; + ForceContrast(&quot;#999999&quot;, colorArray[4], 0.15) + &quot;;} /* colorArray[4] wrong for the left column? */ \
	.profile .left_column .mobile_status #status_text{color:&quot; + ForceContrast(&quot;#000000&quot;, colorArray[4], 0.15) + &quot;} /* colorArray[4] wrong for the left column? */ \
	\
	#adcolumn_advertise{background:&quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.25) + &quot;;} \
	#adcolumn_more_ads{background:&quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.25) + &quot;;} \
	#sidebar_ads .adcolumn{border-left:solid &quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.25) + &quot;;} \
	.admarket_ad{background-color:&quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.75) + &quot;;border:1px solid #ccc;} \
	.social_ad_advert h2{color:&quot; + ForceContrast(MixTwoHexColors(colorArray[5],MixTwoHexColors(colorArray[7],colorArray[8],0.75),0.25), MixTwoHexColors(colorArray[7],colorArray[8],0.75), 0.15)  + &quot;;} \
	/*.ad_story .social_ad_advert{background-color:&quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.75) + &quot;;} */ \
	.admarket_fluff_ad{background:&quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.25) + &quot;;} \
	.admarket_fluff_ad{border-top:1px solid &quot; + MixTwoHexColors(colorArray[7],colorArray[8],0.75) + &quot;;} \
	\
	.XXXXXstory_content{background:#FF0000;} \
	.XXXXXstory_body{background:#FF0000;} \
	.XXXXXsize_2{background:#FF0000;} \
	.XXXXXfrom_friend_story{background:#FF0000;} \
	.XXXXXwall_story{background:#FF0000;} \
	.XXXXXstory_content{background:#FF0000;} \
	.XXXXXstory_media{background:#FF0000;} \
	.XXXXXtag_story_box{background:#FF0000;}  \
	\
	.minifeedwall .from_friend_story .from_friend{background:&quot; + colorArray[9] + &quot; url(/images/comments/quote_nub_blue.gif) no-repeat 52px 8px;} \
	.minifeedwall .from_friend_story .story_content{border-bottom:1px solid &quot; + MixTwoHexColors(colorArray[8],colorArray[9],0.75) + &quot;;} \
	.minifeedwall .from_friend_story .story_content{background:&quot; + MixTwoHexColors(colorArray[8],colorArray[9],0.75) + &quot;;} \
	.app_actor_image { border-left: solid 2px &quot; + colorArray[7] + &quot; ;} \
	.profile .box h3.box_header{background:&quot; + colorArray[6] + &quot;;border-top:1px solid &quot;+ colorArray[2] + &quot;;font-size:13px;margin:0px;padding:5px 8px;position:relative;} \
	.profile .box_column{border-top:1px solid &quot; + colorArray[5] + &quot;;border-right:1px solid #d8dfea;} \
	\
	#profile_composer .composer_tabs ul li.selected .composer_tab_arrow{background:transparent url('https://mywebspace.wisc.edu/ormont/web/facebook/composer_tab_selected_arrow-trans.png') no-repeat bottom center;display:block;} \
	#profile_composer .composer_tabs ul li.selected .composer_tab_rounded{background:transparent url('https://mywebspace.wisc.edu/ormont/web/facebook/composer_tab_selected-trans.png') left top no-repeat;} \
	#profile_composer .composer_tabs ul li.selected .composer_tab_rounded_tr{background-position:top right;} \
	#profile_composer .composer_tabs ul li.selected .composer_tab_rounded_bl{background-position:bottom left;} \
	#profile_composer .composer_tabs ul li.selected .composer_tab_rounded_br{background-position:bottom right;} \
	\
	td.pop_content h2.dialog_title{background:&quot; + colorArray[2] + &quot;;border:1px solid #3b5998;color:white;font-size:14px;font-weight:bold;margin:0px;} \
	\
	.HomeTabs .HomeTabs_tab a{padding:5px 9px;margin:4px 1px 0px;background-color:&quot; + colorArray[9] + &quot;;display:block;font-weight:bold;height:13px;} \
	.HomeTabs .HomeTabs_tab a:hover{background-color:&quot; + colorArray[2] + &quot;;border-bottom:1px solid #435f9c;margin-bottom:-1px;padding-bottom:4px;color:#fff;text-decoration:none;} \
	.HomeTabs .Tabset_selected a, \
	.HomeTabs .Tabset_selected a:hover{background-color:#fff;color:#000;border:1px solid #d8dfea;border-bottom:1px solid #fff;padding:4px 9px;font-size:13px;margin:2px 1px -1px 0;height:15px;position:relative;} \
	#newsfeed_tabs_wrapper{background:&quot; +  MixTwoHexColors(colorArray[7], colorArray[9], 0.5) + &quot;;} \
	.home_main_tabs #newsfeed_tabs_wrapper .newsfeed_plus a{background:&quot; + colorArray[9] + &quot; url(/images/white_dropdown_closed.gif) 8px 9px no-repeat;margin:4px 1px 0 1px;} \
	.home_main_tabs #newsfeed_tabs_wrapper .newsfeed_plus a:hover, \
	.home_main_tabs #newsfeed_tabs_wrapper .HomeFeed_selected a{background:&quot; + colorArray[2] + &quot; url(/images/white_dropdown_open.gif) 8px 9px no-repeat;}	 \
	\
	.one_liner .header_title_wrapper a{font-weight:normal;color:&quot; + colorArray[4] + &quot;;} \
	.bumper{color:&quot; + colorArray[8] + &quot;;background:&quot; + colorArray[8] + &quot;;} \
	.commentable_item .show_all_link{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[9], 0.25) + &quot;;border-bottom:1px solid &quot; + colorArray[7] + &quot;;} \
	.commentable_item .wallpost{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[9], 0.5) + &quot;;border-bottom:1px solid &quot; + colorArray[7] + &quot;;} \
	\
	\
	/* Friends Page Specific */ \
	.fp.my_friends #content{background:&quot; + colorArray[7] + &quot;;} \
	.fp.other_friends #content{background:&quot; + colorArray[7] + &quot;;} \
	#fpgc{width:100%;border:1px solid transparent;background:&quot; + colorArray[7] + &quot;;}   /* Purposefully changeing from color border to transparent */ \
	#friends_left_cell{border-right:1px solid &quot; + colorArray[7] + &quot;;} \
	.fmp{background:&quot; + colorArray[5] + &quot;;} \
	.fmp .fsummary{background:&quot; + MixTwoHexColors(colorArray[6],colorArray[9],0.5) + &quot;;} \
	.fmp .footer_bar{background:&quot; + MixTwoHexColors(colorArray[6],colorArray[9],0.5) + &quot;;} \
	.ffriends{background:&quot; + colorArray[9] + &quot;;} \
	.ffriend{border-bottom:solid 1px &quot; + colorArray[5] + &quot;;} \
	&quot;;
	
	/* New homepage layout specific */  /* todo: colorArray[5] is under used. */
	styleText += &quot; \
	.UIRoundedImage{background-color:&quot; + ForceContrast(MixTwoHexColors(colorArray[6],colorArray[9],0.5),&quot;#FFFFFF&quot;,0.05) + &quot;;}  /* All rounded images, mostly for the silhouettes. */  \
	\
	/* Left Column */ \
	#xxxhome_filter_list{background:&quot; + MixTwoHexColors(colorArray[9], colorArray[8],0.5) + &quot;;} \
	/* .UIFilterList_List{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[7],0.5) + &quot;;} */ \
	.UIMutableFilterList_Toggle{border-top:1px solid &quot; + colorArray[5] + &quot;;color:&quot; + colorArray[3] + &quot;;} \
	/* .UIMutableFilterList_Toggle{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[7],0.5) + &quot;;} */ \
	.UIFilterList_Item a{border-bottom:1px solid &quot; + colorArray[5] + &quot;;color:#333333;} \
	.UIFilterList_Item a{background-color:&quot; + MixTwoHexColors(colorArray[9], colorArray[8],0.5) + &quot;;} \
	.UIFilterList_Item a:hover{background-color:&quot; + MixTwoHexColors(colorArray[8], colorArray[6],0.5) + &quot;;} \
	.UIFilterList_Selected a{color:&quot; + ForceContrast(MixTwoHexColors(colorArray[8], colorArray[9],0.5),colorArray[4],0.20) + &quot;;} \
	.UIFilterList_Selected a{background-color:transparent;} \
	.UIFilterList_Selected{background:&quot; + colorArray[4] + &quot;;} \
	.UIFilterList_Selected .UIFilterList_ItemRight{background:&quot; + colorArray[4] + &quot;;} \
	.XXXUIFilterList_Selected{background:url(https://mywebspace.wisc.edu/ormont/web/facebook/UIFilterList_Selected_ltr-trans.png) no-repeat top left;} \
	.XXXUIFilterList_Selected .UIFilterList_ItemRight{background:transparent url(https://mywebspace.wisc.edu/ormont/web/facebook/UIFilterList_Selected_ltr-trans.png)  bottom left no-repeat;} \
	.UIFilterList_FirstItem{border-top:1px solid &quot; + colorArray[4] + &quot;;} \
	\
	/* Middle Column */ \
	#home_stream{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[7],0.5) + &quot;;} \
	.UIIntentionalStory{border-top:1px solid &quot; + colorArray[5] + &quot;; background-color:&quot; + colorArray[9] + &quot;;} \
	\
	/* Right Column */ \
	#home_sidebar{background:&quot; + MixTwoHexColors(colorArray[8], colorArray[7],0.5) + &quot;;} \
	.UIHomeBox_Title{color:&quot; + colorArray[4] + &quot;;} \
	.UIHomeBox_Top{border-bottom:1px solid &quot; + colorArray[5] + &quot;;} \
	.UIHomeBox_Top{background:&quot; + MixTwoHexColors(colorArray[9], colorArray[7],0.5) + &quot;;} \
	.UIHotStory{border-top:1px solid  &quot; + colorArray[6] + &quot;;} \
	.UIHotStory{background:&quot; + colorArray[9] + &quot;;} \
	.UIUpcoming{background:&quot; + colorArray[9] + &quot;;} \
	.UIUpcoming_Item{color:#333333;padding-top:2px;display:block;} \
	.UIUpcoming_Time{color:#808080;font-size:9px;white-space:nowrap;} \
	.UIMediaItem_Photo .UIMediaItem_PhotoFrame{border:3px solid &quot; + colorArray[9] + &quot;;} \
	\
	/* Other Stuff */ \
	.UIRecentActivityStory{background:&quot; + colorArray[9] + &quot;} \
	.UIRecentActivity_Stream .UIRecentActivity_Header{color:&quot; + ForceContrast(colorArray[5], colorArray[8], 0.15) + &quot;;} \
	UIStoryAttachment_Caption{color:&quot; + ForceContrast(colorArray[6], colorArray[9], 0.15) + &quot;;} \
	.UIStoryAttachment_Copy{color:&quot; + ForceContrast(colorArray[7], colorArray[9], 0.15) + &quot;;} \
	\
	span.action_links_bottom{color:&quot; + ForceContrast(MixTwoHexColors(&quot;#999999&quot;, colorArray[5],0.5), colorArray[7], 0.15) + &quot;;} /* The 'Added July 14' on the bottom of photos */ \
	\
	&quot;;
	
	//styleText += &quot;body { background-image: url('http://elastic.colourlovers.com/patternPreview/57/&quot; + colorArray[0].replace('#','') + &quot;/&quot; + colorArray[1].replace('#','') + &quot;/&quot; + colorArray[2].replace('#','') + &quot;/&quot; + colorArray[3].replace('#','') + &quot;/&quot; + colorArray[4].replace('#','') + &quot;.png'); }&quot;;
	
	//div[@id='box_app_2356318349']/h3[1][@class='box_header']
	//div[@id='box_app_2356318349']
	//div[@id='box_app_2392950137']/h3[1][@class='box_header']
	//div[@id='box_app_2407511955']/h3[1][@class='box_header']
	//div[@id='minifeed_936505']/div[2][@class='story_body size_2 from_friend_story wall_story']/div[1][@class='from_friend']/a[1]
//div[@id='minifeed_934970']/div[2][@class='story_body size_2 from_friend_story wall_story']/div[1][@class='from_friend']/a[1]/img[1][@class='app_actor_image']
//div[@id='minifeed_46872142']/div[2][@class='story_body size_2 from_friend_story']/div[2][@class='story_content tag_story_box from_friend_story']
//div[@id='minifeed_22319738']/div[2][@class='story_body size_2 from_friend_story wall_story']/div[2][@class='story_content story_media']
//div[@id='minifeed_46872142']/div[2][@class='story_body size_2 from_friend_story']/div[2][@class='story_content tag_story_box from_friend_story']
//div[@id='minifeed_22319738']/div[2][@class='story_body size_2 from_friend_story wall_story']

	
	styleNode.appendChild(document.createTextNode(styleText));

	
	if (document.getElementById('colorCSS') == null) { head.appendChild(styleNode); }
	else document.getElementById('colorCSS').parentNode.replaceChild(styleNode,document.getElementById('colorCSS'));

	styleNode.setAttribute('id', 'colorCSS');
	
	
	
	ReplaceSilhouette((ForceContrast(MixTwoHexColors(colorArray[6],colorArray[9],0.5),&quot;#FFFFFF&quot;,0.05)));  // .UIRoundedImage also effects some silhouettes.
	
	ReplaceUIRoundedImage(false);
	
	//HighlightColors(colorArray, currentImgDom);
	
	//GetBackgroundImages(colorArray);
	
}


function ReplaceSilhouette(hexColor) {
	try {
		var myImages = document.getElementsByTagName('img');
		
		for (var i=0; i&amp;lt;myimages&gt;-1) {
				myImages[i].src = &quot;https://mywebspace.wisc.edu/ormont/web/facebook/q_silhouette-trans-white-head.png&quot;;
				myImages[i].setAttribute('style',&quot;background: &quot; + hexColor + &quot;;&quot;);
			}
			
			if (myImages[i].src.indexOf('/s_silhouette.jpg')&gt;-1) {
				myImages[i].src = &quot;https://mywebspace.wisc.edu/ormont/web/facebook/s_silhouette-trans-white-head-swirl.png&quot;;
				myImages[i].setAttribute('style',&quot;background: &quot; + hexColor + &quot;;&quot;);
			}
			
			if (myImages[i].src.indexOf('/d_silhouette.gif')&gt;-1) {
				myImages[i].src = &quot;https://mywebspace.wisc.edu/ormont/web/facebook/l_silhouette-trans-white-head-swirl.png&quot;;
				myImages[i].setAttribute('style',&quot;background: &quot; + hexColor + &quot;;&quot;);
			}
			
			if (myImages[i].src.indexOf('/t_silhouette.jpg')&gt;-1) {
				myImages[i].src = &quot;https://mywebspace.wisc.edu/ormont/web/facebook/q_silhouette-trans-white-head-swirl.png&quot;;
				myImages[i].setAttribute('style',&quot;background: &quot; + hexColor + &quot;;&quot;);
			}
			
		}
	}
	catch(err) {
		
	}
}

function ReplaceUIRoundedImage(newImagesOnly) {
	try {
		//hexColor = &quot;#ff0000&quot;;
		//var img = new Image();
		//img.src = &quot;/images/ui/UIRoundedImage.png&quot;;
		//var canvas = document.createElement('canvas');	
		//canvas.className = &quot;UIRoundedImage_CornersSprite&quot;;
		//var ctx = canvas.getContext('2d');
		//canvas.width = img.width;
		//canvas.height = img.height;
		//ctx.drawImage(img,0,0,img.width,img.height);
		////alert(canvas.toDataURL());
		//ctx.globalAlpha = 1;
		//ctx.globalCompositeOperation = &quot;source-in&quot;;	
		//ctx.fillStyle = HexColorToRGBA(hexColor,1);
		//ctx.fillRect(0,0,canvas.width,canvas.height);
		
		
		//GM_log(&quot;Start ReplaceUIRoundedImage()&quot;);
	
		var tempDom;
		
		try {
			if (newImagesOnly == false) {
				
				// Replace previously colored canvases
				var Elements = document.getElementsByTagName('canvas');
				var ImgLen = Elements.length;
				
				//GM_log(&quot;ImgLen = &quot; + ImgLen);
				
				for (var i = 0; i &amp;lt; ImgLen-1; i++){
					//GM_log(&quot;Outside: Running thru canvas, i = &quot; + i);

					if (Elements[i].className == &quot;UIRoundedImage_CornersSprite&quot;) {
						//GM_log(&quot;Inside: Running thru canvas, i = &quot; + i);
						
						
						
						var color = &quot;&quot;;
						var tempDom = Elements[i].parentNode; //.parentNode.parentNode;
						while(color == &quot;&quot; || color == &quot;transparent&quot;) {
							tempDom = tempDom.parentNode;
							color = window.getComputedStyle(tempDom,null).backgroundColor;
						}
						
						//color = HexColorToRGBA(&quot;#FF0000&quot;,1);

						var img = new Image();
						img.src = &quot;/images/ui/UIRoundedImage.png&quot;;
						var canvas = document.createElement('canvas');	
						canvas.className = &quot;UIRoundedImage_CornersSprite&quot;;
						
						var ctx = canvas.getContext('2d');
						canvas.width = img.width;
						canvas.height = img.height;
						ctx.drawImage(img,0,0,img.width,img.height);
						
						ctx.globalAlpha = 1;
						ctx.globalCompositeOperation = &quot;source-in&quot;;	
						ctx.fillStyle = color; //HexColorToRGBA(hexColor,1);
						//ctx.fillStyle = HexColorToRGBA(hexColor,1);
						ctx.fillRect(0,0,canvas.width,canvas.height);
						//document.body.appendChild(canvas);
						Elements[i].parentNode.replaceChild(canvas,Elements[i]);
					}
				}
			}
		}
		catch(err) {
			GM_log(&quot;Error in canvas ReplaceUIRoundedImage(): &quot; + err);
		}
		
		try {
			Elements = document.getElementsByTagName('img');
			ImgLen = Elements.length;
			for (var i = 0; i &amp;lt; ImgLen-1; i++){
				if (Elements[i].src.indexOf(&quot;UIRoundedImage.png&quot;)&gt;-1) {
					
					var color = &quot;&quot;;
					var tempDom = Elements[i].parentNode; // .parentNode.parentNode;
					while(color == &quot;&quot; || color == &quot;transparent&quot;) {
						tempDom = tempDom.parentNode;
						color = window.getComputedStyle(tempDom,null).backgroundColor;
					}

					
					var img = new Image();
					img.src = &quot;/images/ui/UIRoundedImage.png&quot;;
					var canvas = document.createElement('canvas');	
					canvas.className = &quot;UIRoundedImage_CornersSprite&quot;;
					
					var ctx = canvas.getContext('2d');
					canvas.width = img.width;
					canvas.height = img.height;
					ctx.drawImage(img,0,0,img.width,img.height);

					ctx.globalAlpha = 1;
					ctx.globalCompositeOperation = &quot;source-in&quot;;	
					ctx.fillStyle = color; //HexColorToRGBA(hexColor,1);
					//ctx.fillStyle = HexColorToRGBA(hexColor,1);
					ctx.fillRect(0,0,canvas.width,canvas.height);
					//document.body.appendChild(canvas);
					Elements[i].parentNode.replaceChild(canvas,Elements[i]);
				}
			}
		}
		catch(err) {
			GM_log(&quot;Error in img ReplaceUIRoundedImage(): &quot; + err);
		}
		
		GM_log(&quot;End ReplaceUIRoundedImage()&quot;);
	}
	catch(err) {
		GM_log(&quot;Error in ReplaceUIRoundedImage(): &quot; + err);
	}
}

function HighlightColors(colorArray, ImgDom) {	// Doesn't work due to cross-domain issues.
	// Highlight colors on images that were used to color the page.
	
	var canvas = document.createElement(&quot;canvas&quot;);
	var canvasContext = canvas.getContext(&quot;2d&quot;);
	
	
	var i;
	var j;
	var k;
	
	canvas.width = ImgDom.width;
	canvas.height = ImgDom.height;

	
	canvasContext.drawImage(ImgDom, 0, 0);
	
	
	//canvasContext.drawImage(&quot;&lt;a href=&quot;http://photos-a.ak.fbcdn.net/photos-ak-sf2p/v297/109/100/8611250/n8611250_44467048_9037.jpg&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&quot; + colorArray[0] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[1] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[2] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[3] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[4] + &quot;&lt;/td&gt;&lt;/tr&gt;&quot;);
	document.write(&quot;&lt;tr&gt;&lt;td&gt;&quot; + colorArray[5] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[6] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[7] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[8] + &quot;&lt;/td&gt;&lt;td&gt;&quot; + colorArray[9] + &quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;);
}

function GetSaturation(hexColor) {
	
	var red = parseInt(hexColor.substr(1,2), 16)/255;
	var green = parseInt(hexColor.substr(3,2), 16)/255;
	var blue = parseInt(hexColor.substr(5,2), 16)/255;
	
	
	var max = Math.max(red,green,blue);  
	var min = Math.min(red,green,blue);
/*	
	var hue = 221;  
	
	if (red == max) hue = 60*(green-blue)/(max-min);
	if (green == max) hue = 60*(blue-red)/(max-min)+120;
	if (blue == max) hue = 60*(red-green)/(max-min)+240; 
	
	if (max == min) hue = 0;
	
	if (hue &gt; 360) hue = hue - 360;
	if (hue &amp;lt; 0) hue = hue + 360;
	
	*/
	
	//  if ((max + min)/2 &amp;lt; 0.5) var saturation=(max-min)/(max+min) * (100-increasePercent) + increasePercent;
	//  if ((max + min)/2 &gt;=0.5) var saturation=(max-min)/(2.0-max-min) * (100-increasePercent) + increasePercent;
	
	
	var saturation = (1-min/max)*100;
	
	//alert(&quot;saturation: &quot; + Math.floor(saturation) );
	
	
	return Math.floor(saturation);
	
}

function GetContrast(hexColor1, hexColor2) {
	/* Contrast should generally be around 500 for background &amp;amp; foreground */
	var red1 = parseInt(hexColor1.substr(1,2), 16)/255;
	var green1 = parseInt(hexColor1.substr(3,2), 16)/255;
	var blue1 = parseInt(hexColor1.substr(5,2), 16)/255;
	
	var red2 = parseInt(hexColor2.substr(1,2), 16)/255;
	var green2 = parseInt(hexColor2.substr(3,2), 16)/255;
	var blue2 = parseInt(hexColor2.substr(5,2), 16)/255;
	
	return (Math.max(red1,red2) - Math.min(red1,red2)) + (Math.max(blue1,blue2) - Math.min(blue1,blue2)) + (Math.max(green1,green2) - Math.min(green1,green2));
}


function GetBrightness(hexColor) {
	/* Contrast should generally be around 500 for background &amp;amp; foreground */
	var red = parseInt(hexColor.substr(1,2), 16)/255;
	var green = parseInt(hexColor.substr(3,2), 16)/255;
	var blue = parseInt(hexColor.substr(5,2), 16)/255;

	return (red*299 + green*587 + blue*114)/1000;
}


function GetLuminance(hexColor) {
	/* Luminance ratio between foreground and background should be 5:1 */
	var red = parseInt(hexColor.substr(1,2), 16)/255;
	var green = parseInt(hexColor.substr(3,2), 16)/255;
	var blue = parseInt(hexColor.substr(5,2), 16)/255;

	if (red &amp;lt;= 0.03928) red = red/12.92;
	else red = ((red+0.055)/1.055)^2.4; 


	if (green &amp;lt;= 0.03928) green = green/12.92;
	else green = ((green+0.055)/1.055)^2.4; 


	if (blue &amp;lt;= 0.03928) blue = blue/12.92;
	else blue = ((blue+0.055)/1.055)^2.4; 

   return 0.2126 * red + 0.7152 * green + 0.0722 * blue 
}



function ForceContrast(hexColor1, hexColor2, contrastMinimum) {
//return hexColor1;
		
	var brightness1 = GetBrightness(hexColor1);
	var brightness2 = GetBrightness(hexColor2);

	var brightnessDiff = Math.abs(brightness1 - brightness2);

	//alert(&quot;brightnessDiff = &quot; + brightnessDiff);

	//alert(&quot;colors = &quot; + hexColor1 + &quot; &quot; + hexColor2);
	
	var i = 0;
	
	if (brightness1 == brightness2 &amp;amp;&amp;amp; brightness1 &gt; 0.5) var mixColor = &quot;#000000&quot;;
	else if (brightness1 == brightness2 &amp;amp;&amp;amp; brightness1 &amp;lt;= 0.5) var mixColor = &quot;#FFFFFF&quot;;
	else if (brightness1 &gt;= brightness2 &amp;amp;&amp;amp; (1 - brightness2) &amp;lt; contrastMinimum) var mixColor = &quot;#FFFFFF&quot;;
	else if (brightness1 &gt;= brightness2 &amp;amp;&amp;amp; (1 - brightness2) &gt;= contrastMinimum) var mixColor = &quot;#000000&quot;;	
	else if (brightness1 &amp;lt; brightness2 &amp;amp;&amp;amp; brightness2 &amp;lt; contrastMinimum) var mixColor = &quot;#FFFFFF&quot;;
	else if (brightness1 &amp;lt; brightness2 &amp;amp;&amp;amp; brightness2 &gt;= contrastMinimum) var mixColor = &quot;#000000&quot;;


	while (brightnessDiff &amp;lt; contrastMinimum) {
		i = i+1;
		if (i &gt; 10) { RecordTimer(&quot;ForceContrast&quot;); return hexColor1; }
		
		var brightness1 = GetBrightness(hexColor1);
		var brightnessDiff = Math.abs(brightness1 - brightness2);
		
		hexColor1 = MixTwoHexColors(hexColor1, mixColor, 0.005 + 2*Math.abs(contrastMinimum - brightnessDiff)); // The part in th 'abs' just make it converge faster. 
		//alert(&quot;brightness = &quot; + brightness1 + &quot; &quot; + brightness2 + &quot;\nratio = &quot; + brightnessDiff + &quot;\ni = &quot; + i + &quot;\nhexColor1 = &quot; + hexColor1);
	}
	
	return hexColor1;

}


function ForceContrastXXX(hexColor1, hexColor2, contrastMinimum) {
	//return hexColor1;
	/* If the colors are too close to each other, move color1 away from color2 */
	var luminance1 = GetLuminance(hexColor1);
	var luminance2 = GetLuminance(hexColor2);

	var luminanceRatio1 = ((luminance1+0.5)/(luminance2+0.5));
	var luminanceRatio2 = ((luminance2+0.5)/(luminance1+0.5));

	alert(&quot;luminanceRatio1 = &quot; + luminanceRatio1);

	//alert(&quot;colors = &quot; + hexColor1 + &quot; &quot; + hexColor2);
	
	
	var i = 0;
	
	while (luminanceRatio1 &amp;lt; contrastMinimum &amp;amp;&amp;amp; luminanceRatio2 &amp;lt; contrastMinimum) {
		i = i+1;
		if (i &gt; 5) return hexColor1;
		
		var luminance1 = GetLuminance(hexColor1);
		var luminance2 = GetLuminance(hexColor2);

		var luminanceRatio1 = ((luminance1+0.5)/(luminance2+0.5));
		var luminanceRatio2 = ((luminance2+0.5)/(luminance1+0.5));
		
		alert(&quot;luminance = &quot; + luminance1 + &quot; &quot; + luminance2);
			
		alert(&quot;forcing contrast&quot;);
		if (luminanceRatio1 &amp;lt; 1) {
			/* Color one is brighter */
			hexColor1 = MixTwoHexColors(hexColor1, &quot;#FFFFFF&quot;, 0.1);
			alert(&quot;here 1&quot;);
		}
		else if (luminanceRatio1 &gt; 1) {
			/* Color one is darker */
			hexColor1 = MixTwoHexColors(hexColor1, &quot;#000000&quot;, 0.1);
			alert(&quot;here 2&quot;);
		}
		else {
			if (hexColor1 == hexColor2) {
				alert(&quot;here 3&quot;);
				if (hexColor1.toUpperCase() == &quot;#FFFFFF&quot;) hexColor1 = &quot;#AAAAAA&quot;;
				else if (hexColor1 == &quot;#000000&quot;) hexColor1 = &quot;#111111&quot;;
				else {
					if (luminance1 &gt; 1.5) hexColor1 = MixTwoHexColors(hexColor1, &quot;#FFFFFF&quot;, 0.1); 
					else hexColor1 = MixTwoHexColors(hexColor1, &quot;#000000&quot;, 0.1);
				}
			}
			else {
				alert(&quot;here 4&quot;);
				preHexColor1 = hexColor1;
				alert(&quot;before hexColor1 = &quot; + hexColor1);
				hexColor1 = MixTwoHexColors(hexColor1, &quot;#FFFFFF&quot;, 0.1);  //this line could be better
				alert(&quot;after hexColor1 = &quot; + hexColor1);
				if (preHexColor1 == hexColor1) return hexColor1;
			}
		}
		
	}
	
	return hexColor1;

}

function IncreaseSaturation(hexColor,increasePercent) {
	if (increasePercent &amp;lt; 0) increasePercent = 0;  
	if (increasePercent &gt; 100) increasePercent = 100;  //saturating math...hehe
	
	
	var red = parseInt(hexColor.substr(1,2), 16)/255;
	var green = parseInt(hexColor.substr(3,2), 16)/255;
	var blue = parseInt(hexColor.substr(5,2), 16)/255;
	
	
	var max = Math.max(red,green,blue);  
	var min = Math.min(red,green,blue);
	
	var hue = 221;  
	
	if (red == max) hue = 60*(green-blue)/(max-min);
	if (green == max) hue = 60*(blue-red)/(max-min)+120;
	if (blue == max) hue = 60*(red-green)/(max-min)+240; 
	
	if (max == min) hue = 0;

	if (hue &gt; 360) hue = hue - 360;
	if (hue &amp;lt; 0) hue = hue + 360;
	
	
	
	//if ((max + min)/2 &amp;lt; 0.5) var saturation = (max-min)/(max+min) * (100-increasePercent) + increasePercent;
	//if ((max + min)/2 &gt;=0.5) var saturation = (max-min)/(2.0-max-min) * (100-increasePercent) + increasePercent;
	
	
	
	var saturation = (1-min/max)*100;
	
	
		
	//alert(&quot;saturation: &quot; + Math.floor(saturation) + &quot; hue: &quot; + Math.floor(hue) + &quot; lightness: &quot; + Math.floor((max + min)*50));
		
	if (saturation &amp;lt; 40) return &quot;hsl(219,42%,40%)&quot;;  //make sure no off gray -&gt; bright color
	
	//saturation = saturation * (100-increasePercent) + increasePercent;
	
	//  alert((max-min)*50);
	//  alert(&quot;hsl(&quot; + Math.floor(hue) + &quot;,&quot; + Math.floor(saturation) + &quot;%,50%)&quot;);
	return &quot;hsl(&quot; + Math.floor(hue) + &quot;,&quot; + Math.floor(saturation) + &quot;%,&quot; + Math.floor((max + min)*50) + &quot;%)&quot;;
	
	/*
		if (blue == max) blue=255*increasePercent/100 + blue*(1-increasePercent/100);
	 else if (red == max) red=255*increasePercent/100 + red*(1-increasePercent/100);
	 else if (green == max) green=255*increasePercent/100 + green*(1-increasePercent/100);
	 
	 if (red == min) red=red*(1-increasePercent/100);
	 else if (green == min) green=green*(1-increasePercent/100);
	 else if (blue == min) blue=blue*(1-increasePercent/100);    
	 return &quot;rgb(&quot; + Math.floor(red) + &quot;,&quot; + Math.floor(green) + &quot;,&quot; + Math.floor(blue) + &quot;)&quot;;
	 */
	
	
	
}

function HexColorToRGBA(hexColor, alpha) {
	var red = parseInt(hexColor.substr(1,2), 16);
	var green =  parseInt(hexColor.substr(3,2), 16);
	var blue =  parseInt(hexColor.substr(5,2), 16);
	
	alpha = Math.min(Math.max(alpha, 0), 1);
	
	return &quot;rgba(&quot; + red + &quot;,&quot; + green + &quot;,&quot; + blue + &quot;,&quot; + alpha + &quot;)&quot;;

}

function AverageTwoHexColorsToRGB(hexColor1,hexColor2) {
	var red = Math.floor((parseInt(hexColor1.substr(1,2), 16) + parseInt(hexColor2.substr(1,2), 16))/2);
	var green =  Math.floor((parseInt(hexColor1.substr(3,2), 16) + parseInt(hexColor2.substr(3,2), 16))/2);
	var blue =  Math.floor((parseInt(hexColor1.substr(5,2), 16) + parseInt(hexColor2.substr(5,2), 16))/2);
	
	return &quot;rgb(&quot; + red + &quot;,&quot; + green + &quot;,&quot; + blue + &quot;)&quot;;
}


function MixTwoHexColors(hexColor1,hexColor2,percentColor2)
{
	// ex: var hexFade = MixTwoHexColors(&quot;#F1CD00&quot;,&quot;#12C011&quot;,.75);
	
	if (percentColor2 &gt; 1) percentColor2 = 1;
	if (percentColor2 &amp;lt; 0) percentColor2 = 0;
	
	var red = Math.floor((1-percentColor2)*parseInt(hexColor1.substr(1,2), 16) + percentColor2*parseInt(hexColor2.substr(1,2), 16));
	var green =  Math.floor((1-percentColor2)*parseInt(hexColor1.substr(3,2), 16) + percentColor2*parseInt(hexColor2.substr(3,2), 16));
	var blue =  Math.floor((1-percentColor2)*parseInt(hexColor1.substr(5,2), 16) + percentColor2*parseInt(hexColor2.substr(5,2), 16));
	
	/*if (red &gt; 1) red = 1;
	if (blue &gt; 1) blue = 1;
	if (green &gt; 1) green = 1;
	
	if (red &amp;lt; 0) red = 0;
	if (blue &amp;lt; 0) blue = 0;
	if (green &amp;lt; 0) green = 0;*/
	
	return &quot;#&quot; + decimalToHex(red) + decimalToHex(green) + decimalToHex(blue);
	
}


function decimalToHex(decimalValue)  /* works for 0 to 255 */
{
	var high = Math.floor(decimalValue/16);
	var low = Math.round((decimalValue/16 - Math.floor(decimalValue/16))*16);
	
	
	if (high&gt;9) high = String.fromCharCode(high-10+65);
	if (low&gt;9) low = String.fromCharCode(low-10+65);
	
	
	return &quot;&quot; + high + &quot;&quot; + low;
}


//function fadeBetweenTwoColorSchemes(currentFadePercent,fadeStep,endingFadePercent,delay)  
function fadeBetweenTwoColorSchemes(fadeStartTime, fadeDuration)
{
	
	//alert('fadeBetweenTwoColorSchemes(currentFadePercent=' + currentFadePercent + ', fadeStep=' + fadeStep + ', endingFadePercent=' + endingFadePercent + ', delay=' + delay + ')');
	
	var currentTime = new Date();	// Used to set initial start time on the first run, and delta time on every other run.
		
	if (fadeStartTime == null) {  // fadeStartTime will be null on first run, so set it to current time.
		fadeStartTime = currentTime.getTime();
		//alert(&quot;set fade time&quot;);
	}
	
	//var currentFadePercent = currentFadePercent + fadeStep;
	var currentFadePercent = (currentTime - fadeStartTime)/fadeDuration;
	
	//if (currentFadePercent &gt; endingFadePercent) currentFadePercent = endingFadePercent;
	if (currentFadePercent &gt; 1.0) currentFadePercent = 1.0;
	
	
	
	var finalColorArray = window.document.body.getAttribute('finalColorArray').split('*');
	var startingColorArray = window.document.body.getAttribute('startingColorArray').split('*');
	
	//var finalColorArray = (&quot;#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*&quot;).split('*');
	//var startingColorArray = (&quot;#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*#FF0000*&quot;).split('*');
	
	
	//alert(&quot;Start: &quot; + startingColorArray.join(', '));
	//alert(&quot;Final: &quot; + finalColorArray.join(', '));
	
	var fadedColorArray = new Array(10);
	
	fadedColorArray[0] = MixTwoHexColors(startingColorArray[0],finalColorArray[0],currentFadePercent);
	fadedColorArray[1] = MixTwoHexColors(startingColorArray[1],finalColorArray[1],currentFadePercent);
	fadedColorArray[2] = MixTwoHexColors(startingColorArray[2],finalColorArray[2],currentFadePercent);
	fadedColorArray[3] = MixTwoHexColors(startingColorArray[3],finalColorArray[3],currentFadePercent);
	fadedColorArray[4] = MixTwoHexColors(startingColorArray[4],finalColorArray[4],currentFadePercent);
	fadedColorArray[5] = MixTwoHexColors(startingColorArray[5],finalColorArray[5],currentFadePercent);
	fadedColorArray[6] = MixTwoHexColors(startingColorArray[6],finalColorArray[6],currentFadePercent);
	fadedColorArray[7] = MixTwoHexColors(startingColorArray[7],finalColorArray[7],currentFadePercent);
	fadedColorArray[8] = MixTwoHexColors(startingColorArray[8],finalColorArray[8],currentFadePercent);
	fadedColorArray[9] = MixTwoHexColors(startingColorArray[9],finalColorArray[9],currentFadePercent);
	
	
	//alert(&quot;Faded: &quot; + fadedColorArray.join(', ')); 
	
	
	//startTime = new Date();
	InsertCSS(fadedColorArray);
	//currentTime = new Date();
	//var timeTaken = (currentTime.getTime() - startTime.getTime());
	
	
	//if (currentFadePercent &amp;lt; endingFadePercent) /*fadeTimer =*/ setTimeout(fadeBetweenTwoColorSchemes, delay - timeTaken, currentFadePercent, fadeStep, endingFadePercent, delay);
	//else {
	//	window.document.body.setAttribute('startingColorArray',window.document.body.getAttribute('finalColorArray'));
	//	//alert(&quot;Fade done&quot;);
	//}
	
	if (currentFadePercent &amp;lt; 1.0) setTimeout(fadeBetweenTwoColorSchemes, /* zero delay till run again */ 0, fadeStartTime, fadeDuration);  
	else {
		window.document.body.setAttribute('startingColorArray',window.document.body.getAttribute('finalColorArray'));
		//alert(&quot;Fade done&quot;);
		
		// Run one last time (to get elements that failed to load before we colored.
		if ((currentTime - fadeStartTime)/fadeDuration &amp;lt; 2)	setTimeout(fadeBetweenTwoColorSchemes, /* delay till run again */ 1000, fadeStartTime, fadeDuration);  
	}
}


function CheckForUpdate() {
	
	//alert(&quot;Checking for update&quot;);
	
	var versionOnServer = new Array(0,0,0);
	
	GM_xmlhttpRequest({
		method: 'GET',
		url: 'http://www.ormont.net/version.xml',
		headers: {
			//'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
			'Accept': 'application/atom+xml,application/xml,text/xml',
		},
		onload: function(responseDetails) {
			var parser = new DOMParser();
			var dom = parser.parseFromString(responseDetails.responseText, &quot;application/xml&quot;);
		    var entries = dom.getElementsByTagName('version');
			
			var versionOnServerDOM;
			var changes;
			var link;
			for (var i = 0; i &amp;lt; entries.length; i++) {
				versionOnServerDOM = entries[i].getElementsByTagName('versionsegment');
				changes = entries[i].getElementsByTagName('changes');
				link = entries[i].getElementsByTagName('link');
			}
						
			if (entries.length == 0) return;  //no version tag found.        
			
			for(var k = 0; (k &amp;lt; versionOnServerDOM.length); k++) versionOnServer[k] = versionOnServerDOM[k].textContent;
			
			try { 
				if (typeof GM_getValue('lastNotifiedVersion','') != 'undefined') lastNotifiedVersion = GM_getValue('lastNotifiedVersion','').split(&quot;,&quot;);
				else lastNotifiedVersion = new Array(0,0,0);
			}
			catch(err) { lastNotifiedVersion = new Array(0,0,0); }
			
			
			var alreadyNotifedOfNewVersion = 1;
			for(var j = 0; j &amp;lt; lastNotifiedVersion.length; j++) if (lastNotifiedVersion[j] != versionOnServer[j]) alreadyNotifedOfNewVersion = 0;
			
			if (alreadyNotifedOfNewVersion == 1) return;

			//alert(&quot;Version on server = &quot; + versionOnServer.join(&quot;.&quot;) + &quot;, Running Version = &quot; + thisScriptVersion.join(&quot;.&quot;));
			for(var j = 0; j &amp;lt; versionOnServer.length; j++) {
				if ((thisScriptVersion[j] &amp;lt; versionOnServer[j]) || ((typeof thisScriptVersion[j] == 'undefined') &amp;amp;&amp;amp; (typeof versionOnServer[j] != 'undefined'))) {
					if(confirm(&quot;A new version of Facebook Auto-Colorizer was released.\n\n&quot; + changes[0].textContent + &quot;\n\nNotice appears only once per version.&quot; + &quot;\n\nGo to Install Page?&quot;)) {
						window.location = link[0].textContent;
						return;
					}
					else {
						try { GM_setValue('lastNotifiedVersion',versionOnServer.join(',')); }
						catch(err) { alert(&quot;Error: Can not write to version key.\n\nabout:config key was reset; Restart firefox.&quot;); }
						SetLastCheckedForVersionVariable();
						return;
					}
				}
				
				if (thisScriptVersion[j] &gt; versionOnServer[j]) {
					//alert(&quot;no update needed, thanks for beta testing the new version.&quot;);
					SetLastCheckedForVersionVariable();
					return;
				}
			}
			
			//alert(&quot;no update needed&quot;);
			SetLastCheckedForVersionVariable();
		}
	});
}


function AttemptToPreCacheForNextPage() {
	return;  // this is currently not working. (and causing alot of bad images urls)
	
	if (getApparentUrl().indexOf('/photo.php?') == -1) return false;
	try{ 
		var documentSrc=document.body.innerHTML;
		var nextImageOnload = &quot;&quot;;
		documentSrcSplit = documentSrc.split('&quot;');
		for (i in documentSrcSplit) {
			if (documentSrcSplit[i].indexOf('(new Image()).src=')&gt;-1) nextImageOnload = documentSrcSplit[i];
		} 
		var nextImage = nextImageOnload.split(&quot;'&quot;)[1];
		nextImage = nextImage.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
		
		StartTimer(&quot;Look for PreCache in Cache&quot;);
		if (RetrieveFromCache(nextImage, UrlToCacheType(nextImage)) == null) GetColors(nextImage, false);
		RecordTimer(&quot;Look for PreCache in Cache&quot;);
		
		//alert(&quot;nextImage = &quot; + nextImage);
		return true;
	}
	catch(err){return false;}
}

function PreCacheChangedProfilePics() {	
	
	
	StartTimer(&quot;PreCache Changed Profile Pics&quot;);
	var entries = document.getElementsByTagName('div');
	
	var numEntries = entries.length;

	
	for (i = 0; i &amp;lt; numEntries; i++) {
		if (entries[i].className == 'clearfix pictures_container') {
			myImages = entries[i].getElementsByTagName('img');
			var numImages = myImages.length;
			
			for (j = 0; j &amp;lt; numImages; j++) {
				var nextImage = (myImages[j].src).split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
				
				/* Todo: check the the image is not already cached */
				StartTimer(&quot;Look for PreCache Profile Pics in Cache&quot;);
				if (RetrieveFromCache(nextImage, UrlToCacheType(nextImage)) == null) GetColors(nextImage, false);
				RecordTimer(&quot;Look for PreCache Profile Pics in Cache&quot;);
			}
			
		}
	}
	RecordTimer(&quot;PreCache Changed Profile Pics&quot;);
}


function PreCacheAllImagesOnPage() {	
	StartTimer(&quot;PreCache All Images on Page&quot;);
	
	myImages = document.getElementsByTagName('img');
	var numImages = myImages.length;
	
	for (j = 0; j &amp;lt; numImages; j++) {
		var nextImage = (myImages[j].src).split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
		nextImage = nextImage.replace('&lt;a href=&quot;http://ttatic.ak','http://static.ak')&quot;&gt;http://ttatic.ak','http://static.ak')&lt;/a&gt;;
		
		/* Todo: check the the image is not already cached */
		StartTimer(&quot;Look for PreCache Profile Pics in Cache&quot;);
		if (RetrieveFromCache(nextImage, UrlToCacheType(nextImage)) == null) GetColors(nextImage, false);
		RecordTimer(&quot;Look for PreCache Profile Pics in Cache&quot;);
	}
	

	
	RecordTimer(&quot;PreCache All Images on Page&quot;);
}

function AddToApplicationsList() {
	StartTimer(&quot;Add To Applications List&quot;);
	var presenceBar = document.getElementById(&quot;application_icon_garden_root&quot;);
	//alert(expandBar.previousSibling.lastChild.lastChild.innerHTML)
	
	var textNode = document.createTextNode(&quot;Auto-Colorizer&quot;);
	
	var link = document.createElement('a');
	link.setAttribute('href', '&lt;a href=&quot;http://www.facebook.com/share.php?u=http%3A%2F%2Fuserscripts%2Eorg%2Fscripts%2Fshow%2F3626&amp;amp;t=Facebook+Auto%2DColorizer%3A+Adds+an+awesome+color+scheme+to+every+facebook+page+based+on+you+friend%27s+photo%2E')&quot;&gt;http://www.facebook.com/share.php?u=http%3A%2F%...&lt;/a&gt;;
	link.setAttribute('class', 'link_title');
	link.setAttribute('onmousedown', 'new track_moveable(this.parentNode, this);');
	link.setAttribute('style',&quot;background-image: url(&lt;a href=&quot;https://mywebspace.wisc.edu/ormont/web/facebook/color_logo_16x16.png);&quot;&gt;&lt;div&gt;&lt;a&gt;','&lt;img src=&quot;',appInfo['new_icon'],'&quot; /&gt;','&lt;div&gt;','&lt;strong&gt;',htmlize(appInfo['name']),'&lt;/strong&gt;','&lt;/div&gt;','','&lt;/div&gt;'];
	
	_renderApplicationIconGardenItem:function(appID){
		var appInfo=this.applications[appID];
		var markupArr=['&lt;div&gt;',
					   '&lt;a&gt;',
					   '&lt;img src=&quot;',
					   appInfo['new_icon'],
					   '&quot; /&gt;',
					   '&lt;div&gt;',
					   '&lt;strong&gt;',
					   htmlize(appInfo['name']),
					   '&lt;/strong&gt;',
					   '&lt;/div&gt;',
					   '',
					   '&lt;/div&gt;'];
		return markupArr.join('');
	}
	
	,mouseOverIconGarden:function(appID){if(shown(this.menuWrapper)){return;}
		*/
		
/*
	link.setAttribute('onmouseover', 
		&quot;var fbAutoColorizerDialog = new pop_dialog(); \
		fbAutoColorizerDialog.show_dialog('&lt;div&gt;'+tx('sh01')+'&lt;/div&gt;'); \
		getDialog = new Ajax(); \
		getDialog.onDone = function(ajax_obj,responceText){ \
		alert(responceText); \
		} \
		 &quot; );
*/

	//alert(ShowDialog);

	/*
	var divInside = document.createElement('div');
	divInside.setAttribute('class', 'container');
	divInside.setAttribute('ID', '2437461801');

	var divOutside = document.createElement('div');
	divOutside.setAttribute('class', 'list_item');	
	
	link.appendChild(textNode);
	divInside.appendChild(link);
	divOutside.appendChild(divInside);
	expandBar.previousSibling.lastChild.appendChild(divOutside);
	*/
	RecordTimer(&quot;Add To Applications List&quot;);
}

function IsInChatBar(ImgNode) {
	// Note: &quot;profile_status clearfix&quot; is the class of the parient's parient of a photo in the chat bar. 
	if (ImgNode.getAttribute(&quot;class&quot;) == &quot;chat_info_pic&quot;) return true;
	
	
	return (ImgNode.parentNode.parentNode.getAttribute(&quot;class&quot;) == &quot;profile_status clearfix&quot;);
}

function ShowDialog() {
	var fbAutoColorizerDialog = new pop_dialog(); 
	fbAutoColorizerDialog.show_dialog('&lt;div&gt;'+tx('sh01')+'&lt;/div&gt;'); 
	//fbAutoColorizerDialog.make_modal();
	//fbAutoColorizerDialog.fade_out(1000);
	
	//fbAutoColorizerDialog.show_choice(&quot;hello2&quot;,&quot;how are you?&quot;,tx('pk01'),function(){}, tx('sh02'),function(){});
	
	//fbAutoColorizerDialog.show_message(&quot;Facebook Auto-Colorizer&quot;, &quot;This is work in progress.&quot;);
	
	
	var content = &quot;&lt;table&gt;&amp;lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;img src=&quot;https://mywebspace.wisc.edu/ormont/web/facebook/color_logo_16x16.png&quot; height=&quot;64&quot; width=&quot;64&quot; /&gt;&lt;/td&gt;&lt;td width=&quot;64&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;\
	&lt;a href=&quot;http://www.facebook.com/share.php?u=http://userscripts.org/scripts/show/3626&amp;amp;amp;t=Facebook+Auto-Colorizer:+Adds+an+awesome+color+scheme+to+every+facebook+page+based+on+you+friend%27s+photo.&quot;&gt;\
	&lt;img src=&quot;http://static.ak.facebook.com/images/share/facebook_share_icon.gif&quot; /&gt;&lt;img src=&quot;http://wisc.facebook.com/images/share_options/share_button_ff_mac.gif&quot; /&gt;&lt;/a&gt;&lt;br /&gt;\
	&lt;br /&gt;&lt;a href=&quot;http://userscripts.org/scripts/show/3626&quot;&gt;Facebook Auto-Colorizer Install Page&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://wisc.facebook.com/inbox/?compose&amp;amp;amp;id=8638838&quot;&gt;Send Author a Message&lt;/a&gt;\
	&lt;br /&gt;&lt;br /&gt;[future: Simple Color Controls]&lt;br /&gt;Chat bar: \
	&amp;lt;input&gt;  \
	Colored \
	&amp;lt;input&gt;  \
	Clear \
	&amp;lt;input&gt;  \
	Color Gel&lt;/p&gt;\
	&lt;br /&gt;&lt;center&gt;\
	&amp;lt;form&gt;\
	&amp;lt;input /&gt;\
	&amp;lt;input /&gt;\
	&amp;lt;input /&gt;\
	&amp;lt;input /&gt;\
	Amount &amp;lt;input /&gt;\
	&amp;lt;input src=&quot;http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif&quot; alt=&quot;Make payments with PayPal - it&quot;&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
			photoUrl = url;
		}
	}
	catch(err){}
	
	
	//look specifically for the top image on the home page.
	if ((typeof photoUrl == 'undefined') &amp;amp;&amp;amp; (getApparentUrl().indexOf('/home.php')&gt;-1)) {
		try {
			if (window.document.body != null) {
				var myImages = document.getElementById('home_stream').getElementsByTagName('img');
				var numEntries = myImages.length;
				for (i = 4; i &amp;lt; numEntries; i++) {
					url = myImages[i].src;
					if ((url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.XXXgif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) &amp;amp;&amp;amp; (url.indexOf('UIRoundedImage.png')==-1) &amp;amp;&amp;amp; (url.indexOf('platform.ak.facebook.com')==-1)) {
						photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
						currentImgDom = myImages[i];
						i = numEntries;  // Break from the loop.
						//alert(photoUrl);
					}
				}
			}
		}
		catch(err) {
			//GM_log(&quot;Could not find photo using: document.getElementById('home_stream').getElementsByTagName('img')[0].src&quot;);
		}
	}

	
	//look specifically for a photo album image
	if ((typeof photoUrl == 'undefined') &amp;amp;&amp;amp; (getApparentUrl().indexOf('/photo.php?')&gt;-1)) {
		try {
			if (window.document.body != null) {
				url = document.getElementById('myphoto').src;
				if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
					photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
					currentImgDom = document.getElementById('myphoto');
				}
			}
		}
		catch(err) {
			//GM_log(&quot;Could not find photo using: document.getElementById('myphoto')&quot;);
		}
	}
	
	//look specifically for a group image
	if ((typeof photoUrl == 'undefined') &amp;amp;&amp;amp; (getApparentUrl().indexOf('/group.php?')&gt;-1)) {
		try {
			if (window.document.body != null) {
				url = document.getElementById('profileimage').getElementsByTagName('img')[0].src;
				
				if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
					photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
					currentImgDom = document.getElementById('profileimage').getElementsByTagName('img')[0];
				}
			}
		}
		catch(err) {
			//GM_log(&quot;Could not find photo using: document.getElementById('myphoto')&quot;);
		}
	}
	
	//look specifically for a profile photo
	if ((typeof photoUrl == 'undefined') &amp;amp;&amp;amp; (window.document.body != null)) {
		try {
			url = document.getElementById('profile_pic').src;
			if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
				if (url.indexOf('silhouette')==-1) {
					photoUrl = document.getElementById('profile_pic').src.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
					currentImgDom = document.getElementById('profile_pic');
				}
			}
		}
		catch(err) {
			
		}
	}
	
	
	//look specifically for a share.php selected photo (!!! doesn't work !!!)
	if (getApparentUrl().indexOf('/share.php?')&gt;-1) {
		if (typeof photoUrl == 'undefined') {
			try {
				var entries = document.getElementsByTagName('div');
				var numEntries = entries.length;
				for (i = 0; i &amp;lt; numEntries; i++) {
					if (entries[i].className == 'thumbnail thumbnail_selected') {
						// NEED TO GET URL HERE!!!
						//url = ??????;
						if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
							photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
							//currentImgDom = ???
						}
						//alert(&quot;Found share pic: &quot; + photoUrl);
					}
				}
			}
			catch(err) {}
		}
	}
	
	
	myImages = document.getElementsByTagName('img');
	
	//look specifically for a group image
	if (typeof photoUrl == 'undefined') {
		if (getApparentUrl().indexOf('/group.php?')&gt;-1) {
			for (var i=0; i&amp;lt;myimages&gt;-1)) &amp;amp;&amp;amp; (url.indexOf('t_default.jpg')==-1)) {
					if (typeof photoUrl == 'undefined') {
						if (!IsInChatBar(myImages[i])) {
							if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
								photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
								currentImgDom = myImages[i];
							}
							//alert(&quot;here 1&quot;);
						}
					}
				}
			}
		}
	}
	
	
	
	//look specifically for a user image on a profile page
	if (typeof photoUrl == 'undefined') {
		if (getApparentUrl().indexOf('/profile.php?')&gt;-1 || getApparentUrl().indexOf('/s.php?')&gt;-1) {
			for (var i=0; i&amp;lt;myimages&gt;-1)) &amp;amp;&amp;amp; (url.indexOf('t_default.jpg')==-1)) {
					if (typeof photoUrl == 'undefined') {
						if (!IsInChatBar(myImages[i])) {
							if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
								photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
								currentImgDom = myImages[i];
								
								photoUrl = undefined;
							}
							//alert(&quot;here 2&quot;);
						}
					}
				}
			}
		}
	}
	
	//look for a group or event image
	if (typeof photoUrl == 'undefined') {
		for (var i=0; i&amp;lt;myimages&gt;-1) || (url.indexOf('/ppic/')&gt;-1) || (url.indexOf('/object')&gt;-1)) &amp;amp;&amp;amp; (url.indexOf('t_default.jpg')==-1) &amp;amp;&amp;amp; (url.indexOf('/object/')==-1)) {
				if (typeof photoUrl == 'undefined') {
					if (!IsInChatBar(myImages[i])) { 
						if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
							photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
							currentImgDom = myImages[i];
						}
						//alert(&quot;here 3&quot;);
					}
					
				}
			}
		}
	}
	
	//look for a user image
	if (typeof photoUrl == 'undefined') {
		for (var i=0; i&amp;lt;myimages&gt;-1) || (url.indexOf('http://profile.')&gt;-1)  || (url.indexOf('http://photos.')&gt;-1) || (url.indexOf('http://pe-')&gt;-1) || (url.indexOf('http://vthumb.')&gt;-1)) &amp;amp;&amp;amp; (url.indexOf('/app_')==-1)) {
				
				if (typeof photoUrl == 'undefined') {
					if (!IsInChatBar(myImages[i])) {
						if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
							photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
							currentImgDom = myImages[i];
						}
						//alert(&quot;here 4&quot;);
					}
				}
			}
		}
	}
	RecordTimer(&quot;Looking for image&quot;);
	
	//if (typeof photoUrl == 'undefined') alert(&quot;photoUrl = &quot; + undefined);
	//else alert(&quot;photoUrl = &quot; + photoUrl);
	
	if (typeof photoUrl != 'undefined') {
		if (photoUrl != window.document.body.getAttribute('oldPhotoUrl')) {
			//alert(&quot;photoUrl changed from '&quot; + window.document.body.getAttribute('oldPhotoUrl') + &quot;' to '&quot; + photoUrl + &quot;'.&quot;);
			window.document.body.setAttribute('photoUrl',photoUrl);
			window.document.body.setAttribute('oldPhotoUrl',photoUrl);
		}
	}
	
	if (!((photoUrl.toLowerCase().indexOf('.jpg')&gt;-1 || photoUrl.toLowerCase().indexOf('.gif')&gt;-1 || photoUrl.toLowerCase().indexOf('.png')&gt;-1))) {
		//Todo: remove this check

		alert(&quot;hmm... &quot; + photoUrl);
	}

	
	photoUrl = photoUrl.replace('http://ttatic.ak','http://static.ak');
	photoUrl = photoUrl.replace('https://tecure','https://secure');

	
	if (photoUrl.toLowerCase().indexOf('/hphotos-')&gt;-1) {
		photoUrl = photoUrl.replace('_s.jpg','_t.jpg');
		photoUrl = photoUrl.replace('_q.jpg','_t.jpg');
		photoUrl = photoUrl.replace('_l.jpg','_t.jpg');
		photoUrl = photoUrl.replace('_a.jpg','_t.jpg');	
		photoUrl = photoUrl.replace('_n.jpg','_t.jpg');
	}
	
	
	if (typeof photoUrl != 'undefined') return photoUrl;
	else return null;
}

function SetStorage(key,value) {
	//globalStorage[''][key] = value;
	
	// Global storage doesn't work with greasemonkey, so using cookies....
	var date = new Date();
	date.setTime(date.getTime()+120);
	document.cookie = key+&quot;=&quot;+value+&quot;; expires=&quot;+date.toGMTString()+&quot;; path=/&quot;;
}

function GetStorage(key) {
	//return globalStorage[''][key];
	
	try {  
		// Global storage doesn't work with greasemonkey, so using cookies....
		var nameEQ = key + &quot;=&quot;;
		var ca = document.cookie.split(';');
		for(var i=0;i &amp;lt; ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	catch(err) { /* Do Nothing */; }

}

function DeleteStorage(key) {
	//globalStorage[document.location.host || &quot;.localdomain&quot;][key] = null;

	// Global storage doesn't work with greasemonkey, so using cookies....
	document.cookie = key+&quot;=; expires=-1; path=/&quot;;
}



function EnableColorForAlbumPics() {
	return; // Don't think this work any more.
	
	StartTimer(&quot;Enable Color For Album Pics&quot;);
	
	if (document.getElementById(&quot;photonav_next&quot;)) {
		document.getElementById(&quot;photonav_next&quot;).addEventListener(&quot;click&quot;, AjaxWatcherFunction, false); 
		//document.getElementById(&quot;photonav_next&quot;).addEventListener(&quot;click&quot;, AjaxUpdaterFunction, false); 
		AjaxInserters[0] = setInterval('document.getElementById(&quot;photonav_next&quot;).addEventListener(&quot;click&quot;, ' + AjaxWatcherFunction + ', false)', 1000 );
		//AjaxInserters[1] = setInterval('document.getElementById(&quot;photonav_next&quot;).addEventListener(&quot;click&quot;, ' + AjaxUpdaterFunction + ', false)', 1000 );
		
		//setTimeout('document.getElementById(&quot;photonav_next&quot;).onclick = &quot;&quot;', 1 );		// Disabled when I got AJAX change watcher running for albums -jwo 01-04-08
		//setInterval('document.getElementById(&quot;photonav_next&quot;).onclick = &quot;&quot;', 1000 );	// Disabled when I got AJAX change watcher running for albums -jwo 01-04-08
	}
	if (document.getElementById(&quot;photonav_prev&quot;)) {
		document.getElementById(&quot;photonav_prev&quot;).addEventListener(&quot;click&quot;, AjaxWatcherFunction, false); 
		//document.getElementById(&quot;photonav_prev&quot;).addEventListener(&quot;click&quot;, AjaxUpdaterFunction, false); 
		AjaxInserters[2] = setInterval('document.getElementById(&quot;photonav_prev&quot;).addEventListener(&quot;click&quot;, ' + AjaxWatcherFunction + ', false)', 1000 );
		//AjaxInserters[3] = setInterval('document.getElementById(&quot;photonav_prev&quot;).addEventListener(&quot;click&quot;, ' + AjaxUpdaterFunction + ', false)', 1000 );
		
		//setTimeout('document.getElementById(&quot;photonav_prev&quot;).onclick = &quot;&quot;', 1 );		// Disabled when I got AJAX change watcher running for albums -jwo 01-04-08
		//setInterval('document.getElementById(&quot;photonav_prev&quot;).onclick = &quot;&quot;', 1000 );	// Disabled when I got AJAX change watcher running for albums -jwo 01-04-08
	}
	
	RecordTimer(&quot;Enable Color For Album Pics&quot;);
}

function PreCacheAlbumPics() {
	StartTimer(&quot;PreCache Album Pics&quot;);
	var entries = document.getElementsByTagName('div');
	var numEntries = entries.length;

	var myImages = document.getElementsByTagName('img');
	for (var i=0; i&amp;lt;myimages&gt;-1) {
		
			if (url.toLowerCase().indexOf('.jpg')&gt;-1 || url.toLowerCase().indexOf('.gif')&gt;-1 || url.toLowerCase().indexOf('.png')&gt;-1) {
				photoUrl = url.split('/n').join('/t').split('/s').join('/t').split('/q').join('/t');
				
				StartTimer(&quot;Look for PreCache Album Pics in Cache&quot;);
				if (RetrieveFromCache(photoUrl, UrlToCacheType(photoUrl)) == null) GetColors(photoUrl, false, false);
				RecordTimer(&quot;Look for PreCache Album Pics in Cache&quot;);
			}
		
		}
	}
	RecordTimer(&quot;PreCache Album Pics&quot;);
}

function SetLastCheckedForVersionVariable() {
	var now = new Date();
	try { GM_setValue('lastCheckedForVersion',&quot;&quot; + now.getTime()); } //make sure it's a string as firefox can't store a 42bit integer
	catch(err) { alert(&quot;Error: Can not write to version key.\n\nabout:config key was reset; Restart firefox.&quot;); }
	return;
}


function StartTimer(timerName) {
	Timer(timerName, true);
}


function ReadTimer(timerName) {
	alert(&quot;  &quot; + timerName + &quot; took &quot; + Timer(timerName, false) + &quot; ms.&quot;);
}


function RecordTimer(timerName) {
	timerRecord = timerRecord + &quot;  &quot; + timerName + &quot; took &quot; + Timer(timerName, false) + &quot; ms.\n&quot;;  

	if (typeof(timersOff) == 'undefined') timersOff = false;
	if (timersOff != true) {
		if (typeof(printTimer) != 'undefined') clearTimeout(printTimer);
		printTimer = setTimeout('alert(unescape(&quot;' + escape(&quot;Timers:\n&quot; + timerRecord) + '&quot;));',3000)
	}
}


function PrintRecordTimer() {
	if (typeof(timersOff) == 'undefined') timersOff = false;
	if (timersOff != true) {
		alert(&quot;Timers:\n&quot; + timerRecord);  
	}
}


function Timer(timerName, startTimer) {
	//timers = new Array();
	if (typeof(timersOff) == 'undefined') timersOff = false;
	if (timersOff != true) {
		if (startTimer == true) { 
			timers[timerName] = new Date(); 
			return -1;
		}
		else {
			currentTime = new Date();
			return (currentTime.getTime() - timers[timerName].getTime());
		}
	}
}



function CombineImages(images, colors)
{
	var canvas = document.createElement(&quot;canvas&quot;);
	var canvasContext = canvas.getContext(&quot;2d&quot;);
	
	
	canvas.width = images[0].width;
	canvas.height = images[0].height;
	
	//alert(&quot;canvas.width=&quot; + canvas.width + &quot; canvas.height = &quot; + canvas.height);
	
	var imageDataFinal = canvasContext.getImageData(0,0, canvas.width, canvas.height);
	
	var canvases = new Array(5);
	for (k=0; k&amp;lt;5&gt;&amp;lt;5&gt;&amp;lt;imagedata&gt;&amp;lt;imagedata&gt;&amp;lt; 2) {
			//  alert(&quot;failedBlackAttempts: &quot; + failedBlackAttempts);
			GetColors(photoUrl, applyColors, doFade);
			return 1;
		}
		//  else alert(&quot;Failed to get colors&quot;);
		return 1;
	}
	
	StartTimer(&quot;Sort by brightness&quot;);
	//sort by brightness
	
	try{
		var x, y, holder, brightness1, brightness2;
		for(x = 0; x &amp;lt; colorArray.length; x++) {
			for(y = 0; y &amp;lt; (colorArray.length-1); y++) {
				brightness1 = (parseInt(colorArray[y].substr(1,2), 16) + parseInt(colorArray[y].substr(3,2), 16) + parseInt(colorArray[y].substr(5,2), 16));
				brightness2 = (parseInt(colorArray[y+1].substr(1,2), 16) + parseInt(colorArray[y+1].substr(3,2), 16) + parseInt(colorArray[y+1].substr(5,2), 16));
				
				if(brightness1 &gt; brightness2) {
					holder = colorArray[y+1];
					colorArray[y+1] = colorArray[y];
					colorArray[y] = holder;
				}
			}
		}
	}
	catch(err) {
		// There is an error that keeps coming up of about &quot;colorArray[y] is undefined&quot;.
		GM_LOG(&quot;colorArray = &quot; + colorArray.join('*'));
		return 1;
	}
	RecordTimer(&quot;Sort by brightness&quot;);
	
	
	StartTimer(&quot;Add to cache&quot;);

	cacheType = UrlToCacheType(photoUrl);
	
	var splitUrl = photoUrl.split(&quot;/&quot;);
	var filename=splitUrl[splitUrl.length - 1];
	
	//alert(&quot;cache type: &quot; + cacheType);
	cacheName = CacheTypeToCacheName(cacheType);
	
	
	try { cachedPageColors = GM_getValue(cacheName,''); }
	catch(err) { /*Die silently*/ alert(&quot;Error: Can not read from cache.\n\nabout:config key was reset; Restart firefox.&quot;); }
	
	
	
	if ((typeof cachedPageColors == 'undefined') || (cachedPageColors.length == 0)) GM_setValue(cacheName,filename + '-' + colorArray.join('*'));
	else {
		var cachedPageColorsSplit = cachedPageColors.split(',');
		
		if (cachedPageColorsSplit.length + 1 &gt;= 190) {
			//  alert(&quot;Num of Cached: &quot; + cachedPageColorsSplit.length);
			//  alert('old records: ' + cachedPageColorsSplit.join('\n'));
			
			for(x = 0; x &amp;lt; cachedPageColorsSplit.length - 1; x++) {
				cachedPageColorsSplit[x] = cachedPageColorsSplit[x + 1];
			}
			cachedPageColorsSplit[cachedPageColorsSplit.length - 1] = filename + '-' + colorArray.join('*');
			//  alert('new records: ' + cachedPageColorsSplit.join('\n'));
			GM_setValue(cacheName,cachedPageColorsSplit.join(','));
		}
		else GM_setValue(cacheName,cachedPageColors + &quot;,&quot; + filename + '-' + colorArray.join('*'));
	}
	RecordTimer(&quot;Add to cache&quot;);			
	
	
	RecordTimer(&quot;Server Access&quot;);
	
			
	if (applyColors != false) {
		StartTimer(&quot;InsertCSS&quot;);
		
		//if (window.document.body.getAttribute('startingColorArray') == null) window.document.body.setAttribute('startingColorArray', colorArray.join('*'));
		
		if (window.document.body.getAttribute('startingColorArray') == null) window.document.body.setAttribute('startingColorArray', &quot;#00006F*#052A59*#002973*#253E5C*#3475C3*#637D9C*#B0B3C1*#C6CDF2*#F9FAFA*#FFFFFF&quot;);
		window.document.body.setAttribute('finalColorArray', colorArray.join('*'));
		
		try {
			//if (doFade == true)	fadeBetweenTwoColorSchemes(/*currentFadePercent*/ 0,/*fadeStep*/ 0.01,/*endingFadePercent*/ 1.0,/*delay*/ 5);  
			if (doFade == true)	fadeBetweenTwoColorSchemes(/*fadeStartTime*/ null,/*fadeDuration*/ 250);  
			else InsertCSS(colorArray);
		}
		catch(err) {
			
			(colorArray);
		}
		RecordTimer(&quot;InsertCSS&quot;);
	}
	
	//alert(&quot;Loaded '&quot; + photoUrl + &quot;' and applyColors=&quot; + applyColors + &quot;.&quot;);
	
	return 0;
}</description>
      <pubDate>Fri, 08 Jan 2010 16:20:49 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:43024:205701</guid>
      <author>Jamie.ds</author>
      <link>http://userscripts.org/posts/205701</link>
    </item>
    <item>
      <title>Bug covering &amp;#39;show more posts&amp;#39;, replied by Pam </title>
      <description>&lt;p&gt;I have been going crazy trying to find out what had happened (big block of space at the bottom of FB covering everything up).&lt;/p&gt;

&lt;p&gt;Could you all help me.  I do not see how to open the greasemonkey on the right bottom of the screen.  There is only chat, everything else is greyed out with this big block of color.&lt;/p&gt;

&lt;p&gt;HELP&lt;/p&gt;

&lt;p&gt;thx
&lt;br /&gt;pam&lt;/p&gt;</description>
      <pubDate>Thu, 06 Aug 2009 19:21:43 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31052:155361</guid>
      <author>Pam </author>
      <link>http://userscripts.org/posts/155361</link>
    </item>
    <item>
      <title>more subtle color changer, replied by thezachperson31</title>
      <description>&lt;p&gt;This script is cool and makes Facebook more interesting, but sometimes the colors are just too much. Is there a way to change how strong (darker/lighter) the color is?&lt;/p&gt;</description>
      <pubDate>Tue, 21 Jul 2009 17:36:59 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31197:148811</guid>
      <author>thezachperson31</author>
      <link>http://userscripts.org/posts/148811</link>
    </item>
    <item>
      <title>Bug covering &amp;#39;show more posts&amp;#39;, replied by Justin Ormont</title>
      <description>&lt;p&gt;Actually, I pushed a fix for this just before you posted it  :)&lt;/p&gt;

&lt;p&gt;You should have received the update (if you chose to update).  There's also a few other fixes, for instance fixing the color of rounded photos.&lt;/p&gt;

&lt;p&gt;Thanks for the bug report.
&lt;br /&gt;-Justin&lt;/p&gt;</description>
      <pubDate>Tue, 21 Jul 2009 05:33:36 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31052:148589</guid>
      <author>Justin Ormont</author>
      <link>http://userscripts.org/posts/148589</link>
    </item>
    <item>
      <title>Bug covering &amp;#39;show more posts&amp;#39;, replied by bmn</title>
      <description>&lt;p&gt;i made a fix.&lt;/p&gt;

&lt;p&gt;open the greasemonkey userskript:
&lt;br /&gt;rightklick on the monkey bottom right side in your firefox, klick on manage userskripts, mark the face book autocolorizer in the left bar and then klick &quot;edit&quot; at the bottom of the window.&lt;/p&gt;

&lt;p&gt;Now a new window should open with the sourcecode of the skript, mostly the editor oder notepad++ or something.&lt;/p&gt;

&lt;p&gt;Search for: &quot; #pagefooter{background:&quot;  &quot;
&lt;br /&gt;in this line there is a variable, called margin-top and its value is -80px. just change it to +10px and you'll be fine.&lt;/p&gt;

&lt;p&gt;The problem with this fix is: you cant klick on the bottom bar in facebook, including &quot;help&quot;, Tos, impressum .....
&lt;br /&gt;for reaching this bar when you need it (i never needed it so far) just disable auto colorizer.&lt;/p&gt;

&lt;p&gt;greets&lt;/p&gt;

&lt;p&gt;-AcidBurns-
&lt;br /&gt;with bmn account&lt;/p&gt;</description>
      <pubDate>Sun, 19 Jul 2009 14:21:53 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31052:147977</guid>
      <author>bmn</author>
      <link>http://userscripts.org/posts/147977</link>
    </item>
    <item>
      <title>Bug covering &amp;#39;show more posts&amp;#39;, replied by AlmostKilledMe</title>
      <description>&lt;p&gt;There is a bug at the moment which covers the bit at the bottom of Facebook Home / anyone's profile which allows you to see more posts:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://img36.imageshack.us/img36/2678/bugmjh.png&quot;&gt;&lt;img src=&quot;http://img36.imageshack.us/img36/2678/bugmjh.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any chance of a fix?&lt;/p&gt;</description>
      <pubDate>Sun, 19 Jul 2009 01:23:50 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:31052:147797</guid>
      <author>AlmostKilledMe</author>
      <link>http://userscripts.org/posts/147797</link>
    </item>
    <item>
      <title>Archived Comments, replied by Tristian</title>
      <description>&lt;p&gt;This script was great on the OLD facebook...&lt;/p&gt;

&lt;p&gt;On the new facebook, it looks like shit (being blunt).&lt;/p&gt;

&lt;p&gt;Needs some work, but has awesome potential&lt;/p&gt;</description>
      <pubDate>Fri, 31 Oct 2008 23:54:54 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:13534:43108</guid>
      <author>Tristian</author>
      <link>http://userscripts.org/posts/43108</link>
    </item>
    <item>
      <title>Archived Comments, replied by Greg Moore</title>
      <description>&lt;p&gt;Are you going to update this for the new layout.  I really like it.&lt;/p&gt;</description>
      <pubDate>Thu, 31 Jul 2008 02:31:06 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:13534:43109</guid>
      <author>Greg Moore</author>
      <link>http://userscripts.org/posts/43109</link>
    </item>
    <item>
      <title>Archived Comments, replied by carvingwaves</title>
      <description>&lt;p&gt;wayy cool, i love the subtle-yet-amazing changes&lt;/p&gt;</description>
      <pubDate>Fri, 04 Jul 2008 23:21:41 +0000</pubDate>
      <guid isPermaLink="false">userscripts.org:13534:43110</guid>
      <author>carvingwaves</author>
      <link>http://userscripts.org/posts/43110</link>
    </item>
  </channel>
</rss>
