/*
 * @title lightBoxGallery.js
 * @description YUI-LightBoxGallery script for use with goCommunity CommunityContentManagementSystem
 * @author Markus Prokscha <markus.prokscha@blackbit.de> BLACKBIT neue Medien GmbH <info@blackbit.de>
 * @copyright BLACKBIT interactive GmbH 2007
 * @date 2007-12-07
 */

YAHOO.namespace ("lightBox.config");

function initLightBox(lightBox)
{
	YAHOO.lightBox.config[lightBox] = {
		display:{
			gallery:true
			//slideshow:true
		},
		transitions:{
			fade:0.6,
			size:0.6
		},
		window:{
			modal:true,
			dragable:true
		},
		easing:{
			global:YAHOO.util.Easing.easeBothStrong
		},
		position:{
			placement:"absolute"
		},
		connections:{
			url:"/photos.xml",
			type:"XML",
			callBack:YAHOO.Example.callBack
		},
		controls:{
			paging:true,
			pagingButtons:5
		}
	};
} // function

YAHOO.namespace ("Example");

YAHOO.Example.callBack = function(){
};

function initializeGallery(sUrl, lightBox)
{
	// setup filename to get via HttpXMLRequest
	var divContainer = document.getElementById(lightBox);
	//alert( YAHOO.lightBox.config["lightbox1"] );

	// create a callback object to handle the response, and pass an object literal to both success and failure handlers as the argument.
	var handleSuccess = function(o)
	{
		if (o.responseText !== undefined)
		{
			var xml = o.responseXML;
			//document.getElementById( 'status1' ).innerHTML = "ok!";
			var someTitle = xml.getElementsByTagName('title');
			//var lightBoxGalleryTitle = someTitle[0].firstChild.nodeValue;
			var someGalleryTitle = xml.getElementsByTagName('galleryTitle');
			var lightBoxGalleryTitle = someGalleryTitle[0].firstChild.nodeValue;
			//alert("lightBoxGalleryTitle: " + lightBoxGalleryTitle);
			lightBoxGalleryTitle = lightBoxGalleryTitle.replace('~ae~', '&auml;');
			lightBoxGalleryTitle = lightBoxGalleryTitle.replace('~Ae~', '&Auml;');
			lightBoxGalleryTitle = lightBoxGalleryTitle.replace('~oe~', '&ouml;');
			lightBoxGalleryTitle = lightBoxGalleryTitle.replace('~Oe~', '&Ouml;');
			lightBoxGalleryTitle = lightBoxGalleryTitle.replace('~ue~', '&uuml;');
			lightBoxGalleryTitle = lightBoxGalleryTitle.replace('~Ue~', '&Uuml;');
			var photos = xml.getElementsByTagName('photo');
			var someDescription = xml.getElementsByTagName('description');

			for (var i=0; i < photos.length; i++)
			{
				var html = '';
				var currentPhoto = photos[i];
				var description = someDescription[i];
				var title = someTitle[i];
				var sTemp = currentPhoto.getAttribute('longdesc');
				//alert("description: " + description.firstChild.nodeValue);
				if (i < 5) {
					html += '<a class="galleryThumb" id="thumb' + i + '" href="javascript:;">';
				}
				else {
					html += '<a class="galleryThumb invisibleThumb" id="thumb' + i + '" href="javascript:;">';
				}
				
				html += '<img src="/blobs/'+currentPhoto.getAttribute('tnfile')+'" ';
				html += 'longdesc="/blobs/' + currentPhoto.getAttribute('file') + '" ';
				html += 'description="' + sTemp.replace('$$newline$$', '<br />') + '" ';
				html += 'title="' + lightBoxGalleryTitle + '" ';
				//html += 'title="' + description.firstChild.nodeValue + '" ';
				html += 'alt="' + sTemp.replace('$$newline$$', '<br />') + '" ';
				html += 'style="z-index: 10; border-left: ' + (189 - currentPhoto.getAttribute('tnwidth')) / 2 + 'px solid transparent; border-right: ' + (189 - currentPhoto.getAttribute('tnwidth')) / 2 + 'px solid transparent;" ';
				html += 'class="lightBox" />';

				html += '<div class="thumbnailCaption" style="z-index: 1;">' + title.firstChild.nodeValue + '<img class="magnifyingGlass" id="lightBoxThumb_' + i + '" src="/_images/lupe.gif"></div>';
				html += '<div class="clearing"></div>';
				//html += '<title>' + description.firstChild.nodeValue + '</title>';
				html += '<title>' + lightBoxGalleryTitle + '</title>';
				//html += '<description style="display: none;">' + description.firstChild.nodeValue + '</description>';
				html += '</a>';
				divContainer.innerHTML += html;
			}
			divContainer.innerHTML += '<span id="' + lightBox + 'Ready"></span>';
			divContainer.innerHTML += '<div class="spacer"></div>';
		}
	}

	var handleFailure = function(o)
	{
		if (o.responseText !== undefined)
		{
			//alert("failed");
			divContainer.innerHTML = "transaction failed";
		}
	}

	var callback =
	{
		success:handleSuccess,
		failure: handleFailure,
		argument: { foo:"foo", bar:"bar" }
	}

	// initiate the GET Transaction
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);

}