function preloadImages()
{
	var src;
	var i;
	
	for( i=0; i<document.fullPhotos.length; i++ )
	{
		src = document.fullPhotos[i];
		document.fullPhotos[i] = new Image();
		document.fullPhotos[i].src = src;
	}
}

function hoverImage( e )
{
	var src;
	var thumbnails = document.getElementById( 'iconnavigation' ).getElementsByTagName( 'a' );
	var i;
	
	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;
		}
	}
	
	for( i=0; i<Math.min( document.fullPhotos.length, thumbnails.length ); i++ )
	{
		if( src == thumbnails[i] )
		{
			document.getElementById( 'photo' ).src = ( typeof document.fullPhotos[i] == 'object' ? document.fullPhotos[i].src : document.fullPhotos[i] );
			document.getElementById( 'photo' ).title = src.getElementsByTagName( 'img' )[0].title;
			break;
		}
	}
	$('.thereis_canvas').css('top','-100%');
	
	e.cancelBubble = true;
	
	if(e.stopPropagation)
	{
		e.stopPropagation();
	}
	
	return false;
}

function preloadMap() {

	if( document.geoLocation ) {
	
		$('#content').css('overflow','hidden');
		$.thereis.defaults.showgeocoder = false;
		$.thereis.defaults.marker.draggable = false;
	
		

		$('.thereis_canvas')
			.css({'position':'relative','top':'-100%'})
			.thereis($.whereis.decode(document.geoLocation));
		$('#mapIcon').mouseover(function(){$('.thereis_canvas').css('top','0px');});
	
		if(document.startMap){
			$('#mapIcon').mouseover();
		}
	}
}

function _init( e )
{
	var evtfunc;
	var thumbnails = document.getElementById( 'iconnavigation' ).getElementsByTagName( 'a' );
	var i;
	
	if( !( e = e || event ) )
	{
		return;
	}
	
	evtfunc = {'load':addEvent,'unload':removeEvent}[e.type];
	
	for( i=0; i<Math.min( document.fullPhotos.length, thumbnails.length ); i++ )
	{
		evtfunc( thumbnails[i], 'mouseover', hoverImage );
	}
	
	hoverImage( {'target':document.getElementById( 'iconnavigation' ).getElementsByTagName( 'img' )[Math.min( document.photoStart, document.fullPhotos.length )]} );
	
	if( e.type == 'load' )
	{
		preloadImages();
		preloadMap();
	}
}

addEvent( window, 'load', _init );
addEvent( window, 'unload', _init );