function absTop(el) {
        return (el.offsetParent)?  el.offsetTop+absTop(el.offsetParent) : el.offsetTop;
}

function absLeft(el) {
        return (el.offsetParent)?  el.offsetLeft+absLeft(el.offsetParent) : el.offsetLeft;
}

function screenHeight(win) { 
	if (win == undefined) win = window; 
	if (win.innerHeight) { 
		return win.innerHeight; 
	} 
	else { 
		if (win.document.documentElement 
			&& win.document.documentElement.clientHeight) { 
			return win.document.documentElement.clientHeight; 
		} 
		return win.document.body.offsetHeight; 
	} 
}

/*function screenHeight() { // TODO prove other browsers
	if(!window.innerHeight) {
		myheight = document.body.clientHeight;
	} else {
		myheight = window.innerHeight;
	}
	return myheight;
}*/

function footerPosition() {
	currentPosition = absTop(document.getElementById("footer"))+document.getElementById("footer").offsetHeight;

	if (screenHeight() > currentPosition) {
		document.getElementById("footer").style.position = "absolute";
		document.getElementById("footer").style.left = "0px";
	}
}

lastImage = "img1";

function showImage(imageUrl) {
	if (lastImage == "img1") {
		lastImage = "img2";
	} else {
		lastImage = "img1";
	}

	document.getElementById("project_picture_show_"+lastImage).src = imageUrl;

	fadeImage(0);
}

function fadeImage(picalpha) {
	picalpha += 10;

	newLastImage = "";
	if (lastImage == "img1") {
		newLastImage = "img2";
	} else {
		newLastImage = "img1";
	}

	document.getElementById("project_"+newLastImage).style.opacity = (100-picalpha)/100;
	document.getElementById("project_"+newLastImage).style.filter = 'alpha(opacity=' + (100-picalpha) + ')';

	document.getElementById("project_"+lastImage).style.opacity = picalpha/100;
	document.getElementById("project_"+lastImage).style.filter = 'alpha(opacity=' + picalpha + ')';

	if (picalpha < 100) {
		window.setTimeout("fadeImage("+(picalpha+20)+");", 100);
	}
}

crPos = 0;
currentMoving = 0;
timeoutBreaker = 0;

function scrLeft() {
        currentMoving = 1;
        completeWidth = document.getElementById("project_picture_scroll").offsetWidth;
        crPos += 3;

        if (timeoutBreaker != currentMoving) {
                return;
        }

	if (crPos > 0) {
		crPos = 0;
		document.getElementById("project_picture_left").className = "";
	}

	document.getElementById('project_picture_scroll').style.marginLeft = crPos+"px";
        if (crPos <= 0) {
		document.getElementById("project_picture_right").className = "displayArrow";
                window.setTimeout("scrLeft();",30);
        }
}

function scrollRight() {
        currentMoving = 1;
        completeWidth = document.getElementById("project_picture_scroll").offsetWidth;
        crPos -= 3;

        if (timeoutBreaker != currentMoving) {
                return;
        }

        if (completeWidth-927 >= (crPos*(-1))) {
		document.getElementById("project_picture_left").className = "displayArrow";
                document.getElementById('project_picture_scroll').style.marginLeft = crPos+"px";
                window.setTimeout("scrollRight();",30);
        } else {
		document.getElementById("project_picture_right").className = "";
	}
}

function onloadevent() {
	footerPosition();

	if (document.getElementById("project_picture_right") != null) {
	        completeWidth = document.getElementById("project_picture_scroll").offsetWidth;
	        if (completeWidth-927 >= 0) {
			document.getElementById("project_picture_right").className = "displayArrow";
		}
	}
}

