/**

 * @namespace WPGMZA

 * @module GooglePolyline

 * @requires WPGMZA.Polyline

 */

(function($) {

	

	WPGMZA.GooglePolyline = function(row, googlePolyline)

	{

		var self = this;

		

		WPGMZA.Polyline.call(this, row, googlePolyline);

		

		if(googlePolyline)

		{

			this.googlePolyline = googlePolyline;

		}

		else

		{

			this.googlePolyline = new google.maps.Polyline(this.settings);			

			this.googlePolyline.wpgmzaPolyline = this;

			

			if(row && row.points)

			{

				var path = this.parseGeometry(row.points);

				this.setPoints(path);

			}

		}

		

		google.maps.event.addListener(this.googlePolyline, "click", function() {

			self.dispatchEvent({type: "click"});

		});

	}

	

	WPGMZA.GooglePolyline.prototype = Object.create(WPGMZA.Polyline.prototype);

	WPGMZA.GooglePolyline.prototype.constructor = WPGMZA.GooglePolyline;

	

	WPGMZA.GooglePolyline.prototype.setEditable = function(value)

	{

		this.googlePolyline.setOptions({editable: value});

	}

	

	WPGMZA.GooglePolyline.prototype.setPoints = function(points)

	{

		this.googlePolyline.setOptions({path: points});

	}

	

	WPGMZA.GooglePolyline.prototype.toJSON = function()

	{

		var result = WPGMZA.Polyline.prototype.toJSON.call(this);

		

		result.points = [];

		

		var path = this.googlePolyline.getPath();

		for(var i = 0; i < path.getLength(); i++)

		{

			var latLng = path.getAt(i);

			result.points.push({

				lat: latLng.lat(),

				lng: latLng.lng()

			});

		}

		

		return result;

	}

	

})(jQuery);