// ==UserScript==
// @name           LiveJournal Pin Flagged Inbox Messages
// @namespace      http://afunamatata.com/greasemonkey/
// @description    Pin flagged messages to your LJ inbox to prevent them from being selected by the "select all" checkbox. Messages may still be selected manually.
// @include        http://www.livejournal.com/inbox/*
// @tags           livejournal
// ==/UserScript==

function getCheckbox(ele) 
{	
  return ele.parentNode.parentNode.parentNode.parentNode.childNodes[1].firstChild;
}

function toggleLock()
{    
  var checkbox = getCheckbox(this);
  checkbox.disabled = !checkbox.disabled;
};

// label the checkall checkbox to reflect the change in behavior
var checkall = document.getElementById("InboxItem_CheckAll");
if(checkall != null)
	checkall.title = "Select all unpinned";

// get the relevant bookmarks
bookmarks = document.evaluate("//img[@class='InboxItem_Bookmark']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

// attach listeners
for(i = 0; i < bookmarks.snapshotLength; i++)
{
  var bookmark = bookmarks.snapshotItem(i);
	bookmark.addEventListener("click", toggleLock, false);	

	if(bookmark.src.indexOf("img/flag_on.gif")!=-1)
	  getCheckbox(bookmark).disabled = true;
}
