function $(id) {
	return document.getElementById(id);
}

var projectViewer = new function() {
	this.items = false;
	this.current = -1;
	
	this.swap = function() {
		var handle, nodes, from, to;
		if (handle = $('pv_container')) {
			if ((nodes = handle.childNodes.length) > 1) {
				from = this.current + 1;
				this.current = from = from >= nodes ? from - nodes : from;
				to = from + 1 >= nodes ? from - nodes + 1 : from + 1;
				this.animate(handle, from, to, 0);
				setTimeout(function() {projectViewer.swap();}, 10000);
			}
		}
	}
	
	this.animate = function(handle, from, to, pos) {
		var dx = Math.round(Math.sin(Math.PI * (pos / 200)) * 200);
		if (!handle) handle = $('pv_container');
		handle.childNodes[from].style.left = (0 - dx) + 'px';
		handle.childNodes[to].style.left = (200 - dx) + 'px';
		if (pos < 100) setTimeout(function() {projectViewer.animate(handle, from, to, pos + 2)}, 10);
	}
	
	this.init = function() {
		var handle, i, item, temp = '';
		if (handle = $('pv_container')) {
			for (i = 0; item = handle.childNodes[i]; i++) {
				if (item.className != 'pv_block') handle.removeChild(handle.childNodes[i--]);
			}
			if (this.items) {
				for (i = 1; item = this.items[i]; i++) {
					temp += '<div class="pv_block" style="left: 200px;">' +
							'<div class="pv_title">' + item[0] + '</div>' +
							'<a' + (item[3] ? 'href="' + item[2] + '"' : '') + ' class="pv_img"' +
							' style="background-image: url(files/images/pages/' + item[1] + ')"></a>' +
							'</div>';
				}
				handle.innerHTML += temp;
			}
			setTimeout(function() {projectViewer.swap();}, 10000);
		}
		else {
			setTimeout(function() {projectViewer.init();}, 100);
		}
	}
}



var whois = new function() {
	
	this.request = function(domain, tld) {
		var request, status = {'vrij':'Vrij','bezet':'Bezet','onbekend':'Onbekend'};
		try {request = new XMLHttpRequest();}
		catch (e) {
			try {request = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {request = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (e) {return false;}
			}
		}
		request.onreadystatechange = function() {
			if (request.readyState == 4) {
				var handle, temp, data = request.responseText.split(', ');
				if (data[0] == 'Whois Result') {
					if (handle = $('whois_' + data[1])) {
						handle.firstChild.appendChild(document.createTextNode(status[data[2]]));
						handle.className = 'whois_item whois_status_' + data[2];
						handle.style.display = 'block';
					}
				}
			}
		}
		request.open("GET", "check_domain.php?domain=" + domain + '&tld=' + tld, true);
		request.send(null);
	}
	
	this.check = function() {
		var i, tld,	buffer = '', domain, 
			tlds = Array('nl','com','org','info','be','biz','eu','net','us','nu','cc','tv','name','me');
		
		if ((domain = $('whois_input').value) != '') {
			for (i = 0; tld = tlds[i]; i++) {
				buffer += '<div class="whois_item" id="whois_' + domain + '_' + tld + '"><div></div>' + domain + '.' + tld + '</div>';
				this.request(domain, tld);
			}
		}
		$('whois_block').innerHTML = buffer;
	}
}

function writeE(name) {
	var e = name + '+blizaga.nl';
	document.write('<a href="mailto:' + e.replace('+', '@') + '">' + e.replace('+', '@') + '</a>');
}

setTimeout(function() {projectViewer.init();}, 100);
