// Standard jQuery header
;(function($) {

$(document).ready(function() {	
	// Hide Form Elemets
	//$("#CommentFormTitle").hide();
	//$("#PageCommentInterface_Form_PageCommentsPostCommentForm fieldset").hide();
	//$("#PageCommentInterface_Form_PageCommentsPostCommentForm_action_postcomment").hide();
	// Function to show Comment Form and Hide Comments
	var prevStatus;
	var nextStatus;
	$("#CommentFormInit").click(function () { 
		// Hide Comments
		$("#PageComments").hide();
		$("#CommentFormInit").hide();
		// Get status of slider buttons
		if ($("#prevBtn").is(':visible')){
			prevStatus=true;
		}else{
			prevStatus=false;
		}
		if ($("#nextBtn").is(':visible')){
			nextStatus=true;
		}else{
			nextStatus=false;
		}
		// Hide slider buttons
		$("#prevBtn").hide();
		$("#nextBtn").hide();
		// Show form 
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm fieldset").show();
		$("#CommentFormClose").show(); 
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm_action_postcomment").show();
		
	});
	$("#PageCommentInterface_Form_PageCommentsPostCommentForm_action_postcomment").click(function () { 
		// Show Comments
		$("#PageComments").show();
		$("#CommentFormInit").show();
		// Set status of slider buttons
		if (prevStatus==true){
			$("#prevBtn").show();
		}
		if (nextStatus==true){
			$("#nextBtn").show();
		}
		// Hide Form
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm fieldset").hide();
		$("#CommentFormClose").hide(); 
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm_action_postcomment").hide();
	});
	
	$("#CommentHolder").easySlider({
		
		//prevText: '&#171;<span style="position:relative;top:-3px;font-size:20px;"> zur&#252;ck</span>',
		//nextText: '<span style="position:relative;top:-3px;font-size:20px;"> vor</span> &#187;',
		prevText: '&#171;<span style="position:relative;top:-2px;font-size:16px;"> zur&#252;ck</span>',
		nextText: '<span style="position:relative;top:-2px;font-size:16px;"> vor</span> &#187;',
		orientation: 'horizontal',
		speed:'400',
		controlsFade:false
	});
	$("#CommentFormClose").click(function () { 
		// Show Comments
		$("#PageComments").show();
		$("#CommentFormInit").show();
		// Set status of slider buttons
		if (prevStatus==true){
			$("#prevBtn").show();
		}
		if (nextStatus==true){
			$("#nextBtn").show();
		}
		// Hide Form
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm fieldset").hide();
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm_action_closecomment").hide(); 
		$("#CommentFormClose").hide();
		$("#PageCommentInterface_Form_PageCommentsPostCommentForm_action_postcomment").hide();
	});
	
    
	var bodyClass=$('body').attr('class');
	$("#nextBtn a").addClass(bodyClass);
	$("#prevBtn a").addClass(bodyClass);
	
	function limitChars(textid, limit, infodiv){
		var text = $('#'+textid).val(); 
		var textlength = text.length;
		if(textlength > limit){
			$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
			//$('#' + infodiv).show();
			$('#'+textid).val(text.substr(0,limit));
		}
	}
	
	 $('#Comment.field textarea').keyup(function(){
		 limitChars('Comment.field textarea', 650, 'PageCommentInterface_Form_PageCommentsPostCommentForm_error');
	 })
	
	// Standard jQuery footer
})
})(jQuery);