(function() {

	var els = [
		document.getElementById('blur2'),
		document.getElementById('blur3'),
		document.getElementById('blur4')
	];
	
	function setBlur(n) {
		function setEl(e, b) {
			if (b <= 0 || b > 2) {
				e.style.display = 'none';
			} else {
				e.style.display = '';
				e.style.opacity = b;
				e.style.filter = 'alpha(opacity=' + Math.round(Math.min(1, b) * 100) + ')';
			}
		}
		setEl (els[0], n * 3);
		setEl (els[1], n * 3 - 1);
		setEl (els[2], n * 3 - 2);
	}
	
	var preload = new Image();
	preload.onload = function() {
		setTimeout (function() {
			var i = 1;
			var interval = setInterval(function() {
				i -= 0.06;
				if (i <= 0) {
					i = 0;
					clearInterval(interval);
				}
				setBlur (1 - Math.pow(1 - i, 2));
			}, 50);
		}, 10);
	};
	preload.src = 'im/set.jpg';

})();

// http://en.wikipedia.org/wiki/XMLHttpRequest
if (typeof XMLHttpRequest == "undefined")
	XMLHttpRequest = function () {
		try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
			catch (e) {}
		try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
			catch (e) {}
		try { return new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e) {}
		throw new Error("This browser does not support XMLHttpRequest.");
	};

(function() {

	var el = document.getElementById('dj');
	var ul = document.getElementById('lookup-ul');
	var li = document.createElement('li');
	var state = 0;
	var list = [];
	var acs = [];
	var focus = 1;
	
	li.className = 'autocomplete-li-hide';
	ul.appendChild (li);
	
	function gotList(a) {
		var i;
		if ((i = a.indexOf('"')) > -1) {
			a = a.substr(i + 1);
			if ((i = a.indexOf('"')) > -1) {
				a = a.substr(0, i);
				list = a.split('\'');
				showPopup ();
			}
		}
	}
	
	var lastCreated;
	function AutoCompleteItem(text) {
		this.el = document.createElement('div');
		this.el.className = 'autocomplete-div';
		this.text = document.createTextNode('...');
		this.el.appendChild (this.text);
		li.appendChild (this.el);
	}
	AutoCompleteItem.prototype = {
		showData: function(name) {
			this.text.data = name;
			this.el.style.display = 'block';
		},
		hide: function() {
			this.el.style.display = 'none';
		}
	};
	
	function showPopup() {
		var text = el.value.toUpperCase();
		var matches = [];
		if (focus && text != '') {
			for (var i = 0; i < list.length; i ++) {
				if (list[i].substr(0, text.length).toUpperCase() == text) {
					matches.push (list[i]);
					if (matches.length >= 8) {
						break;
					}
				}
			}
		}
		li.className = 'autocomplete-li-' + (matches.length > 0 ? 'show' : 'hide');
		for (var i = 0; i < matches.length; i ++) {
			if (!acs[i]) {
				acs[i] = new AutoCompleteItem(matches[i]);
			}
			acs[i].showData (matches[i]);
		}
		for (; i < acs.length; i ++) {
			acs[i].hide ();
		}
	}
	
	var timer;
	el.onkeyup = el.onkeydown = el.onkeypress = el.onmouseup = function() {
		clearTimeout(timer);
		timer = setTimeout(function() {
			showPopup ();
		}, 1);
	};
	el.onblur = function() {
		focus = 0;
		showPopup ();
	};
	el.onfocus = function() {
		focus = 1;
		if (!state) {
			state = 1;
			var xh = new XMLHttpRequest();
			xh.open ('GET', '/alldj.php', true);
			xh.onreadystatechange = function() {
				if (xh.readyState == 4) {
					gotList (xh.responseText);
				}
			};
			xh.send ('');
		}
		showPopup ();
	};
	el.setAttribute ('autocomplete', 'off');
	
})();

function setPNG24(img) {
	img.className = img.className.replace(/png24/, 'fixedPng');
	img.src = 'blank.gif';
}


