function zamknij_popup() {
	$('#maraton').fadeOut();	
	$('#maraton-tlo').fadeOut('slow');
}


function wyswietlPokaz(id) {
	
	//alert (innerHeight);
	
	var wysP  = innerHeight-10;
	var szerP = innerWidth-10;
	
	$("#galeria-pokaz").load("../../include/gallery/galeria-pokaz.php?id="+id+"", function() {
		$("#galeria-pokaz").fadeIn(); 															//ładuje tło
		$('#foto_1 img').attr('src', '../../upload_galery/'+id+'/'+realizacje[0][1]);			//ładuje pierwsze obrazki
		$('#foto_2 img').attr('src', '../../upload_galery/'+id+'/'+realizacje[1][1]);
		
		szerImg = $('#foto_1').width();
		wysImg = $('#foto_1').height();
			
		if(wysP < wysImg){													//dopasowanie wymiarów do ekranu
			
			$('#foto_1 img').height(wysP);
			//$('#foto_1 img').width($('#foto_1').height()*(szerImg/wysImg));
		}
		
		if(szerP < $('#foto_1').width()){
		
			$('#foto_1 img').width(szerP);
			//$('#foto_1 img').height($('#foto_1').width()*(wysImg/szerImg));
		}
		
		
		szerW = $('#foto_1').width();
		marginW = -(szerW/2)-10;
		szerH = $('#foto_1').height();
		marginH = -(szerH/2)-10;
		
		
		$('#foto_1').fadeIn();
		$('#foto_1').css('margin-left', marginW);
		$('#foto_1').css('margin-top', marginH);
		
		
		marginW = 0;
		marginH = 0;
		i = 2;
		a = 2;
		interval = setInterval(function(){
			if (a<realizacje.length){
			
				szerW = $('#foto_'+i).width();	
				marginW = -(szerW/2)-10;
				szerH = $('#foto_'+i).height();	
				marginH = -(szerH/2)-10;
				$('#foto_'+i).css('margin-left', marginW);
				$('#foto_'+i).css('margin-top', marginH);
				
				$('#foto_'+i).fadeIn();
				
					//alert(realizacje[i][1]);
					if (i==1){i=2;}
					else {i=1;};
				
				$('#foto_'+i).fadeOut(function(){
					$('#foto_'+i+' img').attr('src', '../../upload_galery/'+id+'/'+realizacje[a][1]);
					
					wysImg = $('#foto_'+i).height();
					szerImg = $('#foto_'+i).width();
					
					if (wysImg > szerImg){
					
						if(wysP<$('#foto_'+i).height()){
							$('#foto_'+i+' img').height(wysP);
							//$('#foto_'+i+' img').width(wysP*(szerImg/wysImg));
						}
						
						//alert ($('#foto_'+i).height()*(szerImg/wysImg));
						
						if(szerP<$('#foto_'+i).width()){
							$('#foto_'+i+' img').width(szerP);
							//$('#foto_'+i+' img').height($('#foto_'+i).width()*(szerImg/wysImg));
						}
						
					}
					
					else if (wysImg <= szerImg){
					
						if(wysP<$('#foto_'+i).height()){
							$('#foto_'+i+' img').height(wysP);
							//$('#foto_'+i+' img').width(wysP*(wysImg/szerImg));
						}
						
						//alert ($('#foto_'+i).height()*(szerImg/wysImg));
						
						if(szerP<$('#foto_'+i).width()){
							$('#foto_'+i+' img').width(szerP);
							//$('#foto_'+i+' img').height($('#foto_'+i).width()*(wysImg/szerImg));
						}
						
					}
					
					
					/*
					
											
						$(function () {      
						$('img').hide();//hide all the images on the page    
						});      
						var i = 0;//initialize    
						var int=0;//Internet Explorer Fix    
						$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded      
						var int = setInterval("doThis(i)",500);//500 is the fade in speed in milliseconds    
						});      
						function doThis() {      
						var images = $('img').length;//count the number of images on the page      
						if (i >= images) {// Loop the images        
						clearInterval(int);//When it reaches the last image the loop ends      
						}      
						$('img:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one      
						i++;//add 1 to the count    
						}  
											
					
					
					
					*/
					
					
					
				});
				++a;
				szer = 0;
				marginW = 0;
				marginH = 0;
			}
			
			else {
				zakonczPokaz();
			}
		},5000);
		
		$('#galeria-pokaz').click(function(){
			zakonczPokaz();
		});
		
	});
}

function zakonczPokaz() {
	clearInterval(interval);
	$('#galeria-pokaz').fadeOut();
	$('#foto_1').fadeOut();
	$('#foto_2').fadeOut();
}

$(document).ready(function() {
			/*
			*   Examples - images
			*/
			$("#shoutbox_okno").fancybox({
				'width'					: '40%',
				'height'				: '75%',
				'autoScale'				: false,
				'transitionIn'			: 'none',
				'transitionOut'			: 'none',
				'type'					: 'iframe'
			});
			
			$(".youtube").live("click",function() {
			$.fancybox({
					'padding'			: 0,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'title'				: this.title,
					'width'				: 680,
					'height'			: 495,
					'href'				: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'				: 'swf',
					'swf'				: {
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
					}
				});
		
			return false;
		});
			

				
				$("a[rel=fancybox]").fancybox({
					'transitionIn'		: 'fade',
					'transitionOut'		: 'fade',
					'titlePosition'		: 'over',

					'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
					},
					
					'onComplete'	:	function() {
						$("#fancybox-wrap").hover(function() {
							$("#fancybox-title").show();
						}, function() {
							$("#fancybox-title").hide();
						});
					}
				});


/*
			$("a#example1").fancybox();

			$("a.lightbox").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'	
			});

			$("a#example4").fancybox({
				'opacity'		: true,
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none'
			});

			$("a#example5").fancybox();

			$("a#example6").fancybox({
				'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.9
			});

			$("a#example7").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example8").fancybox({
				'titlePosition'	: 'over'
			});

			

			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			

			$("#various4").fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			}); 
			
			*/
		});
