(function($) {
  $.translate = function(word, path, params) {
    if(!path && !word) {
      return false;
    }
    if(!path) {
      path = '';
    }
    var translation = word;

    if ($.translations && $.translations[path] && $.translations[path][word]) {
      translation = $.translations[path][word];
     if (params) {
        $.each(params, function(key, value){
          translation = translation.replace('%' + key + '%', value);
        })
      }
    } else {
      $.post('json.php?type=translate', {
        path : path,
        word : word
      });
    }
    return translation;
  };
  $.loadingIndicator = (function () {
    
    var
    Self = $('<img />').attr('src', $('head base').attr('href') + 'images/ajax-loader.gif').attr('style', 'left: 50%; margin: -6px 0 0 -6px;	z-index: 1003; top: 50%; display:none; position: fixed;'),
    Inits = 0,
    IsTrack = false,
    Track = function(e) {
      Self.css({
        'top'  : (e.clientY + 10) + 'px',
        'left' : (e.clientX + 25) + 'px'
      });
    };
    
    $('body').append(Self);
    return {
      init : function(boolTrack, initialE) {
        Inits++;
        if (Inits == 1) {
          Self.show();
        }
        if (boolTrack && !IsTrack) {
          IsTrack = true
          if (initialE && initialE.clientY & initialE.clientX)
            Track(initialE);
          $(document).bind('mousemove', Track);
        }
      },
      stop : function() {
        Inits--;
        if (Inits == 0) {
          Self.hide().css({
            'top' : '50%',
            'left': '50%'
          });
          if (IsTrack) {
            $(document).unbind('mousemove', Track);
            IsTrack = false;
          }
        }
      }
    };
  })();

})(jQuery);
$.unique_id = function() {
  return ((new Date()).getTime() + "" + Math.floor(Math.random() * 1000000)).substr(0, 18);
};
function getOffsets (el) {
  var o = {
    x : el.offsetLeft,
    y : el.offsetTop
  };
  if (el.offsetParent != null) {
    var po = getOffsets(el.offsetParent);
    o.x += po.x;
    o.y += po.y;
  }
  return o;
}
function generateDialog(type, message) {
  return  $(typeof message == 'object'? message : '<p>' + message + '</p>').dialog({
    dialogClass : type,
    title : (type? $.translate('message_' + type + '_title') : ''),
    buttons: {
      Ok: function() {
        $(this).dialog('close');
      }
    },
    modal : true
  });

}
