function pokaz(EL, CONTENT)
{
	$.ajax(
	{
		type: "GET",
		url: "pokaz/id/"+CONTENT+"/type/ajax/",
		beforeSend: function(req)
		{
	        $("#panel_right").html("<div style='text-align: center;line-height: 400px;font-size: 150%;'>proszę czekać...</div>");
	        
		    EL.blur();
		},
		success: function(data)
		{
			$("#panel_right").hide("slide", { direction: "top" }, 500, function callback()
			{
				$("#panel_right").html(data);
        		$("#panel_right").show("slide", { direction: "top" }, 500);
			});
		}
	});
	
}

$.fn.setFocus = function(e)
{
	if (document.getElementById(e)) document.getElementById(e).focus();
	return this;
};

$.fn.ajaxSubmit = function(e) 
{ 
	/* Change a form's submission type to ajax */ 
	this.submit(function()
	{ 
		var params = {}; 
		$(this).find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea").filter(":enabled").each(function() 
		{
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
		
		params["ajax"] = true;
		document.getElementsByClassName("sad");
		$("body").addClass("curWait"); 
		
		$.post(this.getAttribute("action") + "", params, function(xml)
		{
			$("body").removeClass("curWait");
			strError = "Nie udało się wysłać formularza. Proszę spróbować później.";
			oFocus = null;
			
			$("AjaxResponse", xml).each(function() 
			{
				strRedirect = this.getAttribute("redirecturl"); 
				strError = this.getAttribute("error"); 
				oFocus = this.getAttribute("focus"); 
			}); 
			
			if (strError.length == 0) 
			{
				//window.location = strRedirect;
				$("form").html("<div style='height: 50px;line-height: 50px;text-align: center;'>Zapytanie zostało poprawnie wysłane.<br />Postaram się jak najszybciej odpowiedzieć.<br />Pozdrawiam!<br />Michał Schroeder</div>");
				$("div#formErrors").removeClass("formErrors");
				$("div#formErrors").addClass("formInfo");
				$("div#formErrors").css("display", "none");
			}
			else
			{
				$("div#formErrors").removeClass("formInfo");
				$("div#formErrors").addClass("formErrors");
				$("div#formErrors").html("<h3>Błędy w formularzu<\/h3><ul>" + strError + "<\/ul>").filter(":hidden").fadeIn("normal"); 
				if (oFocus)
				{
					$("#" + oFocus).get(0).focus(); 
				}
			}
		}); 
			
		return false; 
	});
	
	return this; 
}

function getPortfolio(SITE, DIRECTION)
{
	$.ajax(
	{
		type: "GET",
		url: "strona/pokaz/"+SITE+"/type/type/ajax/rand/666666/",
		beforeSend: function(req)
		{
			$("#portfolio3").fadeOut(500, function callback() {
				$("#portfolio3").html("<div style='text-align: center;line-height: 380px;font-size: 150%;'>proszę czekać...</div>");
			});
		},
		success: function(data)
		{
			$("#portfolio3").hide("slide", { direction: DIRECTION }, 500, function callback() 
			{
				  	$("#portfolio3").html(data);
        			$("#portfolio3").show("slide", { direction: DIRECTION }, 500, function callback() 
        			{
        				if ($("#nextSite").text() == 1)
        				{
        					$("#page_down_link").css("visibility", "hidden");
        				}
        				else
        				{
        					$("#page_down_link").css("visibility", "visible");
        				}
        				
        				addPortfolioListner();
        			});
			});
			
		}
	});
}

function addPortfolioListner()
{
	$(".portfolio").click(function(e)
	{
		var documentHeight = $(document).height();
		var windowHeight = $(window).height();
		var windowWidth = $(window).width();
		$("#lightbox").css("height", documentHeight +"px");
		
		$(".portfolioBig").hide();
		var id = $(this).attr("title");
		
		$("#lightbox").css("filter", "alpha(opacity=70)");
		
		var html = $("#numer"+id).html();
		$("#popup").html(html);
		
		var height = (($(window).height() + $(window).scrollTop()) - $("#popup").height())/2 + $(window).scrollTop()/2;
		var width = (($(window).width() + $(window).scrollLeft()) - $("#popup").width())/2 + $(window).scrollLeft()/2;
		$("#popup").css("top", height+"px");
		$("#popup").css("left", width+"px");
		
		$("#lightbox").show("scale", {  }, 500, function(){
			$("#popup").show("clip", { direction: "vertical" }, 500, function(){
				
			});
		});
		
		$("#popup span").hover(
			function(){ $(this).css("cursor", "pointer"); $(this).css("cursor", "hand"); },
			function(){ $(this).css("cursor", "auto"); }
		);
		
		$("#popup span").click(function(e)
		{
			$(this).parent().parent().hide("clip", { direction: "vertical" }, 500,  function(){
				$("#lightbox").fadeOut(500);
			});
			
			return false;
		});
		
		$(".close_icon span").hover(
			function(){ $(this).css("cursor", "pointer"); $(this).css("cursor", "hand"); },
			function(){ $(this).css("cursor", "auto"); }
		);
		
		$(".close_icon span").click(function(e)
		{
			$(this).parent().parent().hide("clip", { direction: "vertical" }, 500,  function(){
				$("#lightbox").fadeOut(500);
			});
			
			return false;
		});
		
		$(".portfolio").css("height", "118px");
		
		return false;
	});
}

$(document).ready(function()
{
	$("#menu div").css("visible", "hidden");
	$("#logo_mirror").css("visible", "hidden");
	$("#kontaktForm").ajaxSubmit(); 
	
	if ($(".portfolio").length > 0)
	{
		addPortfolioListner();
	}
	if ($("#page_down_link"))
	{
		$("#page_down_link").click(function(e)
		{
			SITE = $("#page_down_link").attr("title");
			$("#page_down_link").attr("title", SITE+1);
			$("#page_up_link").attr("title", SITE-1);
			
			if (SITE >= 1)
			{
				$("#page_up_link").css("visibility", "visible");
			}
			
			getPortfolio(SITE, "down");
			$("#page_down_link").blur();
			
			return false;
		});
	}
	if ($("#page_up_link"))
	{
		$("#page_up_link").click(function(e)
		{
			SITE = $("#page_up_link").attr("title");
			next = ++SITE;
			--SITE;
			$("#page_down_link").attr("title", next);
			
			if (SITE > 1)
			{
				$("#page_up_link").attr("title", SITE);
			}
			else
			{
				$("#page_up_link").css("visibility", "hidden");
			}
			
			getPortfolio(SITE, "up");
			$("#page_up_link").blur();
			
			return false;
		});
	}
	
	$("#menu > div").show("slide", { direction: "up" }, 500);
	$("#logo_center_middle > div").show("slide", { direction: "left" }, 500);
	
});
