$(document).ready(function(){
	var ktSTtrona=$('#ktSTtrona').val();
	SzerokoscWysokosc();
	opM=0.3;
	opF=0.8;
	if (ktSTtrona==0) {
		rotator();
		$('#PaskiFoto div').css({ "position":"absolute", "top":"0px", "left":"0px" });
		$("#PaskiFoto div:nth-child(5)").animate({ 
	        left: "565px"
	      }, 1000, "linear", function(){
				$(this).fadeTo("slow", opM);
				$("#PaskiFoto div:nth-child(4)").animate({ 
		        left: "424px"
		      }, 1000, "linear", function(){
					$(this).fadeTo("slow", opM);
					$("#PaskiFoto div:nth-child(3)").animate({ 
			        left: "283px"
			      }, 1000, "linear", function(){
						$(this).fadeTo("slow", opM);
						$("#PaskiFoto div:nth-child(2)").animate({ 
				        left: "142px"
				      }, 1000, "linear", function(){
							$(this).fadeTo("slow", opM, function(){
								$("#PaskiFoto div:nth-child(1)").fadeTo("slow", opM, function(){
									$("#PaskiFoto div:nth-child(5)").fadeTo(500, opF);
									$("#PaskiFoto div:nth-child(4)").fadeTo(1500, opF);
									$("#PaskiFoto div:nth-child(3)").fadeTo(2500, opF);
									$("#PaskiFoto div:nth-child(2)").fadeTo(3500, opF);
									$("#PaskiFoto div:nth-child(1)").fadeTo(4500, opF);
							});
						});
					});
				});
			});
		});
	} else if (ktSTtrona==6) {
		$("#Zawartosc img").fadeTo(1800, opF);
	} else if (ktSTtrona==8) {
		$("#Zawartosc img").fadeTo(1800, opF);
	}
	
}); 
var headline_interval;
var oIle;
var lewo=0;
function Przesun(oIle, gdzie, co) {
	var lef=$("#inDaZd").scrollLeft();
	lewo =parseInt($('#inDaZd').css('left'), 10);
	if (gdzie=='left') {
		headline_interval=setInterval("PrzesunA("+oIle+","+co+")",0);
	} else {
		headline_interval=setInterval("PrzesunB("+oIle+","+co+")",0);
	}
	
}
function PrzesunA(c, co) {
	lewo=lewo+c;
	$("#inDaZd").animate({left: lewo +'px'});	
}
function PrzesunB(c, co) {
	lewo=lewo-c;
	$("#inDaZd").animate({left: lewo +'px'});	
}

function SzerokoscWysokosc() {
	$('#Zawartosc').width(($(window).width()-200));
}

function Przycmij(obj, ile) {
	$(obj).fadeTo("fast", ile);
}
function TloButt(obj, ile) {
	if (ile==1) {
		$('#wyslij').css( "color", "#000000" );
		$(obj).fadeTo("slow", 1);
	} else {
		$('#wyslij').css( "color", "#ffffff" );
	  	$(obj).fadeTo("fast", 0);
	}
}

function rotator() {
	var ile=50;
	dod=' onmouseover="Przycmij(this, 1);" onmouseout="Przycmij(this, 0.8);"';
	t = new Array('<div id="Foto1"'+dod+'>&nbsp;</div>','<div id="Foto2"'+dod+'>&nbsp;</div>','<div id="Foto3"'+dod+'>&nbsp;</div>','<div id="Foto4"'+dod+'>&nbsp;</div>','<div id="Foto5"'+dod+'>&nbsp;</div>');
	t.sort( function() {return 0.5 - Math.random()} );
	var t=implode('',t);
	$('#PaskiFoto').html(t);
}

function ZamknijGalerie() {
	$("#Galeria").animate({ 
        opacity:0,
		  width:"1px",
		  height:"1px"
      }, 1000, "linear", function(){
		$('#Galeria').css("display", 'none');
		$("#Szarosc").animate({
			opacity:0
		}, 1000, "linear", function() {
			$('#Szarosc').css("display", 'none');
		});
	});
}	


function PokazGalerie(jaka, scale) {
	
	if (!scale)
		scale = false;
	
	$('#Szarosc').css("display", 'block');
	$("#Szarosc").animate({
			opacity:0.8
		}, 1000, "linear", function() {
			$('#Galeria').css({opacity:1,width:"100%", height:"100%","display":'block'});
			$('#Galeria').html('<img src="./img/ajax-loader.gif" alt="ładuję galerię" id="ajaxLoading" />');
			$('#ajaxLoading').center(true);
			$.ajax({
				type: "POST",
				data: ({'co' : jaka}),
				url: './gtg.php',
				dataType: "html",
				error:function(msg){
					alert( "Błąd. Proszę zgłosić Administratorowi" + msg );
				},
				success:function(msg){
				  $('#Galeria').html(msg);
				  heih=$(window).height();
				  szry=(600*heih)/570;
				  heu=(400*szry)/600;
				  $('#KilkaFot').css("width", (szry+60)+'px');
				  $('.ad-gallery').css("width", szry+'px');
				  $('.ad-image-wrapper').css("height", heu+'px');
				  $('.ad-image').css({"height":heu+'px', "width":szry+'px'});
				  
				  if (!scale) {
				  	$('.ad-image img').height(heu);
				  	$('.ad-image img').width(szry);
				  }
					
				  //$('#KilkaFot').center();
				  //marg=(parseInt($('#KilkaFot').css('marginTop'), 10)+50);
				  //	alert(marg);
				  //$('#KilkaFot').css({"margin-top":marg+'px'});
				}
			});
		});
}

function UkryjFote(oF,Fo) {
	for (i=oF;i<Fo+1;i++) {
		id='#zdjecienr'+i;
		if ($(id).css("top")=='5px') {
			$(id).css("top","300px");
		}
		
	}
}

function AjaGetCont(coto, lol, lang) {
	$.ajax({
		type: "POST",
		data: ({'co' : coto, 'jz' : lang}),
		url: './gtg.php',
		dataType: "html",
		error:function(msg){
			alert( "Błąd. Proszę zgłosić Administratorowi" + msg );
		},
		success:function(msg){
			$(lol).html(msg);
		}
	});
}

function implode (glue, pieces) {
    return ( ( pieces instanceof Array ) ? pieces.join( glue ) : pieces );
}

jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        '40%', 
            zIndex:        '110'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

//setTimeout("rotator()",1*1000);
