


$(document).ready(function() {
	

	
	//TabsProfil
	
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

	
	//Commentfunction
	$(".activate_comments").click(function(){
			$(".all_comments").fadeOut();
			$(this).parent().next(".all_comments").fadeIn(500);
			
			var answerid = $(this).attr("title");
			
			$.ajax({
				   type: "POST",
				   url: "/ajax/answer_comments.php",
				   data: "answer_id="+answerid,
				   success: function(msg){
						$(".content"+answerid).html(msg);
				   }
				 });	
	});
	
	$(".deactivate_comments").click(function(){
		$(this).parent(".all_comments").fadeOut(500);
		$(".content").html("");
	});
	
	
	$('.comment').qtip(
			   {
				   content: '<textarea style="width: 200px;height: 100px; id="comment_content"></textarea><br><a href="#" >Kommentar posten</a>',
				   show: 'click',
				   hide: {when: {event: 'unfocus'}},
				   style: {name: 'blue', tip: true},
				   position: {
					      corner: {
					         target: 'bottomMiddle',
					         tooltip: 'topRight'
					      }
					   }
			   });

	
	
	//Tooltips
	$("#Fragezeichen_Icon_Home").qtip({
		   content: 'Deine Frage muss <b>mindestens 20</b> und darf <b>maximal 200</b> Zeichen lang sein.<br><br>Fragen immer ohne "..." und "Was würdest du tun wenn," eingeben.',
		   show: 'mouseover',
		   hide: 'mouseout',
		   style: {name: 'blue', tip: true},
		   position: {
			      corner: {
			         target: 'topRight',
			         tooltip: 'bottomLeft'
			      }
			   }
		});
	
	
	
	//Registrieren
	
	$("#registration_username").qtip({
		   content: 'Dein Username muss mindestens 3 Zeichen lang sein und darf keine Sonderzeichen enthalten.',
		   show: 'focus',
		   hide: {when: {event: 'blur'}},
		   style: {name: 'blue', tip: true},
		   position: {
			      corner: {
			         target: 'rightMiddle',
			         tooltip: 'leftMiddle'
			      }
			   }
		});
	
	$("#registration_pwd1").qtip({
		   content: 'Dein Passwort muss aus mindestens 6 Zeichen bestehen.',
		   show: 'focus',
		   hide: {when: {event: 'blur'}},
		   style: {name: 'blue', tip: true},
		   position: {
			      corner: {
			         target: 'rightMiddle',
			         tooltip: 'leftMiddle'
			      }
			   }
		});
	
	$("#registration_pwd2").qtip({
		   content: 'Bitte wiederhole dein Passwort.',
		   show: 'focus',
		   hide: {when: {event: 'blur'}},
		   style: {name: 'blue', tip: true},
		   position: {
			      corner: {
			         target: 'rightMiddle',
			         tooltip: 'leftMiddle'
			      }
			   }
		});
	
	$("#registration_email").qtip({
		   content: 'Bitte gib eine gültige Emailadresse an.',
		   show: 'focus',
		   hide: {when: {event: 'blur'}},
		   style: {name: 'blue', tip: true},
		   position: {
			      corner: {
			         target: 'rightMiddle',
			         tooltip: 'leftMiddle'
			      }
			   }
		});
	
   
        $("textarea#form_question").focus();
	
	//Inputfelder
	$("textarea#form_question").focus(function(){
	   if($(this).val() == "...")
                {
                    $(this).val("");
                }
	});

        $("textarea#form_question").blur(function(){
            if($(this).val() == "")
                {
                    $(this).val("...");
                }
	});

        $("textarea#form_question").keyup(function(){
                
            var text = $(this).val();
            var lengh = 200 - text.length;

            if(lengh > 190 | lengh < 0){$("#count_text").css("color","red")}
            else($("#count_text").css("color","green"))

            $("#count_text").html(lengh);
        });


	$("input[type=text]").focus(function(){
	    $(this).select();
	});
	
	$("textarea").focus(function(){
	    $(this).select();
	});
});

