function dynaCat(cat, state){
	var catlink = cat + 'a';
	if (state == 'a'){
		document.getElementById(catlink).style.borderColor = '#f00';
	} else {
		document.getElementById(catlink).style.borderColor = '#fff';
	}
}
var current_pop = '';

function ShowPopout(id){
return(Popout(id, '-25px'));
}
function HidePopout(id){
	document.getElementById(id).style.display="none";
	current_pop = "";
return(false);
}


function Popout(id, top){
	if (current_pop != '') { 
		HidePopout(current_pop); 
	}
	if (id){
		document.getElementById(id).style.display="block";
	}
	current_pop = id;
return(false);
}

function hide_reveal(idh, idd){
document.getElementById(idh).style.display = 'none';
	if (document.getElementById(idd)){
		document.getElementById(idd).style.display = 'block';
	} else {
		document.getElementById('W1').style.display = 'block';	
	}
}
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


function startPools(){
	rotatePool('Pool1');
	rotatePool('Pool2');
	rotatePool('Pool3');
	rotatePool('Pool4');

}

var timers = Array();

function rotatePool(pool){

var delay = 8000;
var fade_speed = 2000;
	if (document.images){
		if (document.images){
			image_counter = pCtr[pool];
			if (pool == 'Pool1') { parray = Pool1; }
			if (pool == 'Pool2') { parray = Pool2; delay = 7000}
			if (pool == 'Pool3') { parray = Pool3; delay = 3000}		
			if (pool == 'Pool4') { parray = Pool4; delay = 6000}		
			
			if (parray.length > 1){

				var pdiv = 'Div' + pool;
				blendimage(pdiv, pool, parray[image_counter].src, fade_speed);
				document.getElementById(pool).title = parray[image_counter].title;
				if (parray[image_counter].pid > 0){
					document.getElementById('FeatureLink').href = 'projects.php?pid=' + parray[image_counter].pid;

				} else {
					document.getElementById('FeatureLink').href = '#';

				}
				image_counter++;
				if (image_counter == parray.length){
					image_counter = 0;
				}
				pCtr[pool] = image_counter;

				timers[pool]=window.setTimeout('rotatePool("'+pool+'")',delay);
			}
		}
	}
}


function replace_image (el, image){
document.getElementById(el).src = image;
return(false);
}


function rotatePoolOld(pool){

    var delay = 4000;
	if (document.images){
		
	
		if (document.all) {	
			document.getElementById(pool).style.filter="blendTrans(duration=2)";
			document.getElementById(pool).style.filter="blendTrans(duration=crossFadeDuration)";
			document.getElementById(pool).filters.blendTrans.Apply();
		}
	
		if (document.images){
			image_counter = pCtr[pool];
			if (pool == 'Pool1') { parray = Pool1; }
			if (pool == 'Pool2') { 
				parray = Pool2; 
				delay = 4000;
			}
			if (pool == 'Pool3') { parray = Pool3; delay = 3000}		
			if (pool == 'Pool4') { parray = Pool4; delay = 6000}		
			
			if (parray.length > 1){
				document.getElementById(pool).src = parray[image_counter].src;
	
		
				if (document.all) {
					document.getElementById(pool).filters.blendTrans.Play();
				}
		
				image_counter++;
				if (image_counter == parray.length){
					image_counter = 0;
				}
				pCtr[pool] = image_counter;

				timers[pool]=window.setTimeout('rotatePool("'+pool+'")',delay);
			}
			
		}
	}
}

function replace_image (el, image){
document.getElementById(el).src = image;
return(false);
}

SwapLimage.current = "LeftImage0";
function SwapLimage(id){
	id = 'LeftImage' + id;
document.getElementById(SwapLimage.current).style.display = "none";
document.getElementById(id).style.display = "block";
SwapLimage.current = id;
}


swapFeature.swapcount=0;
swapFeature.orig='';
var swapTimer;
var swapTimer2;
function swapFeature(image, largeimage){
	window.clearTimeout(swapTimer);

	el = document.getElementById('leftFeature');
	if (el){	
		if(swapFeature.swapcount == 0){
			swapFeature.orig = el.innerHTML;
		}
		swapFeature.swapcount++;
		if(image){
			el.innerHTML = '<img src="'+image+'"  height="244" width="440" onClick="swapMain(\''+largeimage+'\')">';
			swapTimer = window.setTimeout('swapFeature()',11000);
		} else {
			el.innerHTML = swapFeature.orig;		
		}
		

	}
}


swapMain.swapcount=0;
swapMain.orig='';

function swapMain(image){
	window.clearTimeout(swapTimer2);

	el = document.getElementById('mainContent');
	
	if(swapMain.swapcount == 0){
		swapMain.orig = el.innerHTML;
	}
	swapMain.swapcount++;
	if(image){
		el.innerHTML = '<img src="'+image+'" onClick="swapMain()" style="position:relative; top: -10px; margin-bottom: -20px">';
		swapTimer2 = window.setTimeout('swapMain()',12000)
	} else {
		el.innerHTML = swapMain.orig;		
	}

}


function swapback(){
window.clearTimeout(swapTimer);
swapTimer=window.setTimeout('swapFeature()',1000);
}
