/********************************************************************
*	vearbox image gallery handling script							*
*	Copyright (c) 2009 by Radosław Kołodziej <a.k.a. vear>			*
*	veareal,at,gmail,dot,com										*
*	DO NOT REDISTRIBUTE WITHOUT AUTHOR'S PERMISSION					*
********************************************************************/
prepared = false;
function setOpacity(object, value)
	{
		object.style.opacity = value;
		object.style.filter='alpha(opacity=\'' + value*100 + '\')';
	}
	
	function toggleWait()
	{
		if(document.getElementById('gallery-wait').style.visibility == 'hidden')
		{
			document.getElementById('gallery-wait').style.visibility = 'visible';
		}
		else
		{
			document.getElementById('gallery-wait').style.visibility = 'hidden';
		}
		return true;
	}
	
	function checkImageLoaded()
	{
		if(document.getElementById('gallery-shown').complete != true)
		{
			setTimeout('checkImageLoaded()', 500);
		}
		else
		{
			toggleWait();
			document.getElementById('gallery-shown').style.visibility = 'visible';
			setOpacity(document.getElementById('gallery-shown'), 0);
			for(i=1; i<=30; i++)
			{
				setTimeout('setOpacity(document.getElementById(\'gallery-shown\'), ' + i/30 + ')', 30*i);
			}
		}
	}
	
	function loadPhoto(filename)
	{
		if(!prepared)
		{
			document.getElementsByTagName('body')[0].innerHTML = '<div id="gallery-presentation-space"></div>' + document.getElementsByTagName('body')[0].innerHTML;
			prepared = true;
		}
		
		document.getElementById('gallery-presentation-space').innerHTML = '<div onclick="unloadPhoto();" id="gallery-body-cover" style="background-color: #000; width: ' + document.body.scrollWidth + 'px; height: ' + document.body.scrollHeight + 'px; position: absolute; z-index: 11; left: 0; top:0; opacity: 0.5; filter: alpha(opacity=50);"></div><div onclick="unloadPhoto();" id="gallery-present" style="background: transparent; width: 100%; height:100%; position: absolute; z-index: 12; left: 0; top:0; padding-top: ' + window.pageYOffset + 'px; text-align: center;"><img src="' + pathprefix + 'images/loading.gif" style="visibility: hidden" id="gallery-wait" alt="" /><div style="color: #fff; padding-bottom: 2em">' + clicktoclosenotice + '<br /><img id="gallery-shown" onclick="unloadPhoto();" style="background-color: #fff; position: relative; margin: 0.2em; border: 1px solid #ccc; visibility: hidden" src="' + pathprefix + 'images/galeria/' + filename + '" alt="" /></div></div>';
		toggleWait();
		checkImageLoaded();
	}
	function unloadPhoto()
	{
		document.getElementById('gallery-presentation-space').innerHTML = '';
	}