
function HrefMap(mapname_in,width_in,height_in)
{
	this.mapname = mapname_in;
	this.hrefs = new Array();
	this.width = width_in;
	this.height = height_in;
}

HrefMap.prototype.resizeMap = function(new_width_in,new_height_in,new_mapname_in)
{
	var xRatio, yRatio;
	var i = null, j = null;
	
	if (typeof(new_mapname_in) != 'undefined')
	{
		this.mapname = new_mapname_in;
	}
	
	xRatio = new_width_in/this.width;
	yRatio = new_height_in/this.height;
	
	for (i in this.hrefs)
	{
		if (this.hrefs[i]['poly'])
		{
			for (j = 0; j < this.hrefs[i]['poly'].length; j+=2)
			{
				this.hrefs[i]['poly'][j] = Math.round(this.hrefs[i]['poly'][j]*xRatio);
				this.hrefs[i]['poly'][j+1] = Math.round(this.hrefs[i]['poly'][j+1]*yRatio);
			}
		}
		else
		{
			this.hrefs[i]['x1'] = Math.round(this.hrefs[i]['x1']*xRatio);
			this.hrefs[i]['x2'] = Math.round(this.hrefs[i]['x2']*xRatio);
			this.hrefs[i]['y1'] = Math.round(this.hrefs[i]['y1']*yRatio);
			this.hrefs[i]['y2'] = Math.round(this.hrefs[i]['y2']*yRatio);				
		}
	}
}

HrefMap.prototype.addLink = function(candleNum,x1,y1,x2,y2)
{
	this.hrefs[candleNum] = new Array();
	this.hrefs[candleNum]['x1'] = x1;
	this.hrefs[candleNum]['y1'] = y1;
	this.hrefs[candleNum]['x2'] = x2;
	this.hrefs[candleNum]['y2'] = y2;
	this.hrefs[candleNum]['poly'] = false;
}

HrefMap.prototype.addPoly = function(candleNum,arPolygon)
{
	this.hrefs[candleNum] = new Array();
	this.hrefs[candleNum]['poly'] = arPolygon;
}

HrefMap.prototype.generateMap = function(generateMouseOvers)
{
	var i = null,j = null;
	
	var new_map = document.createElement("map");
	
	new_map.setAttribute("name",this.mapname);
	new_map.setAttribute("id",this.mapname);
	
	for (i in this.hrefs)
	{
		var hr = this.hrefs[i];
		var new_area = document.createElement("area");
		
		if (hr['poly'] != false)
		{
			var s = "";

			for (j = 0; j < hr['poly'].length; j++)
			{				
				if (j > 0)
				{
					s += ",";
				}

				s += hr['poly'][j];
			}

			new_area.setAttribute("shape","polygon");
			new_area.setAttribute("coords",s);	
		}
		else
		{
			new_area.setAttribute("shape","rect");
			new_area.setAttribute("coords",hr['x1']+","+hr['y1']+","+hr['x2']+","+hr['y2']);
		}
		
		if(generateMouseOvers == true)
		{
			new_area.setAttribute("onmouseover","candleMouseOver("+i+")");
			new_area.setAttribute("onmouseout","candleMouseOut("+i+")");
		}
		
		new_area.setAttribute("href","javascript:candleClick("+i+")");
		
		new_map.appendChild(new_area);
	}
	
	var new_span = document.createElement("span");
	new_span.appendChild(new_map);

	document.write(new_span.innerHTML);
}	

