/* Author: http://gw.gamewikis.org/wiki/User:Smurf
 * Emai1: madrat+guildwiki at gmail.com
 * File: Map.js
 * Started: 8/5/06
 * Description: Contains functions to load
 * 	the XML data for the map.
 */

//gwmaps.50webs.org

// Disables inline framing
//if(self!=top){top.location.href='http://www.google.com/'} // Redirect

GScript('FlatProjection.js');
GScript('MapControls.js');
GScript('MapXML.js');

function Icon(file,size,center)
{
	this.file = file;
	this.size = size;
	this.center = center;
}

// New Marker type
function MarkerLabel(point,title,icon,type)
{
	this._point = point;
	this._title = title;
	this._icon = icon;
	this._type = type;
}

MarkerLabel.prototype = new GOverlay();

MarkerLabel.prototype.initialize = function(map)
{
	var node = document.createElement("div");
	node.className = "MarkerLabel " + this._type;
	with(node.style)
	{
		position = "absolute";
		whiteSpace = "nowrap";
		textAlign = "center";
	}
	
	var image = document.createElement("img");
	image.src = this._icon.file;
	image.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
	image.alt = this._title;
	
	var imageContainer = document.createElement("div");
	
	with(imageContainer.style)
	{
		width = this._icon.size.width+"px";
		height = this._icon.size.height+"px";
		filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this._icon.file+"',sizingMethod='scale')";
	}
	imageContainer.appendChild(image);
	
	node.appendChild(imageContainer);
	var text = document.createElement("span");
	text.appendChild(document.createTextNode(this._title));
	node.appendChild(text);
	map.getPane(G_MAP_MAP_PANE).appendChild(node);
	
	this._root = node;
	this._map = map;
	this._image = image;
	this._imageContainer = imageContainer;
}

MarkerLabel.prototype.copy = function(){
	return new MarkerLabel(this._point, this._title, this._icon);
}

MarkerLabel.prototype.remove = function() {
	this._root.parentNode.removeChild(this._root);
}

MarkerLabel.prototype.redraw = function(force) {
	if (!force) return;
	
	var pt = this._map.fromLatLngToDivPixel(this._point);
	
	var xOffset = this._icon.size.width/2 - this._icon.center.x;
	this._root.style.left = (pt.x - this._root.clientWidth/2 + xOffset) + "px";
	this._root.style.top = pt.y - this._icon.center.y + "px";
}