function InitSlideshow()
{
	var changeOverCookie = getCookie('locr_slideshow_changeover');
	if(changeOverCookie == 'changeover') changeOver = true;
	if(changeOverCookie == 'no_changeover') changeOver = false;

	var screenWidth = ScreenDimension()[0];

	//if(ScreenWidth < 1400)
		//ImageSize = LOCR_FILE_IDENTIFIER_MEDIUM; else
		ImageSize = LOCR_FILE_IDENTIFIER_LARGE;

	WikipediaLength = 500;
	document.getElementById("changeSizeImg").removeAttribute('class');
	var Class = document.createAttribute('class');
	Class.nodeValue = 'slideshow_zoom_out';
	document.getElementById("changeSizeImg").setAttributeNode(Class);
	document.getElementById("changeSizeImg").setAttribute('alt', document.getElementById('LOCR_SLIDE_L_ZOOM_OUT').value);
	document.getElementById("changeSizeSrc").setAttribute('title', document.getElementById('LOCR_SLIDE_L_ZOOM_OUT').value);

	document.getElementById("LOCR_SLIDE_NAVIGATION").style.width = screenWidth+'px';

	var Url = SlideshowUrl;
	var UrlParams = "wikilength="+WikipediaLength+"&album_id="+document.getElementById('AlbumId').value+"&size="+ImageSize+"&min="+MinimumSlide+"&max="+MaximumSlide;
	var Request = new AjaxRequest();
		Request.Send(Url, {
			callback: CallbackLoadSlideshow,
			callback_parameters: {
				result_is_xml: true
			},
			url_params: UrlParams
		});

	if(document.getElementById('map').style.width && document.getElementById('map').style.height)
	{
		Width = parseInt(document.getElementById('map').style.width.split('px'));
		Height = parseInt(document.getElementById('map').style.height.split('px'));
	}

	SetMapOverlay();

	window.onresize = RefreshSlideView;
}

function CallbackLoadSlideshow(Params)
{
	SlideshowCookie();
	var xmlData = Params.XmlResult;
	var SlideContainer = document.getElementById('LOCR_SLIDE_CONTAINER');
	var SlideMap = document.getElementById('map');

	if(MinimumSlide == 0)
	{
		var countNode = xmlData.getElementsByTagName('count').item(0);

		if(countNode)
		{
			MaximumImages = countNode.firstChild.data;

			// Latitude and Longitude
			var points = xmlData.getElementsByTagName('coordinates').item(0);
			var pointsItems = points.getElementsByTagName('coordinate');

			for(var i = 0; i < pointsItems.length; i++)
			{
				var pointsEntry = pointsItems.item(i);
				var pointsEntryId = parseInt(pointsEntry.getAttribute('id').toString());
				var pointsEntryLatitude = parseFloat(pointsEntry.getAttribute('lat').toString());
				var pointsEntryLongitude = parseFloat(pointsEntry.getAttribute('lng').toString());
				var pointsEntryWidth = parseInt(pointsEntry.getAttribute('w').toString());
				var pointsEntryHeight = parseInt(pointsEntry.getAttribute('h').toString());
				ImagesPoints.push({
					id:		pointsEntryId,
					lat:	pointsEntryLatitude,
					lng:	pointsEntryLongitude,
					w:		pointsEntryWidth,
					h:		pointsEntryHeight
				});

				if((pointsEntryWidth > MaximumImageWidth) && ImageResize)
				{
					MaximumImageWidth = pointsEntryWidth;
					SlideContainer.style.left = 400+'px';
					SlideMap.style.width = (SlideContainer.style.left.split('px')[0]-2)+'px'; // 2: Border
				}

				if((pointsEntryHeight > MaximumImageHeight) && ImageResize)
				{
					var ScreenDimensions = ScreenDimension();
					MaximumImageHeight = pointsEntryHeight;
					if(ScreenDimensions[1] < 700)
						var SlideMapHeight = 700;
					else
						var SlideMapHeight = ScreenDimensions[1];
					SlideMap.style.height = (SlideMapHeight-37)+'px';
				}
			}

			for(var i = 0; i < ImagesPoints.length; i++)
			{
				var currentImageWidth = ImagesPoints[i]['w'];
				var currentImageHeight = ImagesPoints[i]['h'];
				var currentImageRatio = currentImageWidth / currentImageHeight;
				if(currentImageRatio > maxImageRatio)
				{
					maxImageRatio = currentImageRatio;
					maxRatioWidth = currentImageWidth;
					maxImageRatioWidth = currentImageWidth;
				}
				if(currentImageRatio < minImageRatio)
				{
					minImageRatio = currentImageRatio;
					maxRatioHeight = currentImageHeight;
				}
				if(currentImageWidth > maxImageWidth) maxImageWidth = currentImageWidth;
			}
			MaxWidthForPhoto = ScreenWidth;
			RatioForPhoto = (MaxWidthForPhoto) / (ScreenHeight-37);
			if(minImageRatio/2 >= RatioForPhoto) // Panorama-Ansicht
			{
				MaxPercentHeight = maxRatioHeight * 100 / (ScreenHeight-37);
				SlideMap.style.height = ScreenHeight-Math.floor(ScreenWidth/minImageRatio)-37+'px';
				SlideMap.style.width = ScreenWidth+'px';
			} else
			{
				MaxWidthForPhoto = ScreenWidth - SlideContainer.style.left.replace('px','');
				MaxPercentHeight = 0;
			}
		}
	}

	if(ImageSize == LOCR_FILE_IDENTIFIER_MEDIUM)
	{
		maxRatioWidth = ScreenWidth - MinMapWidth; // test
	}

	var slides = xmlData.getElementsByTagName('slides').item(0);
	var slidesItems = slides.getElementsByTagName('slide');

	for(var i = 0; i < slidesItems.length; i++)
	{
		var slidesEntry = slidesItems.item(i);
		var slidesEntryId = parseInt(slidesEntry.getAttribute('id').toString());
		var slidesEntryWidth = parseInt(slidesEntry.getAttribute('width').toString());
		var slidesEntryHeight = parseInt(slidesEntry.getAttribute('height').toString());
		var slidesEntrySource = slidesEntry.getAttribute('src').toString();
		var slidesEntryCaption = slidesEntry.getAttribute('caption').toString();
		var slidesEntryCreated = slidesEntry.getAttribute('created').toString();
		var slidesEntryWikipedia = slidesEntry.getAttribute('wiki').toString();
		Images.push({
			id:			slidesEntryId,
			src:		slidesEntrySource,
			width:		slidesEntryWidth,
			height:		slidesEntryHeight,
			caption:	slidesEntryCaption,
			created:	slidesEntryCreated,
			wiki:		slidesEntryWikipedia
		});
	}

	if(MaximumImages > 0)
	{
		LoadSlideshowImages(0);

		if(MinimumSlide == 0)
			LoadSlideshowMap();

		ShowPoint(0);
		//Debug(PhotoWidth, PhotoHeight, ImageObject);
	}
}

function ScreenDimension()
{
	var Dimensions = new Array(2);
	var Width = 0;
	var Height = 0;

	if(self.innerHeight)
	{
		Width = self.innerWidth;
		Height = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight)
	{
		Width = document.documentElement.clientWidth;
		Height = document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		Width = document.body.clientWidth;
		Height = document.body.clientHeight;
	}

	Dimensions[0] = Width;
	Dimensions[1] = Height;

	return Dimensions;
}