function openOkno(link, wysokosc, szerokosc) {
window.open(link, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,fullscreen=no,channelmode=no,width='+wysokosc+',height='+szerokosc+',top=30,left=30');
}

function drukuj()
{
if(!window.print)
{
alert ("Nie zainstalowano drukarki");
return 0;
}
window.print();
}

var stan; 
function PokazUkryj(nazwa) { 
stan=(document.getElementById(nazwa).style.display=="none")?true:false; 
document.getElementById(nazwa).style.display=(stan)?"block":"none"; 
document.getElementById('szt').value == 1
}  

function checkLength(f, len)
{
if(f && f.value.length<len)
{
f.value = f.value.substring(0, len);
a = f.value.length;
b = 200;
c = b-a;
document.getElementById('charCount').innerHTML = c;
}
else
{
alert('Przekroczono dozwoloną liczbę znaków!!!');
}
} 


$(document).ready(function() {


$(".mieszkanie").hover(function(){
	var id = $(this).attr("id");
	$.post('sub/oferta-ajax.php', {zJSa: id}, function(data){
		$("#dystr-opis-box").empty();
		$("#dystr-opis-box").detach();
		$("#content").append('<div id="dystr-opis-box" style="display:none;">'+data+'</div>');
	});
	$(document).mousemove(function(e){
				$("#dystr-opis-box").fadeTo('slow', 0.8, function(){});
				$("#dystr-opis-box").css("top",(e.pageY+20)+"px");
				$("#dystr-opis-box").css("left",(e.pageX+20)+"px");
		});
}, function(){
	$("#dystr-opis-box").empty();
	$("#dystr-opis-box").detach();
});

$("body").mouseover(function(){
		$("#dystr-opis-box").empty();
		$("#dystr-opis-box").detach();
	});



$(function() {
		$("#tabs").tabs();
	});

$(".menu-item").hover(function(){
	$(this).animate({"opacity": 0.0},200,function(){
		$(this).css('background-image','url(./gfx/menu-hover.jpg)').animate({"opacity":1.0},1500);
	})
},
function(){
	$(this).animate({"opacity": 0.0},700,function(){
		$(this).css('background-image','').animate({"opacity":1.0},200);
	});
});


$(".a-button").hover(function(){
	$(this).animate({"opacity": 0.3},200).animate({"opacity":1.0},700);
},
function(){
	$(this).animate({"opacity": 0.3},200).animate({"opacity":1.0},700);
});


$(".checkLength").focus(function(){
		checkLength_($(this),150);
	});
	
	$(".checkLength").keydown(function(){
		checkLength_($(this),150);
		
	});

	function checkLength_(ob,len){
		
		if($(ob).val().length<len)
		{
		a = $(ob).val().length;
		b = len-1;
		c = b-a;
		$(".charCount", $(ob).parent().parent().parent()).empty();
		$(".charCount", $(ob).parent().parent().parent()).append(""+c+"");
		}
		else
		{
			alert('Przekroczono dozwoloną liczbę znaków!!!');
			$(ob).val($(ob).val().substring(0, len-1));
		}
	}

$(".box").hover(function(){
  $(this).animate({"top": "+=50px"}, 500).animate({"top": "-=10px"}, 200);
},function(){
  $(this).animate({"top": "-=40px"}, "slow");
});

$(".offer").hover(function(){
  $(".offer").animate({opacity: 0.5}, "slow");
  $(this).animate({
	opacity: 1.0,
	top: "-=10px"
	}, "slow");
  
},function(){
  $(".offer").animate({opacity: 1.0}, "slow");
  $(this).animate({
	top: "+=10px"
	}, "slow");
});





var obj = $(this);
var xPos = 0;
var yPos = 0;

var height = $(".offer-content").outerHeight();
var width = $(".offer-content").outerWidth();

var slidespeed = 500;
var slidecount = $(".offer-content").length;
var currslide = 1;


$(".offer-content").each(function(){
	$(this).css('top',yPos+'px');
	$(this).css('left',xPos+'px');
	yPos-=height;
	xPos+=width;
	
});

		/*
		 *	nawigacja slidera
		 */
		$("#arrow-right",obj).click(function(){
		currslide++;
			$(".offer-content",obj).each(function(index){
				var currLeft = $(this).css('left');
				currLeft = currLeft.substr(0,currLeft.length-2);
				
				if(currslide>slidecount){
					currslide=slidecount;
				}else{
					$(this).animate({left:(index*width)-((currslide-1)*width)},slidespeed,function(){});
				}
			});
			
			
		
		});
		
		$("#arrow-left",obj).click(function(){
			currslide--;
			$(".offer-content",obj).each(function(index){
				var currLeft = $(this).css('left');
				currLeft = currLeft.substr(0,currLeft.length-2);
				
				if(currslide<=0){
					currslide=1;
				}else{
					$(this).animate({left:(index*width)-((currslide-1)*width)},slidespeed,function(){});
				}
			});
			
		});
		/*
		 *	nawigacja koniec
		 */
		 
		 
	/*
	 * zmiana rozmiaru czcionki i druk
	 */
	$("#font-small").click(function(){
		$.post('sub/ciacha.php', {font: "small"}, function(data){location.reload();});
	});
	$("#font-mid").click(function(){
		$.post('sub/ciacha.php', {font: "mid"}, function(data){location.reload();});
	});
	$("#font-large").click(function(){
		$.post('sub/ciacha.php', {font: "big"}, function(data){location.reload();});
	});

	$("#print-link").click(function(){
	window.print();
	});
	/*
	 * zmiana rozmiaru czcionki - koniec
	 */
	 
	 
	 
	 
	 /*
	  * powiększanie fot
	  */
	  
	  $(".foto-realiz",obj).click(function(){ //powiększenie foty
	
			$("body",obj).append('<div id="bkd"></div><div id="foto-big"><a href="#" id="foto-close">X</a></div>');
			
			Fidx = $("img").index(this);
			
			if(Fidx>1 || (/*!$.support.noCloneEvent && */Fidx>0)){
				$("#foto-big",obj).append('<div class="span"><a href="#" id="foto-prev">&laquo;</a></div>');
			}else{
				$("#foto-big",obj).append('<div class="span"></div>');
			}
			
			$("#foto-big",obj).append('<div id="foto-mid"></div>');
			
					
			if(Fidx<$("img").size(this)-1){
				$("#foto-big",obj).append('<div class="span"><a href="#" id="foto-next">&raquo;</a></span>');
			}else{
				$("#foto-big",obj).append('<div class="span"></div>');
			}
			
			$("#foto-big",obj).append('<p id="foto-opis"></p>');
			
			$("#foto-mid").css('background','#900 url(\''+$(this).attr('src').substring(0,13)+'\') no-repeat center center');
			$("#foto-opis").append($(this).attr('alt'));
			
			
			$("#bkd").animate({opacity:0.0}, 10, function(){
				$(this).show().animate({opacity:0.7}, 500, function(){
					
				});				
			});
			
			$("#bkd").click(function(){
				closeFoto();
			});
			
			var imgTesting = new Image();

			function CreateDelegate(contextObject, delegateMethod)
			{
				return function()
				{
					return delegateMethod.apply(contextObject, arguments);
				}
			}

			function imgTesting_onload()
			{
				//alert(this.width + " by " + this.height);
				$("#foto-mid").css('width', imgTesting.width+'px');
				$("#foto-mid").css('height', imgTesting.height+'px');
				$("#foto-big").css('width', imgTesting.width+50+'px');
				$("#foto-big").css('height', imgTesting.height+50+'px');
				
				$("#foto-big").css('margin','-200px -'+$("#foto-big",obj).width()/2+'px auto');
				
				
				
				$("#foto-big").show('scale', {percent: 100},500,function(){
					var totalH = $(document).height()+50;
					$("#bkd").css('height',totalH+"px");
				});
				
				$("#foto-close").click(function(){
					closeFoto();
				}); 
				
				$("#foto-next").click(function(){
					Fidx = Fidx+1;
					NextOrPrev();
				});	
				
				$("#foto-prev").click(function(){
					Fidx = Fidx-1;
					NextOrPrev();
				});	
			}

			imgTesting.onload = CreateDelegate(imgTesting, imgTesting_onload);
			imgTesting.src = $(this).attr('src').substring(0,13);

	});
	
	
	
	
	
	function NextOrPrev(){//przewijanie fotek <prev next>
				
				var strTmp = $("img").get(Fidx);
				
				$("#foto-big").empty();
				$("#foto-big").append('<a href="#" id="foto-close">X</a>');
				
			if(Fidx>1|| (/*!$.support.noCloneEvent && */Fidx>0)){
				$("#foto-big",obj).append('<a href="#" id="foto-prev">&laquo;</a>');
			}else{
				$("#foto-big",obj).append('<div class="span"></div>');
			}
			
			$("#foto-big",obj).append('<div id="foto-mid"></div>');
			
			if(Fidx<$("img").size(this)-1){
				$("#foto-big",obj).append('<div class="span"><a href="#" id="foto-next">&raquo;</a><div class="span">');
			}else{
				$("#foto-big",obj).append('<div class="span"></div>');
			}
			
			$("#foto-big",obj).append('<p id="foto-opis">'+$(strTmp).attr("alt")+'</p>');
			
			$("#foto-mid").css('background','#000 url(\''+$(strTmp).attr("src").substring(0,13)+'\') no-repeat center center');
			

			
			
		var imgTesting = new Image();

			function CreateDelegate(contextObject, delegateMethod)
			{
				return function()
				{
					return delegateMethod.apply(contextObject, arguments);
				}
			}

			function imgTesting_onload()
			{
				//alert(this.width + " by " + this.height);
				$("#foto-mid").css('width', imgTesting.width+'px');
				$("#foto-mid").css('height', imgTesting.height+'px');
				$("#foto-big").css('width', imgTesting.width+50+'px');
				$("#foto-big").css('height', imgTesting.height+50+'px');
				
				$("#foto-big").css('margin','-200px -'+$("#foto-big",obj).width()/2+'px auto');
				
				$("#foto-opis").append($(this).attr('alt'));
					
				$("#foto-big").show('scale', {percent: 100},500,function(){
					var totalH = $(document).height()+50;
					$("#bkd").css('height',totalH+"px");
				});
				$("#foto-close").click(function(){
					closeFoto();
				}); 
				
				$("#foto-next").click(function(){
					Fidx = Fidx+1;
					NextOrPrev();
				});	
				
				$("#foto-prev").click(function(){
					Fidx = Fidx-1;
					NextOrPrev();
				});	
			}

			imgTesting.onload = CreateDelegate(imgTesting, imgTesting_onload);
			imgTesting.src = $(strTmp).attr("src").substring(0,13);
		}
	  
	   function closeFoto(){
			$("#foto-big").hide('scale',{percent: 0},500,function(){
				$("#foto-big").detach();
				$("#bkd").animate({opacity:0.0}, 500, function(){
					$(this).detach();
				});
			});
	   }
	  
	  /*
	   * powiększanie fot - koniec
	   */
});
