/*
 * Apache License
 * Version 2.0, January 2004
 * http://www.apache.org/licenses/
 *
 * Copyright 1996-2008 by Sven Homburg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 */

var GPlotter = Class.create();
GPlotter.prototype = {
    initialize: function(elementId, key, errorCallbackFunction)
    {
        this.elementId = elementId;
        this.key = key;
        this.map = null;
        this.errorCallbackFunction = errorCallbackFunction;

		this.baseIcon = new GIcon();
		this.baseIcon.shadow = "/tdimg/gm/shadow.png";
		this.baseIcon.iconSize = new GSize(22, 34);
		this.baseIcon.shadowSize = new GSize(37, 34);
		this.baseIcon.iconAnchor = new GPoint(10, 34);
		this.baseIcon.infoWindowAnchor = new GPoint(10, 2);
		this.baseIcon.infoShadowAnchor = new GPoint(18, 25);
		this.iconUrl = "/tdimg/";
		this.maxIconNumber = 15;

        if (GBrowserIsCompatible())
        {
            this.map = new GMap2($(elementId),
            {mapTypes:[G_SATELLITE_MAP]});
            this.map.addControl(new GSmallMapControl());
            this.map.addControl(new GMapTypeControl());
        }
    },
    setCenter: function(latitude, longitude)
    {
        var point = new GLatLng(latitude, longitude);
        this.map.setCenter(point, 17);
    },
    addMarker: function(latitude, longitude, name)
    {
        var point = new GLatLng(latitude, longitude);

        var icon = new GIcon(this.baseIcon);
        icon.image = this.iconUrl + name + ".png";
        if (name.charAt(0) == 'b')
        {
        	icon.iconSize = new GSize(22, 27);
        	icon.iconAnchor = new GPoint(10, 27);
			icon.infoShadowAnchor = new GPoint(20, 0);
			icon.shadowSize = new GSize(37, 27);
			icon.shadow = "/tdimg/gm/shadowb.png";
        }

        var marker = new GMarker(point, icon);

        this.map.addOverlay(marker);
    },
    callException: function()
    {
        if (this.errorCallbackFunction.length > 0)
            eval(this.errorCallbackFunction + "('" + this.elementId + "')");
    }
}