var activeItem = activeItemID = null;


// http://www.xs4all.nl/~ppk/js/findpos.html
function findPosY(obj)
{	
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	return curtop;
}



function toggleObjectDisplay(objId)
	{
	obj = document.getElementById(objId);
	if (obj)
		{
		if (obj.style.display == "block") obj.style.display = "none";
		else obj.style.display = "block";
		}
	}
	
	
function sg_screenObject()
	{
	this.bottom = function(){
		if (document.body.scrollHeight) return document.body.scrollHeight};
	
	this.height = function() {
		if (document.body.offsetHeight) return document.body.offsetHeight;}
	
	this.visHeight = function() {
		if (window.innerHeight) return window.innerHeight;
		if (document.body.clientHeight) return document.body.clientHeight;}
	
	this.width = function() {
		if (document.body.offsetWidth) return document.body.offsetWidth;}
	
	this.scrollTop = function() {
		if(document.body.scrollTop) return document.body.scrollTop
		if (window.pageYOffset) return window.pageYOffset;
		else return 0;};
	}


function gID(o)
	{
	return document.getElementById(o);
	}

function inArray(string, arr)
	{
	for(var i=0; i < arr.length; i++)
		{
		if(arr[i] == string) return i;

		}
	return false;
	}


function goNavLink()
	{
	document.location = nav_link;
	}

function showHomePage()
	{
	try{
		gID("pg_title").style.visibility = "hidden";
		gID("nav_button").style.visibility = "visible";
		//gID("nav_arrow").style.visibility = "visible";
		}
	catch(err){}
	}
	

function hideHomePage()
	{
	try{
		gID("pg_title").style.visibility = "visible";
		gID("nav_button").style.visibility = "hidden";
		//gID("nav_arrow").style.visibility = "hidden";
		}
	catch(err){}
	}

function hightlight(o)
	{
	activeItem.style.background = "transparent";
	activeItem = o;
	activeItem.style.background = "#666666";
	}

function scrollColumn(mod)
	{
	
	colPos = colPos + mod;
	var newPos = COL_HEIGHT * colPos;

	if (newPos <= 0 && newPos > (-1 * gID("project_list").offsetHeight))
		{
		gID("project_list").style.top = (COL_HEIGHT * colPos) - LINE_HEIGHT + "px"; //"-100px";
		}
	else colPos = colPos - mod;
	}


function scrollTo(o)
	{
	pos = findPosY(o)-141;

	if (pos < 0)
		{
		parent.scrollColumn(1);
		parent.scrollTo(o);
		}
	if(pos > COL_HEIGHT)
		{
		parent.scrollColumn(-1);
		parent.scrollTo(o);
		}
	}

function makeActiveItem(o)
	{
	try 
		{
		parent.gID(parent.activeItem).style.color = "#666666";
		}
	catch(err) {}
	
	parent.activeItem = "client_"+o;
	parent.activeItemID = o;
	
	p = parent.gID(parent.activeItem);
	
	//make sure active item is in view
	//parent.scrollTo(p);
	
	parent.gID(parent.activeItem).style.color = "#FFFFFF";
	}

//change to next/previous project dir:direction
function turnProject(dir)
	{
	var pos = inArray(parent.activeItemID, parent.allProjects);
	if (pos == false) pos = -1;
	
		
	if (pos+dir >= 0 && pos+dir < parent.allProjects.length)
		{

		id = parent.allProjects[pos+dir];
		document.location = "portfolio.php?project_id="+id;
		}
	else 
		{
		if (pos+dir < 0)			
			document.location = "portfolio.php?project_id="+parent.allProjects[parent.allProjects.length-1];
		
		if (pos+dir >= parent.allProjects.length)
			document.location = "portfolio.php?project_id="+parent.allProjects[0];
		}
	}

function centerPage()
	{
	try
		{
		//alert(thisScreen.width);
		if (thisScreen.width() > 610)
		gID("pageCon").style.left = Math.round((thisScreen.width()-600)/2);
		}
		
	catch(err){}
	}

function windowInit()
	{
	//window.resizeTo(900,800)
	

	}
	
function closeScreen()
	{
	try
		{
		//document.location = "";
		document.getElementById("screen").style.visibility = "hidden";
		//document.getElementById("bodyNode").innerHTML = "";
		document.getElementById("desc").style.visibility = "visible";
		document.getElementById("screens_nav").style.visibility = "visible";
		}
	catch(err)
		{
		alert("Your browser appears not to be compatible with this script, my apologies");
		}
	}

function showScreen(id)
	{
	try
		{
		document.getElementById("screen").style.visibility = "visible";
		document.getElementById("desc").style.visibility = "hidden";
		document.getElementById("screens_nav").style.visibility = "hidden";
		}
	catch(err)
		{
		alert("Your browser appears not to be compatible with this script, my apologies");
		}
	}

function sizeFrame(width, height)
	{
	
	try {
		parent.document.getElementById("screen").style.height= height+26;
		}
	catch(err){}
	}

function windowClose()
	{
	
	try {
		parent.document.getElementById("project_detail").style.visibility= "hidden";
		}
	catch(err){}
	}

window.onload = windowInit;
window.onresize = centerPage;
document.onunload = windowClose;