// ==UserScript==
// @name            Basecamp Comment Controls
// @namespace       http://leftjustified.net/journal/2005/05/27/basecamp-greasemonkey-comment-controls/
// @description     Version 0.1 :: Allows user to 'dock' comment form in top right of screen. Adds textarea sizing controls and stores preferred height of textarea
// @include         http://*.seework.com/*
// @include         http://*.grouphub.com/*
// @include         http://*.projectpath.com/*
// @include         http://*.updatelog.com/*
// @include         http://*.clientsection.com/*
// ==/UserScript==

// Version 0.1rc  2005-05-26
// Script copyright (c) 2005, Andrew Krespanis
// Install instructions and 'addGlobalStyle' function (c) Mark Pilgram
// Inspired by
//   --> http://www.snook.ca/archives/000368.html
//   --> http://www.boxofchocolates.ca/archives/2005/05/23/dockable-comments-intelligent-dom-scripting
//   --> http://diveintogreasmonkey.org/
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey 0.3 or later: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Zoom Textarea", and click Uninstall.
//
// --------------------------------------------------------------------

if (document.getElementById && document.getElementById('YourComment')) {
	var css ='body div#YourComment { padding:0 2%; margin-top:.4em; background:#F9F9F9;} ';
	css += ' body div#YourComment textarea {font:1em/1.4 "Lucida Grande", verdana, arial, helvetica, sans-serif; margin:.5em auto; background:#fff; border:2px inset #ccc;} ';
	css += ' body div#YourComment.docked { position:fixed; top:36px; right:.5%; width:34%; border:1px solid #ccc; padding:0 1% 0}';
	css += ' a#docker { font-weight:bold; font-size:90%; width:6em; line-height:1.7; float:right; text-align:center;} ';
	css += ' #bcCommControls { background:#fff; line-height:1.6; border:1px solid #aaa; padding:2px; margin-top:2px;}';
	css += ' #YourComment.docked  #bcCommControls {border-width:0 1px 1px; margin-top:0;}';
	css += '#YourComment a[name] { display:none;}';
	
	function dock() {
		if (commentBox.className == 'docked') {
			commentBox.className = '';
			linkText.nodeValue = 'Dock';
			link.href="#comment_form"
		} else {
			commentBox.className = 'docked';
			linkText.nodeValue = 'Undock';
			link.href='#';
		}
	}
	
	function textSize(direction) {
		if(direction == 'up') {
			commentBody.rows += 5;
		} else {
			commentBody.rows -= 5;
		}
		GM_setValue('bcCommRows', commentBody.rows);
		return false;
	}
	function addGlobalStyle(css) {
		var head, style;
		head = document.getElementsByTagName('head')[0];
		if (!head) { return; }
		style = document.createElement('style');
		style.type = 'text/css';
		style.innerHTML = css;
		head.appendChild(style);
	}
	
	
	commentBox = document.getElementById('YourComment');
	commentForm = commentBox.getElementsByTagName('form')[0];
	commentBody = document.getElementById('commentBody');
	
	commentBody.style.width = '96%';
	link = document.createElement('a');
	linkText = link.appendChild(document.createTextNode('Dock'));
	link.addEventListener("click", dock, false);
	link.href='#';
	link.setAttribute('id' , 'docker');
	
	var textPlus = document.createElement('a');
	textPlus.href="#comment_form";
	textPlus.style.fontSize = '76%';
	textPlus.addEventListener("click", function() {textSize('up') }, false);
	textPlus.appendChild(document.createTextNode('Increase Size'));
	var textMinus = document.createElement('a');
	textMinus.href="#comment_form";
	textMinus.style.fontSize = '76%';
	textMinus.addEventListener("click", function() {textSize('down') }, false);
	textMinus.appendChild(document.createTextNode('Decrease Size'));
	
	var controlHolder = document.createElement('div');
	controlHolder.setAttribute('id', 'bcCommControls');
	controlHolder.appendChild(link);
	controlHolder.appendChild(textPlus);
	controlHolder.appendChild(document.createTextNode(' | '));
	controlHolder.appendChild(textMinus);
	commentBox.insertBefore(controlHolder, commentForm);
	
	addGlobalStyle(css);
	
	if ( GM_getValue('bcCommRows')) {
	 commentBody.rows = GM_getValue('bcCommRows');
	}
}
