var like_url = '/ajax/post-like.php';
var like_max = 10;
var like_cache = Array();

function _getRel(el) {
  return $(el).readAttribute('rel');
}

function _isCached(id) {
  if(like_cache.indexOf(parseInt(id)) >= 0) {
    return true;
  } else {
    return false;
  }   
}

function showLike(el) {
  id = _getRel(el);

  if(_isCached(id)) {
    container = $('post-like-' + id).select('div.like_container');
    if(container[0].visible()) {
      container[0].setStyle({display:'none'});
    } else {
      container[0].setStyle({display:'block'});
    }
    return;
  }
  
  siblings = $(el).nextSiblings();
  container = siblings[0];
  container.setStyle({display:'block'});
  new Ajax.Updater(container, like_url, {
      parameters: {id: id, sta: 'jos', limit: like_max},
      method: 'get',
      onSuccess: function(transport) {
        like_cache[like_cache.size()] = parseInt(id);
      }  
    }); 
}

function postLike(el) { 
  id = _getRel(el);
  
  new Ajax.Request(like_url,{
      method: 'get',
      parameters: {id: id},
      onCreate: function() {
        el.insert({top: '<img src="/slike/like_ajax.gif"/>'});        
      },
      onSuccess: function(transport) {
          container = $('post-like-' + id).select('div.like_container');
          post_like = $('post-like-' + id).select('span.post_like');
                             
          if(!post_like[0]) {
             container[0].insert({before: '<span class="post_like" rel="1">1</span>'});   
          } else {            
             value = parseInt(_getRel(post_like[0])) + 1;
             post_like[0].update(value).writeAttribute({rel: value});
          }
          el.remove();
      }
  });
}


function Izbrisati(message, url) 
{
	if (confirm(message)){				
		
var razlog = prompt("Razlog ?", "");

if(razlog!=null){
location.href=url+'&razlog='+razlog;
}

	}
}