$(document).ready( function() {
	if($("#dzial_content")) {
		makeAjax.start();
	}
//		var el = $(".navi_sel");
//		$.scrollTo(el, 0);
		if($("#pr_opened").length)
			$.scrollTo("#pr_opened", "normal");
});

var makeAjax = new Object({
	
	divH: "0", curr: "0", prdivH: "0", prev: "0",

	start: function() {

	$.listen('click','.pr_link',function() {  
		makeAjax.divH=$("#dzial_content").height();
		var content_show = $(this).attr("href"); 
		content_show = content_show.substring(1);
		var newHgL;
		$(".navi_sel").attr("class", "navi");
		$(this).css("color", "#e35f03");
		$.ajax({  
			method: "get",url: "index.php",data: content_show+'&ajax=1',  
			cache: false, 
			success: function(html){ 
				$("#dzial_content").fadeOut("slow", function() {
					$("#dzial_content").html(html);
					makeAjax.curr = $("#loaded_content").height();
					$("#dzial_content").height(makeAjax.divH);
					$("#dzial_content").animate({height: makeAjax.curr}, "slow");
					newHgL = $("#left").height() - makeAjax.divH + makeAjax.curr;
					$("#left").animate({height: newHgL}, "slow");
					$.getScript("js/galeria.js");
				}); 
				$("#dzial_content").fadeIn("slow");		
			}
		}); 
		return false;
	
	}); 

	$.listen('click','.pr_link2',function() {  
//		makeAjax.prdivH=$(this).parent().parent(".pr_content").height();
		makeAjax.divH=$("#dzial_content").height();
		var content_show = $(this).attr("href"); 
		content_show = content_show.substring(1);
		var newHgL;
		var el = $(this);
		if($("#pr_opened").height()>0) {
			$("#pr_opened").attr("id",'pr_closed');
			var c_show = $("#add_load").attr("title"); 
			makeAjax.prev = $("#pr_closed").height();
			$.ajax({  
				method: "get",url: "index.php",data: c_show+'&ajax=1',  
				cache: false, 
				success: function(html){ 
					$("#pr_closed").fadeTo("slow", 0.01, function() {
						$("#pr_closed").html(html);
						makeAjax.curr = 100;
						$("#dzial_content").css("height","auto");
						$("#pr_closed").animate({height: makeAjax.curr}, "slow", function() {
//							$.scrollTo("#pr_opened", "normal");
						});
						makeAjax.prdivH = -100;
					}); 
					$("#pr_closed").fadeTo("slow", 1, function() {	
						$("#pr_closed").attr("id",'pr');
					});
				}
			});  
		}
		$(this).css("color", "#e35f03");
		$.ajax({  
			method: "get",url: "index.php",data: content_show+'&ajax=1',  
			cache: false, 
			success: function(html){ 
				el.parent().parent(".pr_content").attr("id",'pr_opened');
				$("#pr_opened").fadeTo("slow", 0.01, function() {
					$("#pr_opened").html(html);
					makeAjax.curr = $(".pr_loaded_content").height();
//					if($.browser.msie && $.browser.version == '7.0')
//					{
//						makeAjax.curr = makeAjax.curr + 36;
//					}
					$("#dzial_content").css("height","auto");
					$("#pr_opened").animate({height: makeAjax.curr}, "slow", function() {
//						$.scrollTo("#pr_opened", "normal");
					});
					newHgL = $("#left").height() + makeAjax.curr - makeAjax.prev - 100 - makeAjax.prdivH;
//					alert(makeAjax.prdivH);
					$("#left").animate({height: newHgL}, "slow");
					$.getScript("js/galeria.js");
					$("#pr_opened").fadeTo("slow", 1, function() {
						$.scrollTo("#pr_opened", "normal");
					});
				}); 			
			}
		}); 
		
		return false;
	
	}); 

}

});