// JavaScript Document
        $(document).ready(function(){
								   
						   
								   
			var current ;	
			loadAllComments();
			
			$("a.like-this").live('click', function(event) {
				$('#likes_'+$(this).attr('commenter-id')).html("<span style=\"text-decoration: blink; font-weight:bold;\">ladowanie...</span>");
				$.post("index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1", { like: $(this).attr('commenter-id') , likeaction: "1" }, function(data) {
  						var arr = data.split("[like]");								 
						var nr = arr[1];
						$('#likes_'+nr).load('index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&onlylikes=1&cmntid='+nr )
					});

				
 			}); 
			
			$("a.disslike-this").live('click', function(event) {
				$('#likes_'+$(this).attr('commenter-id')).html("<span style=\"text-decoration: blink; font-weight:bold;\">ladowanie...</span>");
					$.post("index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1", { like: $(this).attr('commenter-id') , likeaction: "-1" }, function(data) {
  					  	var arr = data.split("[like]");								 
						var nr = arr[1];
						$('#likes_'+nr).load('index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&onlylikes=1&cmntid='+nr )	
					});

				
 			}); 
			
			$("a.show-more").live('click', function(event) {
				$(this).parent().parent().find(".iammore").show();		
				$(this).parent().parent().find(".iamless").hide();		
 			}); 
			
			$("a.show-less").live('click', function(event) {
				$(this).parent().parent().find(".iamless").show();		
				$(this).parent().parent().find(".iammore").hide();		
 			}); 
			
								   
			$(document).find("a.show_no_comment").parent().parent().parent().css({'border-width' : '0px','padding-top' : '0px'});					   
 			
			$("a.show_comments").live('click', function(event) {
  				 event.preventDefault();
   				$(this).parent().parent().parent().next().slideDown();
				$(this).parent().parent().parent().hide();
				
				
 			});
			
			 $("a.show_comments_wf").live('click', function(event) {
  				 event.preventDefault();
				$(this).parent().parent().parent().next().find("div.comment_form").show(); 
				$(this).parent().parent().parent().next().find("a.show_comment_form").hide();
				$(this).parent().parent().parent().next().find("a.hide_comment_form").show();				
   				$(this).parent().parent().parent().next().slideDown();
				$(this).parent().parent().parent().hide();
 			});
			
			 $("a.hide_comments").live('click', function(event) {
  				 event.preventDefault();
				$(this).parent().parent().parent().slideUp();
   				$(this).parent().parent().parent().prev().slideDown();
				$(this).parent().parent().parent().find("div.comment_form").slideUp(); 
				$(this).parent().parent().parent().find("a.show_comment_form").show(); 
				$(this).parent().parent().parent().find("a.hide_comments").show();	
 			});
			 
			 $("a.show_comment_form").live('click', function(event) {
  				 event.preventDefault();
				$(this).parent().parent().parent().find("div.comment_form").slideDown(); 
				$(this).hide();
				$(this).parent().parent().parent().find("a.hide_comment_form").show();				
 			});
			 
			 $("a.hide_comment_form").live('click', function(event) {
  				 event.preventDefault();
				$(this).parent().parent().parent().parent().find("div.comment_form").slideUp(); 
				$(this).parent().parent().parent().parent().find("a.show_comment_form").show();
				$(this).parent().parent().parent().parent().find("a.hide_comments").show();					
				$(this).hide();
 			});	
			 
			 $("a.hide_no_comment").live('click', function(event) {
  				 event.preventDefault();
			    $(this).parent().parent().parent().css({'border-width' : '0px','padding-top' : '0px'});				 
				$(this).parent().parent().parent().parent().find("div.comment_form").slideUp(); 				
				$(this).hide();
				$(this).parent().parent().parent().parent().find("a.show_no_comment").show(); 
 			});		
		
			$("a.show_no_comment").live('click', function(event) {
  				 event.preventDefault();
			    $(this).parent().parent().parent().css({'border-width' : '1px','padding-top' : '1px'});
				$(this).parent().parent().parent().parent().find("div.comment_form").slideDown(); 				
				$(this).hide();
				$(this).parent().parent().parent().parent().find("a.hide_no_comment").show(); 
 			});		
			    $(".comments").find(".inputSubmit").live('click', function(event) {
  				 		if($(this).parent().prev().val() == ""){
   						  alert("Wpisz najpierw tresc komentarza.");
    					  event.preventDefault();
						}
				 });


 		});
		
		function loadAllComments()  { 
			 $('.commenter-placeholder').each(function(index) {	
				 var options = { 
								target:        $(this),   // target element(s) to be updated with server response 
								success:       showCommenterResponse  // post-submit callback 
							}; 
							
					$(this).load("index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&cmntid=" + $(this).attr('commenter-id'), function() {
							$(this).find('form.just-loaded').submit(function() { 
								$(this).ajaxSubmit(options); 
								return false; 
							}); 		
							$(this).find('form.just-loaded').removeClass('just-loaded');
					});																					  
			 });						
			}
			
			function showCommenterResponse(responseText, statusText, xhr, $form)  { 		 
				$('.showme').slideDown();
				$('.showme').removeClass('schowme');
				
				
				 $('.commenter-placeholder').each(function(index) {	
				 var options = { 
								target:        $(this),   // target element(s) to be updated with server response 
								success:       showCommenterResponse  // post-submit callback 
							}; 
							
							$(this).find('form.just-loaded').submit(function() { 
								$(this).ajaxSubmit(options); 
								return false; 
							}); 					
							$(this).find('form.just-loaded').removeClass('just-loaded');																		  
				 });	
				
				
				
			} 
			 
