// JavaScript Document

var fader;
function openFeatured(e) {
	obj = document.getElementById("featuredopen");
	
	if (obj.style.display != "block") {
		obj.style.display = "block";
		obj.style.opacity = 0;
			
		clearTimeout(fader);	
		if (obj.style.filter) {
			fader = setInterval("currentAlpha = parseInt(obj.style.filter.split('=')[1].split(')')[0]); if (currentAlpha < 100) {obj.style.filter = \"alpha(opacity=\"+(currentAlpha+10)+\")\"} else {clearInterval(fader);}",10);
		} else if (obj.style.opacity) {
			fader = setInterval("currentAlpha = parseFloat(obj.style.opacity); if (currentAlpha < .99) { obj.style.opacity = currentAlpha+.11; } else { clearInterval(fader); } ",10);
		} 
	}
}

function closeFeatured(e) {
	if (e.relatedTarget) { relTarget = e.relatedTarget; }
	else if (e.toElement) { relTarget = e.toElement; }

	found = false;
	temp = relTarget;
	while (temp != document.documentElement) {
		temp = temp.parentNode;
		if (temp.id == "featured") {
			found = true;
			break;	
		}
	}
	if (found != true) {
		obj = document.getElementById("featuredopen");
		
		clearTimeout(fader);
		if (obj.style.filter) {
			fader = setInterval("currentAlpha = parseInt(obj.style.filter.split('=')[1].split(')')[0]); if (currentAlpha > 0) {obj.style.filter = \"alpha(opacity=\"+(currentAlpha-10)+\")\"} else {clearInterval(fader);obj.style.display = \"none\";}",10);
		} else if (obj.style.opacity) {
			fader = setInterval("currentAlpha = parseFloat(obj.style.opacity); if (currentAlpha > 0) { obj.style.opacity = currentAlpha-.11; } else { clearInterval(fader); obj.style.display = \"none\"; } ",10);
		} else {
			obj.style.display = "none";
		}
	}
			
}

function gotoURL(url) {
	window.location = url;
}

function highlight(which) {
	which.className = "highlight";
}

function unhighlight(which) {
	which.className = "unhighlight";
}


function prev() {
	if(projectFoundAt + offset + beginoffset > 0 && mousedown) {
		if (ul.childNodes.length >= 6) {
			ul.removeChild(ul.lastChild);
		}
		offset--;
		ul.insertBefore(createli(projectFoundAt+offset+beginoffset), ul.firstChild);
		buttonhighlight(document.getElementById('fpmback'));
		buttonunhighlight(document.getElementById('fpmnext'));
		timer = setTimeout("prev()", 300);
	}
}

function next() {
	// alert(projectFoundAt+","+offset+","+beginoffset+","+ul.childNodes.length+","+projects.length);
	if(projectFoundAt + offset + beginoffset + ul.childNodes.length < projects.length && mousedown) {
		if (ul.childNodes.length >= 6) {
			ul.removeChild(ul.firstChild);
		}
		offset++;
		ul.appendChild(createli(projectFoundAt+offset+beginoffset+ul.childNodes.length));
		buttonhighlight(document.getElementById('fpmnext'));
		buttonunhighlight(document.getElementById('fpmback'));
		timer = setTimeout("next()", 300);
	}
}

function doubleclickthis() {
// handle doubleclicks in IE
	this.onmousedown();
	this.onmouseup();
}

function doit(it) {
	mousedown = true;
	if (it == 'prev') {	prev();
	} else { next(); }
}

function stopmove() {
	mousedown = false;
	clearTimeout(timer);
}

function buttonhighlight(i) {
	// highlight and check for grayed
	if (i.id == "fpmnext" && projectFoundAt + offset + beginoffset + ul.childNodes.length >= projects.length || (i.id == "fpmnext" && projects.length == 0)) {
		i.className = "fpmnextgray";
	} else if (i.id == "fpmnext") {
		i.className = "fpmnexthighlight";
	} else if (i.id == "fpmback" && projectFoundAt + offset + beginoffset <= 0 || (i.id == "fpmback" && projects.length == 0)) {
		i.className = "fpmbackgray";
	} else if (i.id == "fpmback") {
		i.className = "fpmbackhighlight";
	}
}

function buttonunhighlight(i) {
	// unhighlight, check for grayed
	if (i.id == "fpmnext" && projectFoundAt + offset + beginoffset + ul.childNodes.length >= projects.length || (i.id == "fpmnext" && projects.length == 0)) {
		i.className = "fpmnextgray";
	} else if (i.id == "fpmnext") {
		 i.className = "fpmnext"; 
	} else if (i.id == "fpmback" && projectFoundAt + offset + beginoffset <= 0 || (i.id == "fpmback" && projects.length == 0)) {
		i.className = "fpmbackgray";
	} else if (i.id == "fpmback") {
		 i.className = "fpmback"; 
	}
}

function createMenu(start) {
	for (i=start; i<=start+5; i++) {
		if (i >= 0 && i <= projects.length-1) {
			ul.appendChild(createli(i));
		}
	}
	buttonunhighlight(document.getElementById('fpmback'));
	buttonunhighlight(document.getElementById('fpmnext'));
	document.body.onmouseup = stopmove;
}
