
$( document ).ready( function() {
	hideAnimationContents();
	addClickTriggerForDetails();
});

function addClickTriggerForDetails() {
	$(".click_open").click(function(event) {
		event.preventDefault();
		enableOpen($(this));
	});
}

function hideAnimationContents()
{
	$('.animateContent').css({height:0, minHeight: 0, overflow:'hidden'});
}

function enableOpen(_this) {
	_this.unbind().click(function(event) { event.preventDefault(); });// once the button is pressed, disable any further action
	var line = _this.parent();
	openContent(line);
}

function enableClose(_this) {
	_this.unbind().click(function(event) { event.preventDefault(); });// once the button is pressed, disable any further action
	var line = _this.parent();
 	closeContent(line);
}

function openContent(line)
{
	line.find('.click_open').attr('src','img/openloader.gif');

	var height = line.find('.qualiListContent').height();
	var imgheight = line.find('.left').height();
	var maxheight = Math.max(height, imgheight)+20;
	line.find('.animateContent').css({height: 0 }).animate( {height: maxheight , minHeight: imgheight }, 1000, function() {
		$(this).css({overflow:'hidden'});
		line.find('.click_open').attr('src','img/quali_open.gif');
        	line.find('.click_open').unbind().click(function(event) {
			event.preventDefault();
			enableClose($(this),0);
		});
	});


}


function closeContent(line)
{
	line.find('.click_open').attr('src','img/quali_closed.gif');
	line.find('.animateContent').animate( {height: 0, minHeight: 0}, 1000, function(){
		$(this).css({overflow:'hidden'});
		line.find('.click_open').click(function(event) {
			event.preventDefault();
			enableOpen($(this),0);
		});
	});
}


function checkCommentFormRemainingText(l)
{
	currentText = document.getElementById("comment_form_text").value;
	if(currentText.length>l)
	{
		document.getElementById("comment_form_remaining_text").innerHTML = "Text zulang";
	}
	if(currentText.length==l)
	{
		document.getElementById("comment_form_remaining_text").innerHTML = "";
	}
	if(currentText.length<l)
	{
		document.getElementById("comment_form_remaining_text").innerHTML = ""+(l-currentText.length)+" Zeichen verbleibend";
	}
}

lastCommentId = false;
function showComment(commentId)
{
	if(lastCommentId)
	{
		document.getElementById("comment_message_short_"+lastCommentId).style.display = "inline";
		document.getElementById("comment_message_full_"+lastCommentId).style.display = "none";
	}
	document.getElementById("comment_message_short_"+commentId).style.display = "none";
	document.getElementById("comment_message_full_"+commentId).style.display = "inline";
	lastCommentId = commentId;
}
