function hoverTile( e )
{
	var src;
	var id;
	var html;
	
	if( !( e = e || event ) )
	{
		return;
	}
	
	src = e.target || e.srcElement;
	
	while( !/^a$/i.test( src.tagName ) )
	{
		if( /^body$/i.test( ( src = src.parentNode ).tagName ) )
		{
			return;
		}
	}
	
	if( !( id = src.href.match( /\?p=(\d+)\b/ ) ) )
	{
		return;
	}
	
	id = id[1];
	
	if( !locations[id] )
	{
		return;
	}
	
	showInfo( src.getElementsByTagName( 'img' )[0].getAttribute( 'title' ), locations[id] );
}
function outTile( e )
{
	showInfo();
}

function showInfo( p_name, p_location )
{
	var nfo = document.getElementById( 'info' );

	while( nfo.hasChildNodes() )
	{
		nfo.removeChild( nfo.firstChild );
	}

	if( p_name )
	{
		var n = document.createElement( 'span' );
		n.className = 'projectname';
		n.appendChild( document.createTextNode( p_name ) );
		var l = document.createElement( 'span' );
		l.className = 'projectlocation';
		l.appendChild( document.createTextNode( p_location ) );
		
		nfo.appendChild( n );
		nfo.appendChild( l );
	}
}

function _init( e )
{
	var evtfunc;
	var tiles;
	var i;
	
	if( !( e = e || event ) )
	{
		return;
	}
	
	evtfunc = e.type == 'load' ? addEvent : removeEvent;
	tiles = document.getElementById( 'square' ).getElementsByTagName( 'a' );
	
	for( i=0; i<tiles.length; i++ )
	{
		if( /\btile\b/i.test( tiles[i].className )
		 && !/\blabel\b/i.test( tiles[i].className ) )
		{
			evtfunc( tiles[i], 'mouseover', hoverTile );
			evtfunc( tiles[i], 'mouseout', outTile );
		}
	}
}

addEvent( window, 'load', _init );
addEvent( window, 'unload', _init );
