/*
 * @title lightBoxGallery.js
 * @description YUI-LightBoxGallery script for use with goCommunity CommunityContentManagementSystem
 * @author Markus Prokscha <markus.prokscha@go-community.de> BLACKBIT interactive GmbH <info@go-community.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:6
		}
	};
} // 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;
			//alert("lightBoxGalleryTitle: " + lightBoxGalleryTitle);
			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];
				//alert("description: " + description.firstChild.nodeValue);
				html += '<a href="javascript:;">';
				html += '<img src="/blobs/'+currentPhoto.getAttribute('tnfile')+'" ';
				html += 'longdesc="/blobs/' + currentPhoto.getAttribute('file') + '" ';
				html += 'title="' + lightBoxGalleryTitle + '" ';
				html += 'alt="' + description.firstChild.nodeValue + '" ';
				html += 'class="lightBox" />';
				html += '<title>' + description.firstChild.nodeValue + '</title>';
				html += '</a>';
				divContainer.innerHTML += html;
			}
			divContainer.innerHTML += '<span id="' + lightBox + 'Ready"></span>';
		}
	}

	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);

}