//lenses.js

hex=255;

function wordshift() {
	if (navigator.appName!='Microsoft Internet Explorer') {
		var t = document.getSelection();
		od(t);
	}
	else {
		var t = document.selection.createRange();
		if(document.selection.type == 'Text' && t.text>'') {
			document.selection.empty();
			od(t.text);
		}
	}
	function od(t) {
		while (t.substr(t.length-1,1)==' ') 
			t=t.substr(0,t.length-1)
		while (t.substr(0,1)==' ') 
			t=t.substr(1)
		if (t) {
			clearHighlight();
			fadetextOut();
			hex=255; 
			pauseComp(1000);
			window.location = 'index.php?aperture='+t;
		}
	}
}


function pauseComp(millis)
{
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); }
	while(curDate-date < millis);
}


function clearHighlight() {
    if (document.selection) {document.selection.empty();}
    else if (window.getSelection()) {
        body = document.getElementsByTagName("body")[0];
        window.getSelection().collapse(body,0);
        if(window.getSelection().removeAllRanges){
            window.getSelection().removeAllRanges();
            }
        }
    else if (document.getSelection()) {document.getSelection().collapse();}
}


function fadetext(){ 
	if(hex>0) {
		hex-=15;
		document.getElementById("fade0").style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadetext()",5); 
	}
}


function fadetextOut(){ 
	if(hex<255) {
		hex+=15;
		document.getElementById("fade0").style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadetextOut()",5); 
	}
}