/*
	##########################
	DISABLE TEXT SELECTION JAVASCRIPT
	##########################
	
	Disables selection of text with a mouse on a page
	
	Usage:
	<script type="text/javascript" language="javascript" src="http://lab.bandit.co.nz/scripts/disableselect/bandit-disable-select.js"></script>
	
	##########################
	BY JAMES <at> BANDIT.CO.NZ
	##########################
	
	addLoadEvent by www.simonwillison.net
*/

// THOU! SHALT! NOT! PASS!
function bd_disable_select(e) {
	el.select(); // as simple as this
	if(document.all) scrollTo(0,0); // but IE will jump to the bottom of the page... ~_~
	if(md) document.onmouseup = function() { bd_disable_select(); md = false; captain_hook(); return true; } // is the mouse still down? disable on mouseup too then!
}

// hook the mouse events
function captain_hook() {
	document.onmousedown = function() { t = setTimeout("bd_disable_select();",250); md = true; return true; } // disable selection after 250 msecs
	document.onmouseup = function() { clearTimeout(t); md = false; return true; } // wait they clicked a button/link!
}

// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) { oldonload(); }
			func();
		}
	}
}

// do it
var el,t; var md = false;
addLoadEvent(function() {
	if(document.onselectstart) { document.onselectstart = function () { return false; } } // old ie
	else {
		// create the text box
		el = document.createElement("input");
		el.setAttribute("type","text");
		
		// must have a value for it to work in WebKit
		el.setAttribute("value","Bandit Design's Disable Text Selection: http://lab.bandit.co.nz/scripts/disableselect/");
		
		// hide it
		el.setAttribute("style","position: absolute; left: -9999px; "); // this doesn't work in ie ~_~
		el.style.position = "absolute"; el.style.left = "-9999px";
		
		// whack it in there
		document.body.appendChild(el); // append fake selection box
		
		// hook
		captain_hook();
	}
});