ASC.namespace('ASC.Chrysler.FAD.DrivingDirection');
ASC.Chrysler.FAD.DrivingDirection = ASC.extend(Ext.util.Observable,
		{
	    map: null,
	    originalCoordinate:null,
	    destinationCoordinate:null,
	    directionsDesc: null,
	    directions:null,
	    isSuccess:true,
	    constructor: function (cfg)
		{
			ASC.Chrysler.FAD.DrivingDirection.superclass.constructor.apply(this);
			if (GBrowserIsCompatible())
			{
				if(cfg.map)
				{
					this.map = cfg.map;
				}
				else
				{
					this.map = new GMap2(ASC.getEl(cfg.renderTo).dom); 
				}
				if(cfg.controls)
				{
				    for(var i =0;i<cfg.controls.length;i++)
					{
				    	this.map.addControl(cfg.controls[i]);
					}
				}
				//alert(cfg.original);
				this.directionsDesc        = cfg.directionsDesc;
				this.originalCoordinate	   = cfg.original;
				this.destinationCoordinate = cfg.destination;
			}
			this.addEvents({"error":true,"success":true,"checkError":true,"checkSuccess":true});	
			
		},
		getDrivingDirection:function()
		{
			 var desc = ASC.getEl(this.directionsDesc).dom;
			 this.directions = new GDirections(this.map, desc); 
			 this.directions.el = this;
			//alert(this.originalCoordinate);
			//alert(this.destinationCoordinate);
			 GEvent.addListener(this.directions, "load", this.onGDirectionsLoad);
			 GEvent.addListener(this.directions, "error", this.handleErrors);
			 this.directions.load(this.originalCoordinate+" to "+this.destinationCoordinate);
		},
		clear:function()
		{
			if(this.directions)
			this.directions.clear();
		}
		,
		test:function()
		{
			var testDirections = new GDirections(null, null); 
			testDirections.el = this;
			 GEvent.addListener(testDirections, "load", this.ontestSuccess);
			 GEvent.addListener(testDirections, "error", this.ontestError);
			 testDirections.load(this.originalCoordinate+" to "+this.destinationCoordinate);
		},
		ontestSuccess:function()
		{
			this.el.fireEvent("checkSuccess",{})
		}
		,
		ontestError:function()
		{
			this.el.fireEvent("checkError",{})
		}
		,
		onGDirectionsLoad:function(e)
		{
			
			this.el.fireEvent("success",this)
		}
		,
		handleErrors:function(e)
		{
			this.el.fireEvent("error",e)
		}
		
		});