function startGallery(number, gal_id)
{
	if (typeof(number)=="undefined" || number === Number.NaN)
		var number = 0;
	
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	
	var arrayPageSize = getClientXY();
	$('overlay').show();
	$('overlay').style.visibility = 'visible';
	$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	
	// duration & opacity hardcoded
	new Effect.Appear($('overlay'), { duration: 0.2, from: 0.0, to: 0.8 });
	
	var arrayPageScroll = document.viewport.getScrollOffsets();
	var lightboxTop = arrayPageScroll[1] +25 /*+ (document.viewport.getHeight() / 20)*/;
	var lightboxLeft = arrayPageScroll[0] +25 /*+ (document.viewport.getWidth() / 20)*/;
	$('lightbox').setStyle({ top: lightboxTop + 'px', left: lightboxLeft + 'px' });
	
	var cliwh = getCliWH();
	$('lightbox').setStyle({ width: cliwh[0]-50 + 'px', height: cliwh[1]-50 + 'px' });
	
	$('lightbox').show();
	$('lightbox').style.visibility = 'visible';
	
	$('lightbox_close').setStyle({ top: arrayPageScroll[1]+'px' });
	$('lightbox_close').show();
	$('lightbox_close').style.visibility = 'visible';
	
	showSimpleGallery(number, gal_id);
	
	return false;
}

function getCliWH()
{
	if (self.innerHeight)
		return [self.innerWidth, self.innerHeight];
	else if (document.documentElement && document.documentElement.clientHeight)
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	else
		return [document.body.clientWidth, document.body.clientHeight];
}

function stopGallery()
{
	$('lightbox').hide();
	$('lightbox_close').hide();
	new Effect.Fade($('overlay'), { duration: 0.2 });
	
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
}

function showSimpleGallery(number, gal_id)
{
	var fo = new SWFObject('/bin/FlashGallery/SimpleViewer/viewer.swf', 'viewer', '100%', '100%', '8', '#181818');
	fo.addVariable('xmlDataPath', simpleViewerXmlDataPath+"%26gal_id="+gal_id);
	fo.addVariable('firstImageIndex', number);
	fo.write('lightbox');
}

function getClientXY()
{     
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) // all except Explorer
	{
		if(document.documentElement.clientWidth)
			windowWidth = document.documentElement.clientWidth;
		else
			windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
		
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
		pageHeight = windowHeight;
	else
		pageHeight = yScroll;
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
		pageWidth = xScroll;	
	else
		pageWidth = windowWidth;
	
	return [pageWidth,pageHeight];
}

