


//sort numerically
function numberSort(a,b)
{
	return b-a;
};



//normalise column heights 
function columns()
{
	
	//for each column
	for(var i=0; i<afs.colsLen; i++)
	{
		//store the offset height of this column minus the bottom border
		afs.heights[i] = afs.cols[i].offsetHeight - 1;
	}
	
	//sort the column heights array
	afs.heights.sort(numberSort);

	//set all columns to the first (tallest) height
	//using the em-px ratio we calculated in the homepage() function
	for(i=0; i<afs.colsLen; i++)
	{
		afs.cols[i].style.height = (afs.heights[0] * afs.ratio) + 'em'
		//afs.cols[i].style.height = afs.heights[0] + 'px'
	}	

};



//homepage function 
function homepage()
{
	
	//get columns
	afs.cols = document.getElementById('columns').getElementsByTagName('div');
	afs.colsLen = afs.cols.length;
	
	//array for storing column heights
	afs.heights = [];
	
	//for each column
	for(var i=0; i<afs.colsLen; i++)
	{
		//set pointer cursor so it appears to be a link
		//I'm doing an IE discriminator here because
		//win/ie5.0 throws an invalid argument error if you try to set "pointer" as the value
		//because to win/ie5.0 it's an invalid property value 
		//Opera in MSIE spoof mode will see this as well, but it understands "hand", so it doesn't matter
		afs.cols[i].style.cursor = (typeof document.all != 'undefined') ? 'hand' : 'pointer';
		
		//bind a mouseover handler 
		afs.cols[i].onmouseover = function()
		{
			//set rollover classname
			this.className += ' rollover';
		};
		
		//bind a mouseout handler
		afs.cols[i].onmouseout = function()
		{
			//remove rollover classname
			this.className = this.className.replace(/ rollover/g,'');
		};
		
		//bind a click handler
		afs.cols[i].onclick = function()
		{
			//follow first link
			document.location = this.getElementsByTagName('a')[0].href;
		};
	}
	
	//if element creation is supported
	if(typeof document.createElement !=' undefined')
	{
	
		//create a test elements inside the first column 
		afs.test = afs.cols[0].appendChild(document.createElement('span'));
		afs.test.className = 'test';
		
		//calculate the em-px ratio using the offset height (a number in pixels)
		//compared with the known em height (10)
		afs.ratio = (10 / afs.test.offsetHeight);
			
		//normalise the column heights
		columns();
	}
};




