function adres(odnosnik) {
	window.location = odnosnik;
}
function otworz_duze(url) {
	window.open(url,'','settings=fullscreen,location=no,directories=no,menubar=no,toolbar=no,status=yes,scrollbars=yes,resizable=yes,dependent=no');
}
function ajax(dzial,akcja,przesuniecie) {
	var nazwa_sekcja_html = $("div#"+akcja).prev().html();	
	$("div#"+akcja).prev().text('Trwa aktualizacja');
	$("div#"+akcja).css("opacity",0.3);
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "dzial="+dzial+"&element="+akcja+"&offset="+przesuniecie,
		success: function(msg){
			$("div#"+akcja).prev().html(nazwa_sekcja_html);
			$("div#"+akcja).css("opacity",1).html(msg);
			$('a').click(
				function(){
					if($(this).attr("href")!=undefined) {
						ladowanie("pokaz","body");
					}
				}
			);
			$('.zoomme img').mouseover(
				function(){
					var element = this;		
					if(($("body").width()/2)<$(this).offset().left) {
						$(element).bind("mouseout", function(){
							pokaz_zdjecie("schowaj","","","prawa");
						});
						interval = setInterval(function() {
							pokaz_zdjecie("pokaz",$(element).attr('rel'),$(element).attr('name'),"lewa");					
							clearInterval(interval);
						}, 300);
					}
					else {
						$(element).bind("mouseout", function(){
							pokaz_zdjecie("schowaj","","","lewa");
						});					
						interval = setInterval(function() {
							pokaz_zdjecie("pokaz",$(element).attr('rel'),$(element).attr('name'),"prawa");					
							clearInterval(interval);
						}, 300);
					}
				}
			);
			$('.zoomme img').mouseout(
				function(){
					clearInterval(interval);
				}
			);			
		}
	});
}
function pokaz_zdjecie(akcja,adres,opis,pozycja) {
	if(akcja=="pokaz") {
		$("body").append("<div id='pokaz_zdjecie_"+pozycja+"'></div>")		
		var img = document.createElement('img');
		img.onload = function(){
			$("div#pokaz_zdjecie_"+pozycja+"").html("<img id='pokaz_zdjecie_zdjecie' src='"+adres+"' alt=''/><div id='pokaz_zdjecie_opis'>"+opis+"</div>").slideDown('slow');
			var that = this;
			$('#pokaz_zdjecie_zdjecie').click(
				function(){
					$("div#pokaz_zdjecie_"+pozycja+"").remove();
				}
			);
		}
		img.src = adres;
	}
	else if(akcja=="schowaj"){
		$("div#pokaz_zdjecie_lewa").remove();
		$("div#pokaz_zdjecie_prawa").remove();		
	}
}
function ladowanie(akcja,gdzie) {
	if(akcja=="pokaz") {
		$(gdzie,"html").css({height: "100%", width: "100%"});
		$(gdzie).prepend("<div id='ladowanie'><div id='ladowanie_tekst'>Proszę czekać</div></div>");
		$('#ladowanie').css('opacity',.75).show();
		pokaz_zdjecie("schowaj","","","");
	}
	else if(akcja=="schowaj") {		
		$('#ladowanie').fadeOut('fast',function(){
			$('#ladowanie').remove();
		});
	}
}