$(document).ready(function() {



var obj = $(this);


var windowH = $(window).height();//wysokość okna przeglądarki
var windowW = $(window).width();//szerokość 

var Fidx=0; //id fotki



$(".gwiazdka").click(function(){
	var g_id = $(this).attr("id").substring(6);
	$("#ocena").val(g_id);
	$(".gwiazdka-on").attr("class","gwiazdka");
	for(var j=1; j<=g_id; j++){
		$("#ocena-"+j).attr("class","gwiazdka-on");
	}
});

$(".gwiazdka-on").click(function(){
	var g_id = $(this).attr("id").substring(6);
	$("#ocena").val(g_id);
	$(".gwiazdka-on").attr("class","gwiazdka");
	for(var j=1; j<=g_id; j++){
		$("#ocena-"+j).attr("class","gwiazdka-on");
	}
});

	$(".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));
		}
	}



});

function popup(img){
	var obj = $(document);
	$("body",obj).append('<div id="bkd"></div><div id="foto-big"><a href="#" id="foto-close"></a></div>');
	
	$("#foto-big",obj).append('<div id="foto-mid"></div>');	
	
	$("#foto-big").css('background','none');
	$("#foto-close").css('color','#fff');
	$("#foto-mid").css('background','#900 url(\''+img+'\') no-repeat center center');
	
	
	
	$("#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();
				}); 
				
				
			}

			imgTesting.onload = CreateDelegate(imgTesting, imgTesting_onload);
			imgTesting.src = img;
	
	
	function closeFoto(){
			$("#foto-big").hide('scale',{percent: 0},500,function(){
				$("#foto-big").detach();
				$("#bkd").animate({opacity:0.0}, 500, function(){
					$(this).detach();
				});
			});
	   }
}
