/* Author: yangzeming
 * Date: 2013-12-10
 * Desc: 遮罩层
    
 */
define("component/carengine",function (require, exports, module) {

    var carengine = _.Class({
		initial : function(options){
			var defaultOp = {
				tAngle : 4,    // 汽车转角
				axis : -90,   // -90标示 x轴方向垂直朝上，0标示x轴方向朝右侧
				speed : 20,    // 速度系数
				downspeed : 10,
				car : "",  // 汽车对象
				rotate : 0, //
				speedLong : 400,
				downspeedLong : 200,
				path : '/zxw',
				bg : ""    // 背景对象

			
			};
			
			// 长按住前进方向，此时点击右或者左，会出现延时2秒的转向停顿bug
			this.options = $.extend(true, {}, defaultOp, options);
			this.rotate = this.options.rotate;
			this.upLeft = 0;
			this.upDown = 0;
			this.upLeftSet = null;
			this.tmpAni = 30;   // 当出现捕获bug时自动修复走的循环 setIntervel
			this.testCar = $(this.options.car);
			this.imageBg = $(this.options.bg);
			// 导航面板
			this.snav = $(this.options.nav);
			this.guide = $(this.options.guide);

            // 判断是否支持css3的transform  否则就用滤镜处理
			this.isSupportCss3 = this.supportCss3("transform");
			
			this.upup = 0;
			this.keyUD = 0; // 没有的时候，up 1 down 2 此标示为了获取同时按下两个方向键
			this.keyLD = 0; // 没有的时候，left 1 right 2 此标示为了获取同时按下两个方向键
			// 为了解决键盘事件捕获上的一些bug，如当你长按上右时，可以使用标示的方式捕获到，但是此时松开右键，长按前键的捕获随之消失
			this.timeH = null; // 当出现上述bug时，由系统自动做运动修复
			this.timeHAni = 30;

			this.upLongPress = 0;
			this.curSpeed = 0;
			this.curAngle = 1;
			this.isUpFirst = "yes";

			this.isDownFirst = "yes";
			this.downLongPress = 0;
			this.curDownSpeed = 0;
			this.downDown = 0;
			this.guideAxis();

			// 仪表指针的angle
			this.j_speed_guide = $("#j_speed_guide");
			this.wayNum = 0;
			this.steeringAngle = 0;


		},
		// 导航面板坐标转换
		/*
		-ms-transform:rotate(-218deg); 
		-moz-transform:rotate(-218deg); 	
		-webkit-transform:rotate(-218deg); 
		 */
		guideAxis : function(){
			var c_pos = this.testCar.position(),
				i_pos = this.imageBg.position(),
				i_width = this.imageBg.width()+1000,
				i_height = this.imageBg.height()+200,
				g_width = this.snav.width(),
				g_height = this.snav.height();
			var guide_pos = {
				top : c_pos.top+Math.abs(i_pos.top),
				left : c_pos.left+Math.abs(i_pos.left)
			};
			var self = this;
			var bl_top = g_height/i_height*guide_pos.top,
				bl_left = g_width/i_width*guide_pos.left;
			this.guide.css({
				left : bl_left,
				top:bl_top
				
				//"-ms-transform" : "rotate("+(self.rotate+62)+"deg)",
				//"-webkit-transform" : "rotate("+(self.rotate+62)+"deg)",
				//transform : "rotate("+(self.rotate+62)+"deg)"
			});
            self.carTransform((self.rotate+62),self.guide);
			
		
		},
		stopRun : function(){
			$(document).off("keyup.run");
			$(document).off("keydown.run");
			
		},
		run : function(){
			var self = this;
			$(document).off("keydown.run").on("keydown.run",function(e){

				clearInterval(self.timeH);
				clearInterval(self.upLeftSet);
				var keyc = e.keyCode;
				self.trigger("keydown",keyc);
				if(keyc==38){   //  用来表示之前按下了 上键
					self.keyUD = 1;
					
				}
				if(keyc==40){   //  用来表示之前按下了 下键
					self.keyUD = 2;
					
				}
				if(keyc==37){   //  用来表示之前按下了 左键
					self.keyLD = 1;
					
				}
				if(keyc==39){   //  用来表示之前按下了 右键
					self.keyLD = 2;
					
				}
				if(keyc==37&&self.keyUD!=1&&self.keyUD!=2){   // 转换灯的启动 当仅按左键时触发的事件
					
					self.pressLeft();

					return;
				
				}
				if(keyc==39&&self.keyUD!=1&&self.keyUD!=2){   //left
					self.pressRight();
					return;
				
				}
				if((keyc==37&&self.keyUD==1)||(self.keyLD==1&&keyc==38)){   // 当同时按下 “上 左” 键时
					if(self.isUpFirst=="yes"){
						
						self.isUpFirst = "no";
					}
					self.upLongPress++;
					
					self.pressUpLeft();
					return;
				
				}
				if((self.keyUD==1&&keyc==39)||(self.keyLD==2&&keyc==38)){  // up 当同时按下  ”上右“ 键时
					if(self.isUpFirst=="yes"){
						
						self.isUpFirst = "no";
					}
					self.upLongPress++;
					self.pressUpRight();
					return;
				}
				if(keyc==38&&self.keyUD==1){   //    当仅按下 上键时
					self.upLongPress++;
					if(self.isFirst=="yes"){
						//self.curTime = self.sTime = new Date();
						self.isUpFirst = "no";
					}else{
						self.curTime = new Date();
						
					
					}

					self.pressUp();
					return;
				
				}
				
				if((keyc==39&&self.keyUD==2)||(self.keyLD==2&&keyc==40)){ // 当同时按下  ”下右“
					if(self.isDownFirst=="yes"){
						
						self.isDownFirst = "no";
					}
					self.downLongPress++;
					self.pressDownRight();
					return;
				}
				if((keyc==37&&self.keyUD==2)||(self.keyLD==1&&keyc==40)){  // 当同时按下  ”下左“
					if(self.isDownFirst=="yes"){
						
						self.isDownFirst = "no";
					}
					self.downLongPress++;
					self.pressDownLeft();
					return;
				}
				if(keyc==40&&self.keyUD==2){  // down
					if(self.isDownFirst=="yes"){
						
						self.isDownFirst = "no";
					}
					self.downLongPress++;
					self.pressDown();
					return;
				}
				
			
			});

			$(document).off("keyup.run").on("keyup.run",function(e){
				var keyc = e.keyCode;
				if(keyc==38){
					self.eTime = new Date();
					self.isUpFirst = "yes";
					self.upDown = 0;
					self.upLongPress = 0;
					self.curSpeed = 0;
					clearInterval(self.upDownSet);
					var f = self.getXY(self.rotate,150);
					//TweenMax.to(self.imageBg,1,{left:"-="+f.x+"px",top:"-="+f.y+"px",ease:Circ.easeOut});
				}
				if(keyc==40){
					self.isDownFirst = "yes";
					self.downDown = 0;
					self.downLongPress = 0;
					self.curDownSpeed = 0;
					clearInterval(self.downDownSet);
					var f = self.getXY(self.rotate,150);
					//TweenMax.to(self.imageBg,1,{left:"-="+f.x+"px",top:"-="+f.y+"px",ease:Circ.easeOut});
					
				}
				if(keyc==38||keyc==40){   // 当松开 上、下按键时
					clearInterval(self.timeH);
					self.keyUD = 0;
					self.trigger("release",keyc);
					//tl.pause();
				}
				if(keyc==37||keyc==39){   // 当松开 左、右按键时
					//clearInterval(self.timeH);
					//self.testCar.attr("src",self.options.path+"/images/car.png");
					self.keyLD = 0;
					//tl.pause();
				}
				//clearInterval(self.timeH);
				clearInterval(self.upLeftSet);
				clearInterval(self.upDownSet);
				self.upLeft = 0;
				if((keyc==37&&self.keyUD==1)||(keyc==39&&self.keyUD==1)){   // 解决当同时按下”上左、上右时“，松开左、右键；pressup的捕获消失的补救方法
					//self.upLongPress = 0;
					self.upreleaseRL();
					
				}
				if((keyc==37&&self.keyUD==2)||(keyc==39&&self.keyUD==2)){   //left
					self.downreleaseRL();
					
				}
				
				
			});
		},
		downreleaseRL : function(){
			var self = this;
			
			//self.testCar.attr("src",self.options.path+"/images/car.png");
			self.downLongPress++;
			self.setDownSpeed();
			var f = self.getXY(self.rotate,self.curDownSpeed);	
			//self.imageBg.css({left:"+="+f.x+"px",top:"+="+f.y+"px"});
			self.moveChange(f,"","down");
			clearInterval(self.timeH);
			self.timeH = setInterval(function(){
				self.downLongPress++;
					
					self.setDownSpeed();
				var f = self.getXY(self.rotate,self.curDownSpeed);
				
				//self.imageBg.css({left:"+="+f.x+"px",top:"+="+f.y+"px"});
				self.moveChange(f,"","down");
			
			},40);
		},
            /** 
        * 判断浏览器是否支持某一个CSS3属性 
        * @param {String} 属性名称 
        * @return {Boolean} true/false 
        * @version 1.0 
        * @author ydr.me 
        * 2014年4月4日14:47:19 
    */  
           
		supportCss3 : function(style) {  
			var prefix = ['webkit', 'Moz', 'ms', 'o'],  
			i,  
			humpString = [],  
			htmlStyle = document.documentElement.style,  
			_toHumb = function (string) {  
			return string.replace(/-(\w)/g, function ($0, $1) {  
			return $1.toUpperCase();  
			});  
			};  
			   
			for (i in prefix)  
			humpString.push(_toHumb(prefix[i] + '-' + style));  
			   
			humpString.push(_toHumb(style));  
			   
			for (i in humpString)  
			if (humpString[i] in htmlStyle) return true;  
			   
			return false;  
		},
	   // 对于不支持旋转的浏览器 采用滤镜支持

		ieFilter : function(rd,$img){
			var  dh = $img.height(),
				 dw = $img.width(),
				 dx = -dw/2*Math.cos(rd)+dh/2*Math.sin(rd)+dw/2,
				 dy = -dw/2*Math.sin(rd)-dh/2*Math.cos(rd)+dh/2,
				 filter_car = 'progid:DXImageTransform.Microsoft.Matrix(Dx='+dx+',Dy='+dy+',M11='+Math.cos(rd)+',M12='+(-Math.sin(rd))+',M21='+Math.sin(rd)+',M22='+Math.cos(rd)+')' ;
            //$img.css();
			return filter_car;
		
		},
		// 汽车旋转
		carTransform : function(angle,$img){
			$img.css({transform:"rotate("+angle+"deg)","-ms-transform" : "rotate("+angle+"deg)",
				"-webkit-transform" : "rotate("+angle+"deg)"});
			
			if(!this.isSupportCss3){
				var rd = Raphael.rad(angle),
					filter_car = this.ieFilter(rd,$img);
			    $img.css({filter:filter_car});
			}
		},
	    // 给出一个图片最终点的状态，
		moveToPoint : function(left,top){
			var c_pos = this.testCar.position(),
				i_pos = this.imageBg.position();
			var guide_pos = {
				top : c_pos.top+Math.abs(i_pos.top)+this.testCar.height()/2,
				left : c_pos.left+Math.abs(i_pos.left)+this.testCar.width()/2
			};
			var point_pos = {
				top : top + +Math.abs(i_pos.top),
				left : left + Math.abs(i_pos.left)
			};
			var tar_pos = {
				top : point_pos.top-guide_pos.top,
				left : point_pos.left - guide_pos.left
			};  
			var angle = Raphael.angle(guide_pos.left,guide_pos.top,point_pos.left,point_pos.top);
			//$("#j_shubiao").css({
			//	top:top,
			//	left:left
			//});
			this.testCar.css({transform:"rotate("+(angle-90)+"deg)","-ms-transform" : "rotate("+(angle-90)+"deg)",
				"-webkit-transform" : "rotate("+(angle-90)+"deg)"});
			
			if(!this.isSupportCss3){
				var an = angle-90,
					rd = Raphael.rad(an),
					filter_car = this.ieFilter(rd,this.testCar);
			    this.testCar.css({filter:filter_car});
			}
			// 处理ie9以下的调头采用滤镜
			this.rotate = angle-90;
			function getPointPL(s,e){
						var pl = Math.pow((Math.pow((s.left-e.left),2)+Math.pow((s.top-e.top),2)),0.5);
						return pl*0.002;
					
					}
			var t = getPointPL(point_pos,guide_pos);
			TweenMax.to(this.imageBg,t,{left:"-="+tar_pos.left+"px",top:"-="+tar_pos.top+"px"});
		
		},
		upreleaseRL : function(){
			var self = this;
			var f = self.getXY(self.rotate,self.curSpeed);
				//TweenMax.to($("#testcar"), 0, {left:"+="+f.x+"px",top:"+="+f.y+"px",ease:Linear.easeNone});
			self.setSpeed();
			self.moveChange(f,"","up");
			//self.imageBg.css({left:"-="+f.x+"px",top:"-="+f.y+"px"});
			//self.testCar.attr("src",self.options.path+"/images/car.png");
			clearInterval(self.timeH);
			self.timeH = setInterval(function(){

				self.upLongPress++;
				self.setSpeed();
				var f = self.getXY(self.rotate,self.curSpeed);
				//TweenMax.to($("#testcar"), 0, {left:"+="+f.x+"px",top:"+="+f.y+"px",ease:Linear.easeNone});
				//self.imageBg.css({left:"-="+f.x+"px",top:"-="+f.y+"px"});
				self.moveChange(f,"","up");
				
			},40);
		},
		// 根据速度系数和角度，算出下一步该增加的x、y，同时还有一个坐标轴参数
		getXY : function(ro,dure){
			var t = {
				x : 0,
				y : 0
			};
			var axis = this.options.axis;
			var self = this;
			if(ro>360){ro = ro%360;}
			if(ro<-360) ro = ro%(-360);
			t.x = dure*Math.cos((ro+axis)*Math.PI/180) | 0;
			t.y =  dure*Math.sin((ro+axis)*Math.PI/180) | 0;
			// 目前暂时放在这里做边界判断

			var imgpos = this.imageBg.position();
			//if(self.keyUD==1)
			return t;
		},
		easeIn:function (t, b, c, d) {
			return c * (t /= d) * t + b;
		},
		// 加速度
		setSpeed : function(start){
			var self = this;
			if(self.curSpeed>=self.options.speed){
				
				self.curSpeed = self.options.speed;
			}else{
				self.curSpeed = self.easeIn(self.upLongPress,self.curSpeed,self.options.speed,self.options.speedLong);
			}
		},
			// 加速度
		setDownSpeed : function(start){
			var self = this;
			if(self.curDownSpeed>=self.options.downspeed){
				
				self.curDownSpeed = self.options.downspeed;
			}else{
				self.curDownSpeed = self.easeIn(self.downLongPress,self.curDownSpeed,self.options.downspeed,self.options.downspeedLong);
			}
		},
		// 角速度
		setAngle : function(start){
			var self = this;
			if(self.curAngle>=self.options.tAngle){
				
				self.curAngle = self.options.tAngle;
			}else{
				self.curAngle = self.easeIn(self.upLeft,start||0,self.options.tAngle,100);
			}
		
		},
		// 仅仅向前运动
		pressUp : function(){
			var self = this;
			//self.testCar.attr("src",self.options.path+"/images/car.png");
			self.upLeft = 0;
			clearInterval(self.upLeftSet);
			//self.options.speed * (self.upLongPress*self.upLongPress /6000);//0.005*Math.pow(self.upLongPress,2);c * (t /= d) * t * t + b
			
			self.setSpeed();
			
			var f = self.getXY(self.rotate,self.curSpeed);
			self.moveChange(f,"","up");
			//self.imageBg.css({left:"-="+f.x+"px",top:"-="+f.y+"px"});
			if(self.upDown==0){
				self.upDownSet = setInterval(function(){	
					self.upLongPress++;
					self.setSpeed();
					
					var f = self.getXY(self.rotate,self.curSpeed);
					self.moveChange(f,"","up");
					//self.imageBg.css({left:"-="+f.x+"px",top:"-="+f.y+"px"});
				
				},self.tmpAni);
			}else{
				clearInterval(self.upDownSet);
				
			}
			self.upDown++;	
		
		},
		// 下一步的运动变化
		moveChange : function(point,rotate,dir){
			var self = this,
				add = dir=="down"?"+=":"-=";
			var pos = self.imageBg.position(),
				left = pos.left,
				top = pos.top,
				$body = $('body'),
				cw = $body.width()/2-100,
				ch = $body.height()/2-100,
				bjt = 4607 -ch,
				bjl = 4200-cw;
				
			
			if(dir=="down"){
				// 判断是否超过边界
				var _t = top+point.x,
					_l = left+point.y;
				
				if(_t<-10&&_t>-bjt){
					self.imageBg.css({top:(add+point.y+"px")});
				}else{
					
					//var ro = rotate || 0;
					
					if(_t>=-10){
						self.imageBg.css({top:"-35px"});
					
					}
					if(_t<=-bjt){
						self.imageBg.css({top:"-"+(bjt-30)+"px"});
					}
						self.rotate +=180;
					//self.testCar.css({transform:"rotate("+self.rotate+"deg)","-ms-transform" : "rotate("+self.rotate+"deg)","-webkit-transform":"rotate("+self.rotate+"deg)"});
				    self.carTransform(self.rotate,self.testCar);
				}
				if(_l<0&&_l>-bjl){
					self.imageBg.css({left:(add+point.x+"px")});
				}else{
					if(_l>=0){
						self.imageBg.css({left:"-15px"});
					}
					if(_l<=-bjl){
						self.imageBg.css({left:"-"+(bjl-20)+"px"});
					}
						self.rotate +=180;
						//self.testCar.css({transform:"rotate("+self.rotate+"deg)","-ms-transform" : "rotate("+self.rotate+"deg)","-webkit-transform":"rotate("+self.rotate+"deg)"});
				    self.carTransform(self.rotate,self.testCar);
				}
				// 速度表盘的更新
				$("#speedNum").html(Math.floor(this.curDownSpeed/20*100));
				var rota = -218+Math.floor(this.curDownSpeed/20*180);
				//this.j_speed_guide.css({transform:"rotate("+rota+"deg)","-ms-transform" : "rotate("+rota+"deg)","-webkit-transform":"rotate("+rota+"deg)"});
				self.carTransform(rota,this.j_speed_guide);
				this.wayNum +=this.curDownSpeed;
				
			}else{
				// 判断是否超过边界
				var _t = top-point.x,
					_l = left-point.y;
			
				if(_t<-10&&_t>-bjt){
					self.imageBg.css({top:(add+point.y+"px")});
				}else{
					if(_t>=-10){
						self.imageBg.css({top:"-25px"});
					}
					if(_t<=-bjt){
						self.imageBg.css({top:"-"+(bjt-30)+"px"});
					}
						self.rotate +=180;
						//self.testCar.css({transform:"rotate("+self.rotate+"deg)","-ms-transform" : "rotate("+self.rotate+"deg)","-webkit-transform":"rotate("+self.rotate+"deg)"});
				      self.carTransform(self.rotate,self.testCar);
				}
				if(_l<0&&_l>-bjl){
					self.imageBg.css({left:(add+point.x+"px")});
				}else{
					if(_l>=0){
						self.imageBg.css({left:"-15px"});
					}
					if(_l<=-bjl){
						self.imageBg.css({left:"-"+(bjl-20)+"px"});
					}
						self.rotate +=180;
						//self.testCar.css({transform:"rotate("+self.rotate+"deg)","-ms-transform" : "rotate("+self.rotate+"deg)","-webkit-transform":"rotate("+self.rotate+"deg)"});
				      self.carTransform(self.rotate,self.testCar);
				}
				// 速度表盘的更新
				$("#speedNum").html(Math.floor(this.curSpeed/20*100));
				var rota = -218+Math.floor(this.curSpeed/20*180);
				this.wayNum +=this.curSpeed;
				
				//this.j_speed_guide.css({transform:"rotate("+rota+"deg)","-ms-transform" :"rotate("+rota+"deg)","-webkit-transform":"rotate("+rota+"deg)"});
			    self.carTransform(rota,this.j_speed_guide);
			}
			//self.imageBg.css({left:(add+point.x+"px"),top:(add+point.y+"px")});
			rotate&&self.carTransform(self.rotate,self.testCar);//self.testCar.css({transform:"rotate("+rotate+"deg)","-ms-transform":"rotate("+rotate+"deg)","-webkit-transform":"rotate("+rotate+"deg)"});

			//filter:progid:DXImageTransform.Microsoft.Matrix(M11=m11,M12=m12,M21=m21,M22=m22,sizingMethod="auto expand");progid:DXImageTransform.Microsoft.Matrix(Dx=dx,Dy=dy,M11=m11,M12=m12,M21=m21,M22=m22);dx=-width/2*cosdeg+height/2*sindeg+width/2, dy=-width/2*sindeg-height/2*cosdeg+height/2 m11,m12,m21,m22与前面说的一样。那么m11=cos(x),m12=-sin(x),m21=sin(x),m22=cos(x)
			/*if(rotate){
				var rd = Raphael.rad(rotate),
					width = 300,
					height = 300;
				var dx=-width/2*Math.cos(rd)+height/2*Math.sin(rd)+width/2, dy=-width/2*Math.sin(rd)-height/2*Math.cos(rd)+height/2;
				self.testCar.css({"filter":'progid:DXImageTransform.Microsoft.Matrix(Dx='+dx+',Dy='+dy+',M11='+Math.cos(rd)+',M12='+(-Math.sin(rd))+',M21='+Math.sin(rd)+',M22='+Math.cos(rd)+')'});
			}*/
			rotate&&self.carTransform(rotate,$("#steering"));//$("#steering").css({transform:"rotate("+rotate+"deg)","-ms-transform":"rotate("+rotate+"deg)","-webkit-transform":"rotate("+rotate+"deg)"});
			// 小地图导航的更新
			this.guideAxis();
			
			$("#wayNum").html(Math.floor(this.wayNum/1000));
		},
		// 按下前左
		pressUpLeft : function(){
			var self = this;
			//this.curAngle
			//self.setAngle(0);
			
			var angle = this.options.tAngle,
				speed = this.options.speed;
			self.setSpeed();

			self.rotate = self.rotate-angle;
		
			var f = self.getXY(self.rotate,self.curSpeed);
		//	self.testCar.attr("src",self.options.path+"/images/leftt.gif");	
			self.moveChange(f,self.rotate,"up");
			if(self.upLeft==0){
				self.upLeftSet = setInterval(function(){					
					self.rotate-=angle;
					self.upLongPress++;
					self.setSpeed();
					var f = self.getXY(self.rotate,self.curSpeed);
					self.moveChange(f,self.rotate,"up");
					
				},self.tmpAni);
				 
			}else{
				clearInterval(self.upLeftSet);
				
			}
			self.upLeft++;		
		},
		// 按下 前右
		pressUpRight : function(){
			var self = this,
				angle = this.options.tAngle,
				speed = this.options.speed;
			self.rotate = self.rotate+angle;
			self.setSpeed();
			//self.testCar.attr("src",self.options.path+"/images/rightt.gif");
			var f = self.getXY(self.rotate,self.curSpeed);
			self.moveChange(f,self.rotate,"up");
			if(self.upLeft==0){

				self.upLeftSet = setInterval(function(){
					
					self.rotate+=angle;
					self.upLongPress++;
					self.setSpeed();
					var f = self.getXY(self.rotate,self.curSpeed);
					self.moveChange(f,self.rotate,"up");
					
				},self.tmpAni);
				
			}else{
				clearInterval(self.upLeftSet);
				
			}
			self.upLeft++;		
		
		},
		// 按下 后左
		pressDownLeft : function(){
			var self = this,
				angle = this.options.tAngle,
				speed = this.options.speed;
			self.rotate = self.rotate+angle;
		//	self.testCar.attr("src",self.options.path+"/images/leftt.gif");
			self.setDownSpeed();
			var f = self.getXY(self.rotate,self.curDownSpeed);
			
			self.moveChange(f,self.rotate,"down");
			if(self.upLeft==0){

				self.upLeftSet = setInterval(function(){
					self.downLongPress++;
					self.rotate+=angle;
					self.setDownSpeed();
					var f = self.getXY(self.rotate,self.curDownSpeed);
					self.moveChange(f,self.rotate,"down");
				
				},self.tmpAni);
				
			}else{
				clearInterval(self.upLeftSet);
				
			}
			self.upLeft++;	
		
		},
		// 按下 后右
		pressDownRight : function(){
			var self = this,
				angle = this.options.tAngle,
				speed = this.options.speed;
			self.rotate = self.rotate-angle;
		//	self.testCar.attr("src",self.options.path+"/images/rightt.gif");
			self.setDownSpeed(3);
			var f = self.getXY(self.rotate,self.curDownSpeed);
			
			self.moveChange(f,self.rotate,"down");
			if(self.upLeft==0){

				self.upLeftSet = setInterval(function(){
					self.downLongPress++;
					self.rotate-=angle;
					self.setDownSpeed(3);
					var f = self.getXY(self.rotate,self.curDownSpeed);
					self.moveChange(f,self.rotate,"down");
				
				},self.tmpAni);
				
			}else{
				clearInterval(self.upLeftSet);
				
			}
			self.upLeft++;	
		
		},
		// 仅仅向后运动
		pressDown : function(){
			var self = this;
		//	self.testCar.attr("src",self.options.path+"/images/car.png");
			self.upLeft = 0;
			clearInterval(self.downDownSet);
			//self.options.speed * (self.upLongPress*self.upLongPress /6000);//0.005*Math.pow(self.upLongPress,2);c * (t /= d) * t * t + b
	
			self.setDownSpeed();
			

			var f = self.getXY(self.rotate,self.curDownSpeed);
			self.moveChange(f,"","down");
			//self.imageBg.css({left:"-="+f.x+"px",top:"-="+f.y+"px"});
			if(self.downDown==0){
				self.downDownSet = setInterval(function(){	
					self.downLongPress++;
					self.setDownSpeed();
					
					var f = self.getXY(self.rotate,self.curDownSpeed);
					self.moveChange(f,"","down");
					//self.imageBg.css({left:"-="+f.x+"px",top:"-="+f.y+"px"});
				
				},self.tmpAni);
			}else{
				clearInterval(self.upDownSet);
				
			}
			
			//self.imageBg.css({left:"+="+f.x+"px",top:"+="+f.y+"px"});
		
		},
		// 仅按左键时
		pressLeft : function(){
			var self = this;
			//self.testCar.attr("src",self.options.path+"/images/leftt.gif");
		},
		// 仅按右键时
		pressRight : function(){
			var self = this;
			//self.testCar.attr("src",self.options.path+"/images/rightt.gif");
		}
	
	
	});
    module.exports = carengine;
});