// ==UserScript==
// @name          Collapse_Realtime
// @namespace     http://qaa.ath.cx/
// @description   Hide that damn bar
// @include       http://www.youtube.com/*
// ==UserScript==

window.addEventListener('load', function() { initMachine(); }, false );

var hide = GM_getValue("yt_bar");
function initMachine() {
	function reflectState() {
		toHide.innerHTML = hide ? '&#9664;' : '&#9654;';
		toolbar.style.width = hide ? '100%' : '1em';
	}

	var 	toHide = document.createElement('div'),
		toolbar = document.getElementById("toolbar");
	if(toolbar != null)  {
		// take this Mr Crockford...
		with (toHide.style) {
			position = "absolute";
			left = "0px";
			top = "2px";
			color = "#555";
			cursor = "pointer";
		}
		
		toolbar.appendChild(toHide);

		toHide.addEventListener("click", function() {
			hide = !hide;
			GM_setValue("yt_bar", hide);	
			reflectState();
		}, true);

		reflectState();
	}
}
