DEVMODE = true;
BASEURL = document.getElementsByTagName('base')[0].href;    
(function($) {
  $.translate = function(word, path) {
    var translation = word;
    if ($.translations && $.translations[path] && $.translations[path][word]) {
        translation = $.translations[path][word];
    } else if (DEVMODE) {
      $.post('json.php?controller=general&action=translate', {
        path : path,
        word : word
      });
    }
    return translation;
  };

  $.json = function(controller, action, data, callback) {
    if (!callback && $.isFunction(data)) {
      callback = data;
      data = {};
    }
    $.getJSON('json.php?controller=' + controller + '&action=' + action, data, function(j, textStatus) {
      if (typeof(callback) == 'function') {
        callback(j);
      }
    }, 'json');
  };

  $.unique_id = function() {
    return ((new Date()).getTime() + "" + Math.floor(Math.random() * 1000000)).substr(0, 18);
  };

  $.loadingIndicator = (function ($) {
      var
      self = $('<img />').attr('src', BASEURL + 'images/base/loading_circle.gif').attr('style', 'left: 50%; margin: -6px 0 0 -6px;	z-index: 1003; top: 50%; display:none; 	position: fixed;'),
      is = (self.length > 0),
      inits = 0,
      isTrack = false,
      track = function(e) {
          self.css({
              'top'  : (e.clientY + 10) + 'px',
              'left' : (e.clientX + 25) + 'px'
          });
      },
      _init = function(boolTrack, initialE){
          self.show();
          if (boolTrack) {
              isTrack = true
              if (initialE && initialE.clientY & initialE.clientX)
                  track(initialE);
              $().bind('mousemove', track);
          }
      },
      _stop = function() {
          self.hide().css({'top' : '50%', 'left': '50%'});
          if (isTrack) {
              $().unbind('mousemove', track);
              isTrack = false;
          }
      }
      $('body').append(self);
      return {
          init : function(boolTrack, initialE) {
              inits++;
              if (inits == 1)
                 _init(boolTrack, initialE);
          },
          stop : function() {
              inits--;
              if (inits == 0)
                 _stop()
          }
      };
  })(jQuery);


})(jQuery);

