/************************************************************************************************************************************
 *
 *  LocationSign Class
 *
 *  Used for the "my location" marker on the map and it's animation (API V2).
 *  Before including, should include <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAtAgmtC5TOnGzbLD6cZx2XBTkO2p9pFCll053e1phJ87WejYKaBSfHsetUf3xFUU3kRk2h2OipIyHlg" type="text/javascript"></script>
 ************************************************************************************************************************************/


// constructor for LocationSign class
function LocationSign(latlng, map)
{
	this.circleFileSizes = [100, 70, 50, 36, 25]; //px
	this.circleMarkers = new Array();
	this.lockedTarget = false;

	this.circlesNum = function() {return this.circleFileSizes.length;};
	this.setPosition = setPosition;
	this.animate = animate;
	this.showOneCircle = showOneCircle;

	var circle_icon;

	// creating the set of circles (hidden)
	for (i=0; i<this.circlesNum(); i++)
	{
		circle_icon = new GIcon(G_DEFAULT_ICON);
                //circle_icon.image = 'images/map_circle' + this.circleFileSizes[i] + '.png';
                circle_icon.image = 'images/mylocation/map_circle' + this.circleFileSizes[i] + '.png';
		circle_icon.iconSize = new GSize(this.circleFileSizes[i], this.circleFileSizes[i]);
		circle_icon.iconAnchor = new GPoint(this.circleFileSizes[i]/2, this.circleFileSizes[i]/2);
		circle_icon.shadow = "";

		this.circleMarkers[i] = new GMarker(latlng, {
			clickable: false,
			draggable: false,
			icon: circle_icon,
			hide: true,
			zIndexProcess: function(marker) {return 1000000;}
		});

		map.addOverlay(this.circleMarkers[i]);
	}

// creating the center icon (visible)

	var me_icon = new GIcon(G_DEFAULT_ICON);
        //me_icon.image = 'images/map_target.png';
        me_icon.image = 'images/mylocation/blue_dot_halo.png';
        //me_icon.iconSize = new GSize (17, 17);
        me_icon.iconSize = new GSize (128, 128);
	me_icon.shadow = "";
	me_icon.iconAnchor = new GPoint(64, 64);
	//me_icon.iconAnchor = new GPoint(8, 8);

	this.targetMarker = new GMarker(latlng, {
		clickable: false,
		draggable: false,
		icon: me_icon,
		zIndexProcess: function(marker) {return 1000000;}
	});

	map.addOverlay(this.targetMarker);

}

function setPosition(latlng)
{

	if (this.lockedTarget == false)  // the target icon may be locked if we are during circles animation
	{
		this.targetMarker.setLatLng(latlng);
	}
}

function animate()
{
	// making sure the target marker doesn't move during animation
	locationSign.lockedTarget = true;

	//update the circles' location to this of the target:
	for (i=0; i<this.circlesNum(); i++)	{
		this.circleMarkers[i].setLatLng(this.targetMarker.getLatLng());
	}

	this.showOneCircle(0); // show the outer circle
	for (i=1; i<this.circlesNum()+1; i++)	{ // show the other circles
		setTimeout("locationSign.showOneCircle(" + i + ");" , i*200);
	}

	var CircleNum=this.circlesNum();
	// When the animation ends, updating the centeral icon that may have moved by now:
	setTimeout("locationSign.lockedTarget = false; locationSign.setPosition(new GLatLng(currentLocationLat, currentLocationLng));" ,
				CircleNum*200 + 200);
				//this.circlesNum()*200 + 200);

}

function showOneCircle(i)
{
	// show the desired marker
	if (i<this.circlesNum())
		this.circleMarkers[i].show();
	// hide the previous marker
	if(i>0)
		this.circleMarkers[i-1].hide();
}

