more = false;

moretext = ""
lesstext = ""

extthumb = "-thumb.jpg";
extfull = "-large.jpg";

stopFade = 0;
curSlide = 1;
contSlide = 1;

function cacheImages()
{
  var j = 0;
  var imgs = new Array();
  // imgs[j] = new Image();
  // imgs[j].src = '/graphics/emptyimg.gif';
  for (var i = 0; i < imagenums.length; i++)
  {
    imgs[j] = new Image();
    imgs[j].src = imagepath + imagenums[i] + extthumb;
	j++;
  }
  for (var i = 0; i < imagenums.length; i++)
  {
    imgs[j] = new Image();
    imgs[j].src = imagepath + imagenums[i] + extfull;
	j++;
  }
  // alert('TEST - ' + imgs[0].src + ', ' + imgs[1].src + ', ' + imgs[2].src);
}

function initAct() {
		act = 'nn1';
		document.getElementById(act).className = "on";
		document.getElementById('projmoreinfo_a').firstChild.nodeValue = moretext;
		window.setTimeout('nextSlide()', 5000);
}

function initActRes() {
		//act = 'nn1';
		//document.getElementById(act).className = "on";
		//document.getElementById('projmoreinfo_a').firstChild.nodeValue = moretext;
		window.setTimeout('nextSlideRes()', 5000);
}

function nextSlide()
{
	if(!contSlide) return;
	if(numSlides<=1) return;
	
	if(curSlide < numSlides)
		curSlide++;
	else
		curSlide =1;
		
	updateAct('nn'+curSlide,1 );
	swapImageFade(curSlide, 1);
	window.setTimeout('nextSlide()', 4000);

}

function nextSlideRes()
{
	if(!contSlide) return;
	if(numSlides<=1) return;
	
	if(curSlide < numSlides)
		curSlide++;
	else
		curSlide =1;
		
	//updateAct('nn'+curSlide,1 );
	swapImageFade(curSlide, 1);
	window.setTimeout('nextSlide()', 4000);

}

function updateAct(id, cont)
{
		if (! window.act) return;
	
		if(cont == null) contSlide=0;
		
		var obj = document.getElementById(act);
		if (obj) {
			obj.className = "off";
		}
		obj = document.getElementById(id);
		obj.className = "on";
		act = id;
}

function projNavOver(num) {
		document.getElementById('projnavlabel').firstChild.nodeValue = navlabels[num-1];
		//document.getElementById('projnavlabel').firstChild.nodeValue = "asd\n<br>qwe";
}

function projNavOut() {
		document.getElementById('projnavlabel').firstChild.nodeValue = 'Projects';
}
function projTreeNavOut() {
		document.getElementById('projnavlabel').firstChild.nodeValue = curlabel;
}


function imgOver(cid,sid,pid,iid) {
		stopFade = 0;
		if(document.getElementById('p'+pid))
			document.getElementById('p'+pid).className = 'current';
		if(document.getElementById('s'+sid))
			document.getElementById('s'+sid).className = 'current';
		if(document.getElementById('c'+cid))
			document.getElementById('c'+cid).className = 'current';
		fadeOutAll(iid);
		
		title = document.getElementById('i'+iid).alt;
		document.getElementById('numbernav').innerHTML = '<span>Project: ' + title + '</span>';
}

function imgOut(cid,sid,pid,iid) {
		stopFade = 1;

		if(document.getElementById('p'+pid))
			document.getElementById('p'+pid).className = '';
		if(document.getElementById('s'+sid))
			document.getElementById('s'+sid).className = '';
		if(document.getElementById('c'+cid))
			document.getElementById('c'+cid).className = '';
		fadeInAll();
		
		document.getElementById('numbernav').innerHTML = '<span>&nbsp;</span>';
}

function fadeOutAll(ex)
{
	//alert('the - '+ex);
  for (var i = 0; i < gridiids.length; i++)
  {
  	//alert(gridiids[i]);
  	if(gridiids[i] == ex) continue;

  	fadeOut('i'+gridiids[i],100);
  }	
}
function fadeInAll()
{
	
	//alert('the - '+ex);
  for (var i = 0; i < gridiids.length; i++)
  {
  	//fadeIn('i'+gridiids[i],30)
	obj = document.getElementById('i'+gridiids[i]);
	setOpacity(obj, 100);
  }	
}



function swapImage(num, cont)
{
		if(cont == null) contSlide=0;

		var pic = document.getElementById('projphoto');
		pic.src = '/graphics/spacer.gif';
		if (more) pic.src = imagepath + imagenums[num-1] + extthumb;
		else pic.src = imagepath + imagenums[num-1] + extfull;
}
function swapImageFade(num, cont)
{
		if(cont == null) contSlide=0;
		//fadeOut0('projphoto', 100);
		
		//obj = document.getElementById('projphoto');
		//setOpacity(obj, 0);
		fadeOutSlide(100, num, cont);
		
		//swapImageFadeShow(num, cont);
}

function swapImageFadeShow(num, cont)
{
		//window.setTimeout("swapImage('"+num+"',"+cont+")", 1000);
		swapImage(num,cont);
		//window.setTimeout("fadeIn('projphoto', 100)", 1000);
		fadeInSlide('projphoto', 0);
}
function moreOn() 
{
	more = true;
	document.getElementById('photoarea').className = 'photomoreon';
	document.getElementById('tproj').className = 'hide';
	document.getElementById('pproj').className = 'show';
	document.getElementById('awards').className = 'show';
	document.getElementById('projmoreinfo_a').className = 'less';
	document.getElementById('projmoreinfo_a').firstChild.nodeValue = lesstext;
	var x = act.split('nn');
	swapImage(x[1]);
}

function moreOff() 
{
	more = false;
	document.getElementById('photoarea').className = 'photomoreoff loading';
	document.getElementById('tproj').className = 'show';
	document.getElementById('pproj').className = 'hide';
	document.getElementById('awards').className = 'hide';
	document.getElementById('projmoreinfo_a').className = 'more';
	document.getElementById('projmoreinfo_a').firstChild.nodeValue = moretext;
	var x = act.split('nn');
	swapImage(x[1]);
}

function doMore() {
	if (more) moreOff();
	else moreOn();
}



function fadeIn(objId,opacity) {

	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 25;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}else {
			setOpacity(obj,100);
		}
	}
}

function fadeInSlide(objId,opacity) {

	if (document.getElementById) {
		//alert('a');
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeInSlide('"+objId+"',"+opacity+")", 75);
		}else {
			setOpacity(obj,100);
		}
	}
}
function fadeOut(objId, opacity ) {
	if(stopFade == 1) return;
	 
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity > 20) {
			setOpacity(obj, opacity);
			opacity -= 20;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 75);
		}
	}
}
function fadeOutSlide(opacity, num, cont) {
	obj = document.getElementById('projphoto');
	if (opacity >= 0) {
		setOpacity(obj, opacity);
		opacity -= 20;
		window.setTimeout("fadeOutSlide("+opacity+","+num+","+cont+")", 75);
	}else{
		setOpacity(obj, 0);	
		swapImageFadeShow(num, cont);
	}
		
}


function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}









