// JavaScript Document
        $(document).ready(function(){
								   
						   
								   
			var current ;	
			loadAllComments();
			
			$("a.like-this").live('click', function(event) {
                            nr = $(this).attr('commenter-id');
//                            $('#likes_'+nr).load('/kmosite/index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&onlylikes=1&cmntid='+nr )

					$.post("/kmosite/index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&onlylikes=1&cmntid="+nr, { like: $(this).attr('commenter-id') , likeaction: "1" }, function(data) {

						$('#likes_'+nr).html(data);
					});
 			}); 
			
			$("a.disslike-this").live('click', function(event) {
                            nr = $(this).attr('commenter-id');
//                            $('#likes_'+nr).load('/kmosite/index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&onlylikes=1&cmntid='+nr )

					$.post("/kmosite/index.php?option=com_kmo&controller=utils&task=cmnt&ajax=1&onlylikes=1&cmntid="+nr, { like: $(this).attr('commenter-id') , likeaction: "-1" }, function(data) {

						$('#likes_'+nr).html(data);
					});

				
 			}); 
			
			$("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 loadOneCommenter(selector)  {
			 $(selector).each(function(index) {
				 var options = { 
								target:        $(this),   // target element(s) to be updated with server response
								success:       showCommenterResponse  // post-submit callback
							};

					$(this).load("/kmosite/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');
						    ctnrFix();
							$('.wholikes-data').each(function(index) {
							$("#"+$(this).attr('dest-id')).html($(this).html());
							//$("#"+$(this).attr('dest-id')).parent().parent().removeClass('onh');
							//$("#"+$(this).attr('dest-id')).parent().parent().css('display','block');
							$(this).remove();
							});
					});
			 });
			}
		
		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("/kmosite/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');
						    ctnrFix();
							$('.wholikes-data').each(function(index) {
							$("#"+$(this).attr('dest-id')).html($(this).html());
							//$("#"+$(this).attr('dest-id')).parent().parent().removeClass('onh');
							//$("#"+$(this).attr('dest-id')).parent().parent().css('display','block');
							$(this).remove();																	  
							});	
					});																					  
			 });						
			}
			
			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');																		  
				 });	
				
				
				
			} 
			 
