/*
            _    _
 _ __   ___| |_ (_) __ _ _ __ ___
| '_ \ / _ \ __|| |/ _` | '_ ` _ \
| | | |  __/ |_ | | (_| | | | | | |
|_| |_|\___|\__|/ |\__,_|_| |_| |_|
              |__/

This lightbox code is (C)2007 NetJam and cannot be used without permission.

*/


function showInLightbox(url,title)
{

	showLightbox(title,'');


	new Ajax.Request(url, {
  	method: 'get',
  	onSuccess: function(transport) {

	setLightboxContent(transport.responseText);
  	}
	});

	return false;
}

function showInExistingLightbox(url,title)
{

//	showLightbox(title,'');

	$('Lightboxcontent').style.backgroundColor = '#46446e';
	Effect.Fade('LightboxImg',{queue: 'end', duration: 0.4});

	title = '<p>' + title + '</p><div id="Lightboxclose"><a alt="Sluiten" title="Sluiten" href="javascript:closeLightbox();">X</a></div>'

	$('Lightboxhead').update(title);



	new Ajax.Request(url, {
  	method: 'get',
  	onSuccess: function(transport) {

	setExistingLightboxContent(transport.responseText);
  	}
	});

	return false;
}



function setLightboxContent(content)
{

	/* Remove loading */
	$('Lightboxcontent').removeClassName('loadingLightbox');

	/* Add content */
	//$('Lightboxcontent').hide(); // Hide temporary

	$('Lightboxcontent').update(content); // Add HTML
	//Effect.Appear('Lightboxcontent',{queue: 'end', duration: 0.4}); // Show in effect
}


function setExistingLightboxContent(content)
{
	$('Lightboxcontent').update(content); // Add HTML

	Effect.Appear('LightboxImg',{queue: 'end', duration: 0.4});
}


function showLightbox(title,content)
{

	/* Define height & width of lightbox */
	var height = 550;
	var width = 610;


	/* Get scroll height */
	var scrollWidth;
	var scrollHeight;

	if (self.pageYOffset) // all except Explorer
	{
		scrollWidth = self.pageXOffset;
		scrollHeight = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		scrollWidth = document.documentElement.scrollLeft;
		scrollHeight = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		scrollWidth = document.body.scrollLeft;
		scrollHeight = document.body.scrollTop;
	}


	/* Set some stuff */
	var html 	= "<div id='Lightboxhead'><p>"+title+"</p><div id='Lightboxclose'><a alt='Sluiten' title='Sluiten' href='javascript:closeLightbox();'>X</a></div></div><div id='Lightboxcontent'>"+content+"<div id='LightboxError'>&nbsp;</div></div>";
	var left 	= Math.round(  (windowWidth - width)/2  );
	var top 	= Math.round(  ((windowHeight - height)/2) + scrollHeight );



	/* Darken the screen */
	darkScreen(scrollHeight);

	/* Show lightbox*/
	Element.extend('Lightbox'); // Extend
	$('Lightbox').setStyle({left: left+'px', top: top+'px', height: height+'px'}); // Set in middle
	$('Lightbox').update(html); // Place content

	Effect.BlindDown('Lightbox', { queue: 'end' });

	/* Make draggable */

	/*

	NOT !

	new Draggable('Lightbox',{handle:'Lightboxhead',
    snap: function(x,y) {
      return[
        x<( (pageWidth + scrollWidth) - width - 5) ? (x > 0 ? x : 5 ) : ( (pageWidth + scrollWidth) - width - 5),
        y<( (windowHeight + scrollHeight) - height - 5) ? (y > 0 ? y : 5) : ( (windowHeight + scrollHeight) - height - 5 )];
    }

	});

	*/

	/* Show lightbox content loading gif*/
	Element.extend('Lightboxcontent');
	$('Lightboxcontent').addClassName('loadingLightbox');


	//$('Lightbox').show();



	//$('Lightbox').removeClassName('hiddenLightbox');
	//$('Lightbox').addClassName('visibleLightbox');






//	$('Lightbox').scrollTo();

}

function closeLightbox()
{
	//Effect.Fade('Lightboxcontent',{queue: 'end', duration: 0.2, queue: 'end'});
	Effect.BlindUp('Lightbox',{queue: 'end', duration: 0.4, afterFinish: function(){lightScreen();}});
	//$('Lightbox').update("&nbsp;");
	//lightScreen();
}


function checkLightbox(field,error)
{
	if(Form.Element.getValue(field) == "")
	{
		Element.extend('LightboxError');
		$('LightboxError').update(error);
		return false;

	}
	else
	{
		return true;

	}
}


function darkScreen(scrollHeight)
{
	if(windowHeight > pageHeight) { height = windowHeight  }
	else { height = pageHeight }

	//height = height + scrollHeight;


	$('lightboxoverlay').setStyle({width: '100%',height: height+'px'});
	$('lightboxoverlay').show();

}

function lightScreen()
{
	$('lightboxoverlay').setStyle({width: '1px',height: '1px'});
	$('lightboxoverlay').hide();
}


