/* General site functions*/

var fader; 		//global, but declared here for use in setTimeout
var oMainImage; // ditto
var imgMainSrc;	// well, you get the idea

function CW_swapThumbnailImg(obj)
{
	//find image inside anchor (obj)- s/be childNodes[0]
	
	for(var i=0;i<obj.childNodes.length;i++)
	{
		var imgTag = obj.childNodes[i];	
		if(imgTag.tagName=='IMG')	
		{
			//get filename of img
			var imgThumbSrc = new String(imgTag.src);
			//replace _thumb with _main
			imgMainSrc = imgThumbSrc.replace('_thumb','_main');
			//put main image object into local variable for ease of use
			oMainImage = document.getElementById('MainImage');
			//create fader object to handle alpha blending OUT
			//	args: element, rate
			// rate is the % to lose per call, with 20 calls per second.
			// we want fadeout in about 1/3 a second, meaning 
			fader = new Fadomatic(oMainImage,40);
			//start fadeout
			fader.fadeOut();
			//set src of main image as new image, then reload.  But in a minute
			setTimeout("oMainImage.src = imgMainSrc;fader.fadeIn();",300);
		}
	}

	//No image found - just keep quiet.
	return false;
}

function renderPageLayout() //called onload and onresize
{
	horizontalCentre();
	//fixMenu(false);
}

var ImagesArray= new Array();

function preloadProjectImages()
{
	//generic image loader.  loads images for page based on current URL
	//assumes that the images sahre the same project code as the page
	
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	var sProject = sPage.replace('.htm','');

	for(var i = 1;i<7;i++)
	{
		ImagesArray[i] = new Image(1,1);
		var imgSrc = 'images/'+sProject+'_'+i+'_main.jpg';
		ImagesArray[i].src = imgSrc;
	}
}

function horizontalCentre(){
	//resize spacer element at top of page to centre main table horizontally
	//CSS height=50% doesn't work in Win/IE
	//div starts as 1px
	
	//var currentPageHeight = window.screen.availHeight;
	var currentPageHeight;
	if(window.innerHeight)
	{
		currentPageHeight = window.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight && document.documentElement.clientHeight > 0)
	{
		currentPageHeight = document.documentElement.clientHeight;
	}
	else
	{
		currentPageHeight = window.document.body.clientHeight;
	}
	
	if(currentPageHeight > 658)
	{
		document.getElementById('spacerDiv').style.height = (currentPageHeight - 658)/2;
	}
	else
	{
		document.getElementById('spacerDiv').style.height = 1;
	}
}
