// ==UserScript==
// @name           AlwaysFlash
// @namespace      AtmosphereIC
// @description    Flash Card roller
// @include        http://*
// ==/UserScript==

function FlashDeck(h){this._init(h);}

FlashDeck.prototype={
	// set of cards
	dictionary: new Array(
	/* ENTER DICTIONARY HERE */
	),

	// display a card at random
	show:function(){
		sI=Math.floor(Math.random()*2);hI=sI>0?0:1;
		card=this.dictionary[ Math.floor(Math.random() * this.dictionary.length) ].split("\t");
		$('flashcard').innerHTML='<a class="show">' + card[sI] + '<br />	<span class="hide">' + card[hI] + '</span></a>';
	},
	
	// inject styles
	styleNode: function(styles)
	{
		var se = E('style');
		se.type='text/css';
		se.innerHTML=styles;
		return se;
	},
	
	// styling the flashcards
	style:"\n\
	#flashcard\n\
	{\n\
		position:fixed;right:40px;top:40px;\n\
		z-index:1000;background:#222;\n\
		max-width:360px;\n\
		color:#fff;text-align:center;padding:10px;\n\
	}\n\
	#flashcard *{line-height:36px;font-size:32px;}\n\
	#flashcard a{color:white;}\n\
	#flashcard a.show span.hide{display:block;visibility:hidden;font-size:0.7em;}\n\
	#flashcard a.show:hover span.hide{display:block;visibility:visible;}\n",
	
	// listeners
	listeners:null,
	
	// generic listener for clicking on a card
	click:function(e,f){return function(){f(e);}; },
	
	// constructor
	_init:function(handler){
		bod=T('body')[0];
		bod.appendChild(
			_p(_p(E('style'),'type','text/css'),'innerHTML',this.style)
		);
		bod.appendChild(
			_p(E('div'),'id','flashcard')
		);
		card=$('flashcard');
		card.addEventListener("click", this.click( card , handler ), false);
		this.show();
	}
};

// create instance on event
window.addEventListener(
	"load", 
	function(){ new FlashDeck(function(e){e.style.display="none";}); }, 
	false
);

/*
	SOME UTILITY FUNCTIONS
*/
// short for get by ID
function $(e){return document.getElementById(e);}
// short for get by tag
function T(t){return document.getElementsByTagName(t);}
// short for create element
function E(n){return document.createElement(n);}
// short for modifying property of element
function _p(E,P,V){ E[P]=V; return E; }
// short for modifying style property of element
function _sy(E,S,V){ E.style[S]=V; return E; }
