$(document).ready(
	function(){
		
		//RIGHT
		if($("#switchBox .news ul").children().is("li")){
			 $("#switchBox").children("a:first").show();
			 $("#switchBox h3").children("a:first").show();	 

			 if($("#switchBox .blog ul").children().is("li")){
			 	$("#switchBox h3").children("a:last").show();
				$("#switchBox h3").children("span").show();
			}
		}
		else if($("#switchBox .blog ul").children().is("li")){
			 $("#switchBox").children("a:last").show();
			 $("#switchBox h3").children("a:last").show();
			 $("#switchBox h3").children("a:last").removeClass("normal");
		}
		
		$("#switchBox h3").children("a:first").click(function(){
		 	$("#switchBox .news").show();
		 	$("#switchBox .blog").hide();
		 	$(this).removeClass("normal");
		 	$(this).next().next("a").addClass("normal");
		 	$("#switchBox").children("a:last").hide();
		 	$("#switchBox").children("a:first").show();
		 	return false;
		 })
		 
		 $("#switchBox h3").children("a:last").click(function(){
		 	$("#switchBox .news").hide();
		 	$("#switchBox .blog").show();
		 	$(this).removeClass("normal");
		 	$(this).prev().prev("a").addClass("normal");
		 	$("#switchBox").children("a:last").show();
		 	$("#switchBox").children("a:first").hide();
		 	return false;
		 })
		 
		 //INFO
		 
		 /*if($(".center-info .text").height() > 60){
		 	 $(".center-info .text").height(60);
		 	 $(".link_down.me").show();
		 }*/
		 
		 $(".profile .links a.more_info").click(function(){
		 	if($(this).html() == 'rozwiń'){
			 	$(".profile-hide").slideDown(1000);
			 	$(this).html("zwiń");
			 	$(this).removeClass("link_down");
			 	$(this).addClass("link_up");
		 	}
		 	else{
		 		$(".profile-hide").slideUp(1000);
		 		$(this).html("rozwiń");
		 		$(this).removeClass("link_up");
		 		$(this).addClass("link_down");
		 	}
		 	 return false;
		 })
		 
		 //automatyczne rozwiniecie
		/*$("#profil .profile-hide").slideDown(1000);
		$("#profil .links a.more_info").html("zwiń");
		$("#profil .links a.more_info").removeClass("link_down");
		$("#profil .links a.more_info").addClass("link_up");*/
		
		
		$(".profile .links a.more_me").click(function(){
		 	if($(this).html() == 'więcej o mnie'){
			 	$(".center-info").slideDown(1000);
			 	$(this).html("zwiń");
			 	$(this).removeClass("link_down");
			 	$(this).addClass("link_up");
		 	}
		 	else{
		 		$(".center-info").slideUp(1000);
		 		$(this).html("więcej o mnie");
		 		$(this).removeClass("link_up");
		 		$(this).addClass("link_down");
		 	}
		 	 return false;
		 })
		 
		 
		 
		 //tablica
		 $("#message-content").inputText({
			text : 'Zostaw wiadomość, dodaj komentarz do profilu...'
		 })
		
		 $("#message-content").autoResize({
				animate : false,
				animateDuration : 0,
    			extraSpace : 0
		 });
		 $("#message-content").focus(function(){
			if($(this).val() == '' || $(this).val() == 'Zostaw wiadomość, dodaj komentarz do profilu...'){	
				$("#message-submit").show();
			}
		});
		$("#message-content").blur(function(){
			if($(this).val() == '' || $(this).val() == 'Zostaw wiadomość, dodaj komentarz do profilu...'){
				$("#message-submit").hide();
			}
		});
		
		//nawigacja tablicy
		$("#center-column").initWallNavi();
	}	
);

(function($){
	
	jQuery.fn.extend({
		initWallNavi: function(){
			var container = $(this);
			if(container.find(".page_2").is("div")){
				container.find(".page-right").show();
				container.find(".page-left").show();
				container.find(".page-left").css({opacity:0.6});
			}
				
			container.find(".page-right").click(function(){if($(this).css("opacity") >= 1){container.nextPageWall()}; });
			container.find(".page-left").click(function(){if($(this).css("opacity") >= 1){container.prevPageWall()}; });
			
		},
		nextPageWall: function(){
			var actual = $(this).find(".pages:visible");
			actual.hide();
			actual.next().show();
			if(!actual.next().next().is(".pages"))
				$(this).find(".page-right").css({opacity:0.6});
			$(this).find(".page-left").css({opacity:1});
		},
		prevPageWall: function(){
			var actual = $(this).find(".pages:visible");
			actual.hide();
			actual.prev().show();
			if(!actual.prev().prev().is(".pages"))
				$(this).find(".page-left").css({opacity:0.6});
			$(this).find(".page-right").css({opacity:1});	
		}
	})
})(jQuery);
