
var openHeight = 300;
var openTHeight = 59;

function startOpenSequence(projects)
{
	openForSequence(projects, 0);
}

function startCloseSequence(projects)
{
	closeForSequence(projects, 0);
}

function openForSequence(projects, curr)
{
	if (curr < projects.length)
	{
		startOpenProject(projects[curr]);
		curr++;
		setTimeout("openForSequence(new Array("+projects.join(",")+"), "+curr+")", 100);
	}
}

function closeForSequence(projects, curr)
{
	if (curr < projects.length)
	{
		startCloseProject(projects[curr]);
		curr++;
		setTimeout("closeForSequence(new Array("+projects.join(",")+"), "+curr+")", 100);
	}
}

function startToggleProject(project_id)
{
	if (document.getElementById("project_"+project_id).style.display!="block")
	{
		openMore(project_id, 0, 0);
	}
	else
	{
		closeMore(project_id, openHeight, openTHeight);
	}
}

function startOpenProject(project_id)
{
	if (document.getElementById("project_"+project_id).style.display!="block")
	{
		openMore(project_id, 0, 0);
	}
}

function startCloseProject(project_id)
{
	if (!document.getElementById("project_"+project_id).style.display!="block")
	{
		closeMore(project_id, openHeight, openTHeight);
	}
}

function openMore(nowopening, currheight, currTheight)
{	
	currheight = currheight + (openHeight-currheight)/4;
	currTheight = currTheight + (openTHeight - currTheight)/1.8;
	document.getElementById("project_"+nowopening).style.height=currheight;
	document.getElementById("overlay_"+nowopening).style.height=currTheight;
	if (currheight>1)
		document.getElementById("project_"+nowopening).style.display = "block";
	if (currTheight>1)
		document.getElementById("overlay_"+nowopening).style.display = "block";
	if (currheight>openHeight-1)
	{
		document.getElementById("project_"+nowopening).style.height=openHeight;
		document.getElementById("overlay_"+nowopening).style.height=openTHeight;
		opened = nowopening;
		nowopening = -1;
		currheight = 0;
	}
	else
		setTimeout("openMore("+nowopening+", "+currheight+", "+currTheight+")",50);
	
}

function closeMore(nowopening, currheight, currTheight)
{
	currheight = currheight - currheight/4;
	currTheight = currTheight - currTheight/1.8;
	document.getElementById("project_"+nowopening).style.height=currheight;
	document.getElementById("overlay_"+nowopening).style.height=currTheight;
	if (currheight<=1)
		document.getElementById("project_"+nowopening).style.display = "none";
	if (currTheight<=1)
		document.getElementById("overlay_"+nowopening).style.display = "none";
	if (currheight<1)
	{
		document.getElementById("project_"+nowopening).style.height=0;
		document.getElementById("overlay_"+nowopening).style.height=0;
		opened = -1;
		nowopening = -1;
		currheight = 0;
	}
	else
		setTimeout("closeMore("+nowopening+", "+currheight+", "+currTheight+")",50);
	
}

function loadContents(id, project_id, page_nr)
{
	document.getElementById(id).className = "detailcontentpage";
	document.getElementById(id).innerHTML = "";
	document.getElementById("loading_"+project_id).style.display = "block";
	ajaxRequest = new XMLHttpRequest();
	
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if (page_nr>0)
				document.getElementById(id).className = "detailcontentpage";
			else
				document.getElementById(id).className = "detailcontent";
			document.getElementById(id).innerHTML = ajaxRequest.responseText;
			document.getElementById("loading_"+project_id).style.display = "none";
		}
	}
	
	ajaxRequest.open("GET", "contentloader.php?project_id="+project_id+"&page_nr="+page_nr, true);
	ajaxRequest.send(null);
	
	
}

function openVideo(type, link)
{
	if (type==0)
		window.open("showvideo.php?youtube="+link, "videoPlayer","width=425, height=355");
	if (type==1)
		window.open("showvideo.php?file="+link, "videoPlayer","width=470, height=352");
	if (type==2)
		window.open("showvideo.php?vimeo="+link, "videoPlayer","width=400, height=300");
}

function bounce(id, curr, from, to, direction)
{
	var sav = curr;
	if (direction == 0)
	{
		curr += (curr-from+10)/3;
	}
	else
	{
		curr += (from-curr)/4; 
	}
	
	if (curr > (to-1))
	{
		curr = to;
		direction = 1;
	}
	if (curr < (from+1))
	{
		curr = from;
		direction = 0;
	}
	
	
	document.getElementById(id).style.left = curr;
	
	window.setTimeout("bounce('"+id+"', "+curr+", "+from+", "+to+", "+direction+")", 50);
	
}

function openFlipFlap(id, progress)
{
	return;
	if (progress < 1);
		progress += 0.05;
		
	document.getElementById(id).style.width = 70*progress;
	document.getElementById(id).style.height = 18*progress;
	
	if (progress < 1)
		window.setTimeout("openFlipFlap('"+id+"', "+progress+")", 10);
}

function closeFlipFlap(id, progress)
{
	return;
	if (progress > 0);
		progress -= 0.05;
		
	document.getElementById(id).style.width = 70*progress;
	document.getElementById(id).style.height = 18*progress;
	
	if (progress > 0)
		window.setTimeout("closeFlipFlap('"+id+"', "+progress+")", 10);
}


