/*
 * Map
 *
 * Copyright (c) 2010 Boris Dinkevich (dinkevich.com)
 * Licensed under the GPL (GPL-LICENSE.txt) licenses.
 *
 * $Date: 2010-01-01 10:10:01 -0200 (Fri, 01 Jan 2010) $
 * $Rev: 0001 $
 */

var Map = function() {
  return {
    $map: null,
    centerX: null,
    centerY: null,
    changed: false,

    init: function($container, $map) 
    {
      this.$map = $map;

      this.centerX = parseInt($container.css('width'))  / 2;
      this.centerY = parseInt($container.css('height')) / 2;

      $map.children('img').first()
        .attr('width',  parseInt($('body').width()))
        .attr('height', parseInt($('body').height()));

      $container.mousemove(function(e) {
        Map.mouseX = e.clientX;
        Map.mouseY = e.clientY;
        Map.changed = true;
      });

      setInterval(that.updateMap, 20);
    },

    updateMap: function()
    {
      var that = Map;

      if (that.changed) {
        var offsetX = that.mouseX - that.centerX;
        var offsetY = that.mouseY - that.centerY;

        that.$map
          .css('left', -offsetX/20)
          .css('top',  -offsetY/20);

        that.changed = false;
      }
    },
  }
}();




