function Circle(opt){
    var me = this;
    
    this.isDeviation = false;
    this.isNew = true;
    this.phaseId = '';
    
    this.isFocus = true;
    this.isDirectionsSenseShow = false;
    this.isOldGeometry = false;
    
    this.center = null;
    this.radius = null;
    
    this.circle = null;
    this.stepsPoints =  null;
    this._speedValue = null;

    this.allowCheck = true;

    this.initialize(opt || {});
    
    if(checkInterface(this, IGeometry)){
        return;
    }
};

Circle.prototype.initialize = function(opt){
    this.map = opt.map;

    this.allowCheck = true;
    this.stepsPoints =  null;
    this.radius = 2;
    this.isNew = true;
    this.isOldGeometry = false;
    this._speedValue = -1;
    this.isFocus = true;
    this.isDirectionsSenseShow = false;
    this.circle = new google.maps.Circle();
};


Circle.prototype.length = function(){
	return this.geometryPath().length;
};

Circle.prototype.addPoint = function(point){
    var me = this;
    me.center = point;
    
    var directionsService = new google.maps.DirectionsService();
    var directionRequest = {
        origin: point,
        destination: point,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    
    directionsService.route(directionRequest, function(result, status){
        if(status == google.maps.DirectionsStatus.OK){
            me.center = result.routes[0].legs[0].steps[0].path[0];;
        
            me.setOptions({
                center: me.center,
                radius: me.radius,
                map: me.map
            });
    
            var opt = me.generateOptions();
            me.setOptions(opt);
        }
    });
     $('body').trigger('onDirectionChangedEditMap',{
        object: me,
        allowCheck: me.allowCheck
    });
};

Circle.prototype.setOptions = function(options){
    this.circle.setOptions(options);
};

Circle.prototype.generateOptions = function(){
	var opt = helpersGenerateStyle(this.isFocus, this.isDeviation, this.isNew, this.isOldGeometry);
	return opt;
};

Circle.prototype.geometryPath = function(){
    var path = new Array();
    path.push(this.center);
    return path;
};

Circle.prototype.getGeometryJSON = function(){
    var path = this.geometryPath();
    var geometry = new Array();
    for(var i=0, item; item = path[i]; i++){
        geometry.push({
            lat: item.lat(),
            lng: item.lng()
        });
    };
    var values = {
        isDeviation: this.isDeviation == true ? 1 : 0,
        geometry: geometry,
        deviationArrows: '',
        stepsPoints: this.stepsPoints
    };
    return values;
};

Circle.prototype.focus = function(){
    this.isFocus = true;
    var opt = this.generateOptions();
    this.setOptions(opt);
};

Circle.prototype.loseFocus = function(){
    this.isFocus = false;
    var opt = this.generateOptions();
    this.setOptions(opt);
};

Circle.prototype.showMarkers = function(value){
    this.setOptions({
        draggable: value,
        markerOptions: {
            visible: value
        }
    });  
};

Circle.prototype.showDirectionsSense = function(value){
	this.isDirectionsSenseShow = value;
};

Circle.prototype.setDirectionsSense = function(value){
};


//TODO
Circle.prototype.setSpeed = function(value){
    this._speedValue = value;
}
Circle.prototype.getSpeed = function(){
    return this._speedValue;
    //return 51;
};

Circle.prototype.clear = function(){
	this.setOptions({
		map: null
	});
	this.center = null;
};

Circle.prototype.getBounds = function(){
    var bounds = new google.maps.LatLngBounds();
    bounds.extend(this.center);
    return bounds;
}

Circle.prototype.CurrentPhase = function(value){
    if(value == true){
        this.setOptions({
            strokeOpacity: 1
        });
    }else{
        this.setOptions({
            strokeOpacity: 0.5
        });
    }
}

Circle.prototype.setRadius = function(value){
    this.radius = value;
    if(this.circle != null){
        this.setOptions({
            radius: this.radius
        })
    }
}
Circle.prototype.getMap = function(){
    return this.map;
}
