var _pause = 'Pause';
var _play = 'Play';
var _photos = new Object();
var _photoIndex = 0;
var _photoCount = 0;
var _thumbnailUrl='/InfocasaEngine/Handlers/imageView.php?in={0}&is={1}';

function Photo(name,caption)
{
	this.name = name;
	this.caption = caption;
}

function ChangePhoto()
{
	if (_photos[_photoIndex] != null)
	{
		u=new String(_thumbnailUrl);
		u=u.replace(/\{0\}/g,_photos[_photoIndex].name);
		u=u.replace(/\{1\}/g,'medium');
		document.getElementById('propertyDetails__photoSlide__photoIndex').innerHTML = _photoIndex + 1;
		document.getElementById('propertyDetails__photoSlide__photo').src =u;
		document.getElementById('propertyDetails__photoSlide__photo').title = _photos[_photoIndex].caption;
		document.getElementById('propertyDetails__photoSlide__photo').alt = _photos[_photoIndex].caption;
		document.getElementById('photoCaption').innerHTML = _photos[_photoIndex].caption;
	}
}

function FirstPhoto(thumbnailUrl)
{
	_thumbnailUrl=thumbnailUrl;
	_photoIndex = 0;

	ChangePhoto();
}

function LastPhoto(thumbnailUrl)
{
	_thumbnailUrl=thumbnailUrl;
	_photoIndex = _photoCount - 1;

	ChangePhoto();
}

function NextPhoto(thumbnailUrl)
{
	_thumbnailUrl=thumbnailUrl;
	_photoIndex++;

	if (_photoIndex > (_photoCount - 1))
	{
		_photoIndex= 0;
	}

	ChangePhoto();
}

function PreviousPhoto(thumbnailUrl)
{
	_thumbnailUrl=thumbnailUrl;
	_photoIndex--;

	if (_photoIndex < 0)
	{
		_photoIndex = _photoCount -1;
	}

	ChangePhoto();
}

var _photoShow = false;

function PhotoShow()
{
	if (_photoShow == true) {
		_photoIndex++;

		if (_photoIndex > (_photoCount - 1))
		{
			_photoIndex = 0;
			ChangePhoto();

			StopPhotoShow();

		}else{
			ChangePhoto();
			window.setTimeout('PhotoShow();', 5000);

		}
	}
}

function ToggleShow(thumbnailUrl)
{
	_thumbnailUrl=thumbnailUrl;
	if (_photoShow == false)
	{
		StartPhotoShow();
	}
	else
	{
		StopPhotoShow();
	}
}

function StartPhotoShow()
{
	if (_photoCount > 1)
	{
		_photoShow = true;
		PhotoShow();
		s = new String(document.images['StartStop'].src);
		s=s.replace(/[^/]+\.[^/]+$/g,"Stop.png");
		document.images['StartStop'].src = s;
		document.images['StartStop'].title = _pause;
	}
}

function StopPhotoShow()
{
	_photoShow = false;
	s = new String(document.images['StartStop'].src);
	s=s.replace(/[^/]+\.[^/]+$/g,"play.png");
	document.images['StartStop'].src = s;
	document.images['StartStop'].title = _play;
}

function ShowPhoto(elem,thumbnailUrl)
{
	u=new String(thumbnailUrl);
	u=u.replace(/\{0\}/g,_photos[_photoIndex].name);
	u=u.replace(/\{1\}/g,'large');
	window.open(u + '&ca=' + _photos[_photoIndex].caption,'','width=660,height=460,resizable=1,scrollbars=1');
}