// JavaScript Document

function icon(image,size)
{
	var size=(size == null) ? 9 : size;
	var image=(image == null) ? "site" : image;
	var icon = new GIcon();
	icon.image = "http://www.metocean.co.nz/forecast/images/"+image+".png";
	icon.shadow = "http://www.metocean.co.nz/forecast/images/"+image+".png";
	icon.iconSize = new GSize(size,size);
	icon.shadowSize = new GSize(size,size);
	var hsize=Math.round(0.5*size);
	icon.iconAnchor = new GPoint(hsize,hsize);
	icon.infoWindowAnchor = new GPoint(hsize,hsize);
	return icon;
}

function createMarker(x, y, linkstr, infostr, theicon)
{
	var theicon=(theicon == null) ? icon : theicon;
	var point=new GLatLng(y,x);
	var marker = new GMarker(point,{icon:theicon});
	// Show this markers index in the info window when it is clicked
	if (linkstr){
		var html = linkstr;
		GEvent.addListener(marker, "click", function() {window.open(html,'','height=800,width=900,scrollbars=yes,resizable=yes');});
	}
	var info = infostr+" ["+point.x+" "+point.y+"]";
	GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(infostr);});
	return marker;
}

function createBBox(x1,x2,y1,y2,col)
{
	var col=(col == null) ? "#FFFF00" : col;
	var bbox=new GPolygon([new GLatLng(y1,x1),new GLatLng(y1,x2),new GLatLng(y2,x2),new GLatLng(y2,x1),new GLatLng(y1,x1)],col,1);
	return bbox;
}

function Site(x,y,imp,tag,name,type,size,info){
	this.type = (type == null) ? "site" : type;
	this.size = (size == null) ? 9 : size;
	this.x=x;
	this.y=y;
	this.imp=imp;
	this.tag=tag;
	this.name=name;
	info = (info == null) ? name : info;
	if (tag){
		this.linkstr="http://www.metocean.co.nz/forecast/fcgraphs.php?s="+tag+","+imp;
	}else{
		this.linkstr=null;
	}
	this.marker=createMarker(x,y, this.linkstr, info, icon(type,size));
}

function Grid(x1,x2,y1,y2,tag,name){
	this.tag=tag;
	this.name=name;
	this.linkstr='http://www.metocean.co.nz/forecast/?g='+tag;
	this.marker=createBBox(x1,x2,y1,y2);
}

