var header_img = '';
var header_changed = true;

prefixes = {
	'/home/': 'splash/room-001.jpg',
	'/rooms/': 'splash/room-002.jpg',
	'/specials_and_packages/': 'splash/view.jpg',
	'/conference/': 'splash/laptop.jpg',
	'/information/': 'splash/outside.jpg',
	'/newsletter/': 'splash/outside.jpg',
	'/contact/': 'splash/reception.jpg'
}

function getMovieName(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
}
function animate( img ) {
	if( !getMovieName("header") ) return;
	if( !getMovieName("header").changeFlashImage ) return;
	getMovieName("header").changeFlashImage( img );
}

function identifySplash( url )
{
	for ( var p in prefixes )
	{
		if ( url.indexOf( p ) != -1 )
		{
			return prefixes[p];
		}
	}
	
	if ( header_img == '' )
		header_img = 'splash/room-001.jpg';
	
	return header_img;
}

function initialHeaderImage( )
{
	header_img = identifySplash( location.href );
	switchHeader( );
}

function preloadImages( )
{
	for ( var p in prefixes )
	{
		a = new Image( );
		a.src = image_dir + prefixes[p];
	}
	
	//header_img = identifySplash( location.href );
	
	/*$('incoming_image').src = image_dir + identifySplash( location.href );
	$('outgoing_image').src = image_dir + identifySplash( location.href );*/
	//animate( image_dir + identifySplash( location.href ) );
	
	if ( location.hash != '' )
	{
		location.href = '/' + location.hash.substring( 1 ) + '/';
	}
}

function switchPages( atag )
{
	url = atag.href + '?contentOnly=true';
	
	n_header_img = identifySplash( url );
	
	if ( header_img != n_header_img )
	{
		header_changed = true;
		header_img = n_header_img;
	}
	
	new Ajax.Updater( 'content_area', url, {asynchronous: true, evalScripts: true, method: 'get'} );
	
	ourl = atag.href;
	
	if ( ourl.indexOf( 'http://' ) != -1 )
	{
		ourl = ourl.substring( ourl.indexOf( 'http://' )+7 );
		ourl = ourl.substring( ourl.indexOf( '/' )+1 );
		
		if ( ourl[ourl.length-1] == '/' )
			ourl = ourl.substring( 0, ourl.length-1 );
	}
	
	location.href = '#' + ourl;
	
	return false;
}

function switchHeader( )
{
	imurl = image_dir + header_img;
	
	if ( !header_changed )
		return;
	
	header_changed = false;
	animate( imurl );
	
	/*imurl = image_dir + header_img;
	
	if ( $('incoming_image').src.indexOf(imurl) != -1 )
		return;
	
	$('outgoing_image').src = $('incoming_image').src;
	$('incoming_image').src = imurl;
	
	Element.hide('incoming');
	Element.removeClassName( 'incoming', 'initial_transparent' );
	new Effect.Appear('incoming');
	new Effect.SlideDown('incoming');*/
}