function displayRoomPhotos( event, roomId )
{
	if ( window.actualRoomPhotoRoomId === null || window.actualRoomPhotoRoomId != roomId )
	{
		if ( window.actualRoomPhotoEffect !== null )
		{
			window.actualRoomPhotoEffect.cancel();
		}
		hideRoomsPhotos();
		$( 'roomPhotoBox' ).style.top = ( Event.pointerY(event) + 5 ) + 'px';
		$( 'roomPhotoBox' ).style.left = ( Event.pointerX(event) - 170 ) + 'px';
		$( 'roomPhotoBoxName' ).innerHTML = Event.element(event).innerHTML;
//		alert( Event.pointerX(event) );
		displayRoomPhoto( roomId, 1, true );
	}
}
function displayRoomPhoto( roomId, photoId, firstTime )
{
	window.actualRoomPhotoRoomId = roomId;
	window.actualRoomPhotoPhotoId = photoId;
	
	var photoDiv = $( 'room' + roomId + 'Photo' + photoId );
	if ( photoDiv !== null )
	{
		$( 'roomPhotoBox' ).style.display = '';
		$( 'roomPhotoBoxBottom' ).style.display = '';
		var h = Element.getHeight( 'roomPhotoBoxClose' );
		var w = Element.getWidth( 'roomPhotoBoxClose' );
		$( 'roomPhotoBoxBottom' ).style.display = 'none';
		Element.setHeight( 'roomPhotoBoxName', h );
		photoDiv.style.display = '';
		Element.setWidth( 'roomPhotoBoxName', photoDiv.width - w - 46 );
		photoDiv.style.display = 'none';
		if ( photoId > 1 )
		{
			$( 'roomPhotoBoxLeft' ).style.visibility = 'visible';
		}
		else
		{
			$( 'roomPhotoBoxLeft' ).style.visibility = 'hidden';
		}
		if ( $( 'room' + roomId + 'Photo' + ( photoId + 1 ) ) !== null )
		{
			$( 'roomPhotoBoxRight' ).style.visibility = 'visible';
		}
		else
		{
			$( 'roomPhotoBoxRight' ).style.visibility = 'hidden';
		}
		window.actualRoomPhotoEffect = new Effect.Scale('roomPhotoBox',100
		  , { duration: ( firstTime ? 0.5 : 0.2 )
			  , scaleContent:false
			  , scaleMode: { originalHeight: photoDiv.height + 15 + h, originalWidth: photoDiv.width + 6 }
			  , scaleFrom: ( firstTime ? 0.0 : 100.0 )
			  , afterFinish: function() { photoDiv.style.display = ''; 	$( 'roomPhotoBoxBottom' ).style.display = ''; }
			}
		);
//  , scaleContent:true
//  , scaleMode:'contents'					// ‘box’ (default, scales visible area)
	}
}
function hideRoomsPhotos()
{
	var a = $( 'roomPhotoBox' ).childNodes;
	for ( var i = 0; i < a.length; i++ )
	{
		if ( a[i].nodeName == 'IMG' )
		{
			a[i].style.display = 'none';
		}
	}
//.getElementsBySelector('img').size() );
//	$$( '#roomPhotoBox img' ).invoke( 'hide' );
}
function switchRoomPhoto( direction )
{
	if ( $( 'room' + window.actualRoomPhotoRoomId + 'Photo' + ( window.actualRoomPhotoPhotoId + direction ) ) !== null )
	{
		hideRoomsPhotos();
		displayRoomPhoto( window.actualRoomPhotoRoomId, window.actualRoomPhotoPhotoId + direction, false );
	}
}


function closeRoomPhotoBox()
{
	$( 'roomPhotoBox' ).style.display = 'none';
	window.actualRoomPhotoRoomId = 0;
	window.actualRoomPhotoPhotoId = 0;
	//window.actualRoomPhotoEffect = null;
	$( 'roomPhotoBox' ).style.width = '0px';
	$( 'roomPhotoBox' ).style.height = '0px';
	return false;
}

function initRoomPhotoBox()
{
	window.actualRoomPhotoRoomId = 0;
	window.actualRoomPhotoPhotoId = 0;
	window.actualRoomPhotoEffect = null;
	var a = $( 'availability-table' ).getElementsByTagName( 'A' );
	for ( i = 0; i < a.length; i++ )
	{
		if ( a[i].id.substr(0,4) == 'room' )
		{
			Event.observe( a[i].id, 'mouseover', function(event) { displayRoomPhotos( event, parseInt( Event.element(event).id.substr(4) ) ); } );
		}
	}
	Event.observe( window, 'load', function() {	
		Event.observe( document, 'click', function(event) { closeRoomPhotoBox(); } );
		Event.observe( 'roomPhotoBox', 'click', function(event) { Event.stop(event); }, false );
		} );
}