function showTitle()
{
	$('gallery_photoTitle').tween('opacity', [0, 0.7]);
}
 
function hidePhoto(all)
{ 
	if(all == 1)
	{
		$('galleryTop').tween('opacity', [0.92, 0]);
		$('gallerySplash').tween('opacity', [0.92, 0]);
		$('galleryTop').innerHTML = '';
	}
	
	if(all == 2)
	{
		//$('galleryTop').tween('opacity', [0.92, 0]);
	}
	
	$('gallerySplash').innerHTML = '';
}

function showPhoto(link, act, img, all)
{
	var pos = getScrollXY();
	
	var next = Number(act) + 1;
	var prev = Number(act) - 1;
	
	if(prev < 0 ) prev = 0;
	if(next >= galleryTab.length) next = 0;
	
	if(!$('gallerySplash'))
	{
		var gallerySplash = new Element('div', {id: 'gallerySplash', onclick: "javascript:hidePhoto();"});
		$(document.body).adopt(gallerySplash);
				
		var galleryTop = new Element('div', {id: 'galleryTop', onclick: "javascript:hidePhoto();"});
		$(document.body).adopt(galleryTop);		
	}
	//$('galleryTop').set('html', "<img class='loader' src='/imgMenu/ajax-loader.gif' />");
	
	
	//var h = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight);
	var h = document.body.offsetHeight;
	
	var pos = getScrollXY();
		
	$('gallerySplash').setStyle('marginTop', '-' + h + 'px');
	$('gallerySplash').setStyle('height', h + 100 + 'px');
	
	if(!all)
	{
		$('gallerySplash').tween('opacity', [0, 0.92]);
	}
	
	$('galleryTop').setStyle('marginTop', '-' + h + 'px');
	$('galleryTop').setStyle('height', h + 100 + 'px');
	$('galleryTop').tween('opacity', [0, 1]);

	var h2 = pos[1] + 50;
	$('gallerySplash').set('html', "<img style='padding-top: "+ h2 +"px;' src='/imgMenu/ajax-loader.gif' />");
	
	var img = new Element('img', {'src': link + galleryTab[act], 'id': 'photo_gallery', 'alt': ''});
	
	var code = '<div id="photoBox" onclick="hidePhoto(1);"></div>';
	code += '<div id="gallery_photoTitle"><a href="#" onclick="hidePhoto(2); showPhoto(\''+ link +'\', \''+prev+'\', \'photoBox\', 1); return false;">';
	code += '&laquo;&laquo; wstecz</a> | <a href="'+ link + galleryTab[act] +'" title="Link do zdjęcia '+ img.alt +'">pobierz plik</a>';
	
	var num = Number(act) + 1;
	
	code += '| ' + num + ' / ' + galleryTab.length;
	code += ' | <a href="#" onclick="hidePhoto(1)">zamknij</a>';
	code += ' | <a href="#" onclick="hidePhoto(2); showPhoto(\''+ link +'\', \''+next+'\', \'photoBox\', 1); return false;">dalej &raquo;&raquo;</a>';
	code += '</div>';

	$('galleryTop').set('html', code);

	$('photoBox').adopt(img);
	
	$('photo_gallery').setStyle('border', '1px solid orange');
	$('photo_gallery').setStyle('marginTop', pos[1] + 30 + 'px');
	
	showTitle.delay(200, []);
				
	//loadPhoto(link + galleryTab[act], 'photoBox');
	
	$('gallery_photoTitle').setStyle('opacity', 0);
	
	return false;
}

//alert(document.body.scrollWidth)

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

/*
function loadPhoto(link, dest)
{ 
	var pos = getScrollXY();
	
	//x=new Image;
	//x.src=link;

		
	advAJAX.post({
	   //  url: "/ajaxRequest.php",
		'url': link,
		'link' : link,
	
		onInitialization : function(obj) {
			document.getElementById(dest).innerHTML = "<img class='loader' src='/imgMenu/ajax-loader.gif' />";
		},
		onSuccess : function(obj) {
				document.getElementById(dest).innerHTML = "<img id='photo_gallery' src='"+ link +"' />"; 
				//$('photo_gallery').tween('width', [1, x.width]);
				$('photo_gallery').setStyle('marginTop', pos[1] + 100 + 'px');
				showTitle.delay(200, []);				
				
				return false;
		
			},
		onRetry : function(obj) {
		document.getElementById(dest).innerHTML = "<img class='loader' src='/imgMenu/ajax-loader.gif' />"; 
		},
		onRetryDelay : function(obj) { 
		document.getElementById(dest).innerHTML = "<img class='loader' src='/imgMenu/ajax-loader.gif' />"; 
		},
		onError : function(obj) { 
		document.getElementById(dest).innerHTML = "Błąd w połączeniu."; 
		}
	});
}
*/
