$(document).ready(function(){
	
	$("#show_comments a").click(function(event){
		
		$("#show_comments").slideUp("slow",
			function () {
				$("#comments").slideDown("slow");
			}
		);
		
		event.preventDefault();
	});
	
	$("#new_comment").submit(function (event) {

		event.preventDefault();
		
		if ( ($('#new_comment_text').val() == '') || ($('#new_comment_text').val() == jsTranslations['TXT_COMMENT_FIELD_TEXT']+' ...') )
		{
			alert(jsTranslations['TXT_PLEASE_TYPE_COMMENT']);
			return false;
		}
			
		
		new Ajax.Request(jsTranslations['newsURL'], {
			method: 'post',
			parameters: $('#new_comment').serialize(),
			onSuccess: function(transport){
					
				if (transport.responseText.substr(0,4) == 'msg:')
				{
					alert(transport.responseText.substr(4,transport.responseText.length-4));
				} else {
					$('#new_comment_content').slideUp('slow', function() {
						
						if (transport.responseText.length <= 250)
							$('#new_sent_comment').html(transport.responseText).slideDown('slow');
	
						$(this).html('<p class="success">'+jsTranslations['TXT_FORM_SUCCESS']+'</p>');
						$(this).slideDown('slow');
					});
				}
				
			},
			onFailure: function(){
				alert('Komentar nažalost nije poslan zbog greške poslužitelja.');
			}
		});

		return false;
	});
	
	$(".news_comment_inline .show_comments a").click(function(event){
		
		$(this).parent().slideUp("slow",
			function () {
				$(this).parent().find(".comments").slideDown("slow");
			}
		);
		
		event.preventDefault();
	});
	
	$(".news_comment_inline form").submit(function (event) {
	
	var forma = $(this);

		event.preventDefault();
						
		if ( ($(this).find('.new_comment_text').val() == '') || ($(this).find('.new_comment_text').val() == jsTranslations['TXT_COMMENT_FIELD_TEXT']+' ...') )
		{
			alert(jsTranslations['TXT_PLEASE_TYPE_COMMENT']);
			return false;
		}
			
		
		new Ajax.Request(jsTranslations['newsURL'], {
			method: 'post',
			parameters: $(this).serialize(),
			onSuccess: function(transport){
				
				if (transport.responseText.substr(0,4) == 'msg:')
				{
					alert(transport.responseText.substr(4,transport.responseText.length-4));
				} else {
					forma.find('.new_comment_content').slideUp('slow', function() {
						
						if (transport.responseText.length <= 250)
							forma.parent().find('.new_sent_comment').html(transport.responseText).slideDown('slow');
	
						$(this).html('<p class="success">'+jsTranslations['TXT_FORM_SUCCESS']+'</p>');
						$(this).slideDown('slow');
					});
				}
			},
			onFailure: function(){
				alert('Komentar nažalost nije poslan zbog greške poslužitelja.');
			}
		});

		return false;
	});
});