var rootFolder = "/";
var dirSpeed = 5;
var moveDir = 0;
var containerId = "";
var initPosition = 0;
var limitX = -950;
var moveInterval = 0;

function initProjectsMove(dir){
	moveDir = parseInt(dir);
	moveInterval = setInterval(moveProjects,40);
}

function stopProjectsMove(){
	clearInterval(moveInterval);
}

function moveProjects(){
	var projectContainer = document.getElementById(containerId);
	document.getElementById("debuger").innerHTML = initPosition+" / "+moveDir+"<br>"+Math.floor(Math.random()*20);
	initPosition += moveDir;
	if (initPosition < limitX) 
	{
		initPosition = limitX;
		document.getElementById("moveRight").style.display = "none";
		stopProjectsMove();
	} 
	else if(initPosition > 0)
	{
		initPosition = 0;
		document.getElementById("moveLeft").style.display = "none";
		stopProjectsMove();
	}
	projectContainer.style.left = initPosition+"px";
	if (initPosition < 0)
	{
		document.getElementById("moveLeft").style.display = "block";
	} 
	if (initPosition > limitX)
	{
		document.getElementById("moveRight").style.display = "block";
	}
}


function initProjectList() { 
	if (document.getElementById("listProjects"))
	{
		containerId = "listProjects";
		var container = document.getElementById("container");
		var projectContainer = document.getElementById("listProjects");
		if (parseInt(projectContainer.style.width) > 950)
		{		
			limitX = 950-parseInt(projectContainer.style.width);
			var arrLeft = document.createElement("div");
			arrLeft.setAttribute('id','moveLeft');
			arrLeft.className = "arrow";
			arrLeft.style.left = 0;
			arrLeft.style.display = "none";
			arrLeft.innerHTML = '<a href="#" onmouseover="initProjectsMove('+dirSpeed+');" onmouseout="stopProjectsMove();"><img src="'+rootFolder+'i/arr_left.gif" width="20" height="150" /></a>';
			container.appendChild(arrLeft);
			var arrRight = document.createElement("div");
			arrRight.setAttribute('id','moveRight');
			arrRight.className = "arrow";
			arrRight.style.left = "930px";		
			arrRight.innerHTML = '<a href="#" onmouseover="initProjectsMove('+(0-dirSpeed)+');" onmouseout="stopProjectsMove();"><img src="'+rootFolder+'i/arr_right.gif" width="20" height="150" /></a>';
			container.appendChild(arrRight);
		}
		//alert(container.scrollLeft);
		if (parseInt(container.scrollLeft) != 0)
		{
			container.scrollLeft = 0;
		}
		container.className = "innerContent full noscroll";
	}
}

function initPublicList() { 
	if (document.getElementById("listPublications"))
	{
		var container = document.getElementById("container");		
		var pubContainer = document.getElementById("listPublications");
		pubContainer.className = "pubList noscroll";
		containerId = "pCont";
		if (parseInt(getObjectWidth("pCont","width")) > 760)
		{					
			limitX = 760-parseInt(getObjectWidth("pCont","width"));
			var arrLeft = document.createElement("div");
			arrLeft.setAttribute('id','moveLeft');
			arrLeft.className = "arrow sp";
			arrLeft.style.left = "0px";
			arrLeft.style.display = "none";
			arrLeft.innerHTML = '<a href="#" onmouseover="initProjectsMove('+dirSpeed+');" onmouseout="stopProjectsMove();"><img src="'+rootFolder+'i/arr_left.gif" width="20" height="150" /></a>';
			container.appendChild(arrLeft);
			var arrRight = document.createElement("div");
			arrRight.setAttribute('id','moveRight');
			arrRight.className = "arrow sp";
			arrRight.style.left = "740px";		
			arrRight.innerHTML = '<a href="#" onmouseover="initProjectsMove('+(0-dirSpeed)+');" onmouseout="stopProjectsMove();"><img src="'+rootFolder+'i/arr_right.gif" width="20" height="150" /></a>';
			container.appendChild(arrRight);
		}
	}
}

function prevImage(){

}

function showProjText(){
	if (document.getElementById("projText"))
	{
		document.getElementById("projText").className = "innerPad visible";
	}
	if (document.getElementById("projInfo"))
	{
		document.getElementById("projInfo").className = "innerPad hidden";
	}

}

function showProjInfo(){
	if (document.getElementById("projText"))
	{
		document.getElementById("projText").className = "innerPad hidden";
	}
	if (document.getElementById("projInfo"))
	{
		document.getElementById("projInfo").className = "innerPad visible";
	}
}


function showPage(pNum,pTotal){
	for (var p=0;p<pTotal;p++)
	{
		if (document.getElementById("pText"+(p+1)))
		{
			var page = document.getElementById("pText"+(p+1));
			if ((p+1) == pNum)
			{
				page.className = "visible";
			} else {
				page.className = "hidden";
			}
		}
	}
}

function getObjectWidth(id,prop){
		var objWidth = 0;
		if (document.getElementById(id))
		{
			var obj = document.getElementById(id);
			if(obj.offsetWidth){ 
				objWidth=obj.offsetWidth; 
			} 
			else if(obj.style.pixelHeight){ 
				objWidth=obj.style.pixelWidth; 
			} 
		} else {
			if (document.compatMode && (document.compatMode != "BackCompat"))
			   objWidth = document.documentElement[prop];
			else
			   objWidth = document.body[prop];
		}
		return objWidth;
}

function getObjectHeight(id,prop){
		var objHeight = 0;
		if (document.getElementById(id))
		{
			var obj = document.getElementById(id);
			if(obj.offsetHeight){ 
				objHeight=obj.offsetHeight; 
			} 
			else if(obj.style.pixelHeight){ 
				objHeight=obj.style.pixelHeight; 
			} 
		} else {
			if (document.compatMode && (document.compatMode != "BackCompat"))
			   objHeight = document.documentElement[prop];
			else
			   objHeight = document.body[prop];
		}
		return objHeight;
}

Event.observe(window, 'load', initProjectList, false);
Event.observe(window, 'load', initPublicList, false);
