$.fn.GeoMap = function (Options) { return new GeoMap($(this), Options); };
	
var GeoMap = function (MapElement, Options) {
	var Me = this;
	
	this.MapElement = MapElement;
	this.PointClass = 'point';
	this.DivContent = '';
	this.Offset = {Left: 0, Top: 0};
	this.ImageRatio = 1.0;
	this.Width = MapElement.width();
	this.Height = MapElement.height();
	this.AnimationOffset = {Left: 0, Top: -30}
	
	this.SetHoverBox = function (Point, Data) { return true; };
	this.Click = function () { };
	this.LoadCallback = function () { };
	
	if (typeof Options != 'undefined')
		$.each(Options, function (Key, Val) { Me[Key] = Val; });
	
	this.CalcCSS = function (Latitude, Longitude) {
		var CSS = {position: 'absolute'};

		CSS.marginLeft = (Me.Width / 2) + (Longitude / 360 * Me.Width) + Me.Offset.Left + Me.AnimationOffset.Left;
		CSS.marginTop = (Me.Height / 2) + (-Latitude / 180 * Me.Height) + Me.Offset.Top + Me.AnimationOffset.Top;
		
		return CSS;
	};
	
	this.AddPoint = function (Data, AltPointClass, AnimationCallback) {
        var TempClass = Me.PointClass;
        var TempFunction = function () { };
        
	    if (typeof AltPointClass != 'undefined') TempClass = AltPointClass;
	    if (typeof AnimationCallback != 'undefined') TempFunction = AnimationCallback;
	    
		Me.MapElement.append('<div class="' + TempClass + '">' + Me.DivContent + '</div>');
		
		var Point = $('.' + TempClass + ':last');
		Point.css(Me.CalcCSS(Data.latitude, Data.longitude));
		
		var Animation = {
                        marginLeft: Point.css('margin-left').replace(/px/, '') - Me.AnimationOffset.Left,
                        marginTop: Point.css('margin-top').replace(/px/, '') - Me.AnimationOffset.Top
                      };
                      
		Point.animate(Animation, 600, AnimationCallback);
		
		return Point;
	};
	
	this.GetPoint = function (URL) {
		$.getJSON(URL, function (Data) { 
            Me.AddJson(Data);
            Me.LoadCallback();
        });
	};
	
	this.GetPoints = function (URL) {
        $.getJSON(URL, function (Data) {
            $.each(Data, function (i, Item) {
                Me.AddJson(Item); 
            });
            Me.LoadCallback();
        });
    }
	
	this.AddJson = function (Data) {
	    Point = Me.AddPoint(Data);
	    Point.attr('id', Data.id).click(Me.Click);
	    
	    Me.SetHoverBox(Point, Data);
		return Point;
	};
	
	
	return this;
	
};