/*
 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
 Code licensed under the BSD License:
 http://developer.yahoo.com/yui/license.html
 version: 3.3.0
 build: 3167
 */
YUI.add('event-flick',function(Y){var EVENT=("ontouchstart"in Y.config.win&&!Y.UA.chrome)?{start:"touchstart",end:"touchend"}:{start:"mousedown",end:"mouseup"},START="start",END="end",OWNER_DOCUMENT="ownerDocument",MIN_VELOCITY="minVelocity",MIN_DISTANCE="minDistance",PREVENT_DEFAULT="preventDefault",_FLICK_START="_fs",_FLICK_START_HANDLE="_fsh",_FLICK_END_HANDLE="_feh",NODE_TYPE="nodeType";Y.Event.define('flick',{on:function(node,subscriber,ce){var startHandle=node.on(EVENT[START],this._onStart,this,node,subscriber,ce);subscriber[_FLICK_START_HANDLE]=startHandle;},detach:function(node,subscriber,ce){var startHandle=subscriber[_FLICK_START_HANDLE],endHandle=subscriber[_FLICK_END_HANDLE];if(startHandle){startHandle.detach();subscriber[_FLICK_START_HANDLE]=null;}
if(endHandle){endHandle.detach();subscriber[_FLICK_END_HANDLE]=null;}},processArgs:function(args){var params=(args.length>3)?Y.merge(args.splice(3,1)[0]):{};if(!(MIN_VELOCITY in params)){params[MIN_VELOCITY]=this.MIN_VELOCITY;}
if(!(MIN_DISTANCE in params)){params[MIN_DISTANCE]=this.MIN_DISTANCE;}
if(!(PREVENT_DEFAULT in params)){params[PREVENT_DEFAULT]=this.PREVENT_DEFAULT;}
return params;},_onStart:function(e,node,subscriber,ce){var start=true,endHandle,doc,preventDefault=subscriber._extra.preventDefault,origE=e;if(e.touches){start=(e.touches.length===1);e=e.touches[0];}
if(start){if(preventDefault){if(!preventDefault.call||preventDefault(e)){origE.preventDefault();}}
e.flick={time:new Date().getTime()};subscriber[_FLICK_START]=e;endHandle=subscriber[_FLICK_END_HANDLE];if(!endHandle){doc=(node.get(NODE_TYPE)===9)?node:node.get(OWNER_DOCUMENT);endHandle=doc.on(EVENT[END],Y.bind(this._onEnd,this),null,node,subscriber,ce);subscriber[_FLICK_END_HANDLE]=endHandle;}}},_onEnd:function(e,node,subscriber,ce){var endTime=new Date().getTime(),start=subscriber[_FLICK_START],valid=!!start,endEvent=e,startTime,time,preventDefault,params,xyDistance,distance,velocity,axis;if(valid){if(e.changedTouches){if(e.changedTouches.length===1&&e.touches.length===0){endEvent=e.changedTouches[0];}else{valid=false;}}
if(valid){params=subscriber._extra;preventDefault=params[PREVENT_DEFAULT];if(preventDefault){if(!preventDefault.call||preventDefault(e)){endEvent.preventDefault();}}
startTime=start.flick.time;endTime=new Date().getTime();time=endTime-startTime;xyDistance=[endEvent.pageX-start.pageX,endEvent.pageY-start.pageY];if(params.axis){axis=params.axis;}else{axis=(Math.abs(xyDistance[0])>=Math.abs(xyDistance[1]))?'x':'y';}
distance=xyDistance[(axis==='x')?0:1];velocity=(time!==0)?distance/time:0;if(isFinite(velocity)&&(Math.abs(distance)>=params[MIN_DISTANCE])&&(Math.abs(velocity)>=params[MIN_VELOCITY])){e.type="flick";e.flick={time:time,distance:distance,velocity:velocity,axis:axis,start:start};ce.fire(e);}
subscriber[_FLICK_START]=null;}}},MIN_VELOCITY:0,MIN_DISTANCE:0,PREVENT_DEFAULT:false});},'3.3.0',{requires:['node-base','event-touch','event-synthetic']});YUI.add('event-move',function(Y){var EVENT=("ontouchstart"in Y.config.win&&!Y.UA.chrome)?{start:"touchstart",move:"touchmove",end:"touchend"}:{start:"mousedown",move:"mousemove",end:"mouseup"},START="start",MOVE="move",END="end",GESTURE_MOVE="gesture"+MOVE,GESTURE_MOVE_END=GESTURE_MOVE+END,GESTURE_MOVE_START=GESTURE_MOVE+START,_MOVE_START_HANDLE="_msh",_MOVE_HANDLE="_mh",_MOVE_END_HANDLE="_meh",_DEL_MOVE_START_HANDLE="_dmsh",_DEL_MOVE_HANDLE="_dmh",_DEL_MOVE_END_HANDLE="_dmeh",_MOVE_START="_ms",_MOVE="_m",MIN_TIME="minTime",MIN_DISTANCE="minDistance",PREVENT_DEFAULT="preventDefault",BUTTON="button",OWNER_DOCUMENT="ownerDocument",CURRENT_TARGET="currentTarget",TARGET="target",NODE_TYPE="nodeType",_defArgsProcessor=function(se,args,delegate){var iConfig=(delegate)?4:3,config=(args.length>iConfig)?Y.merge(args.splice(iConfig,1)[0]):{};if(!(PREVENT_DEFAULT in config)){config[PREVENT_DEFAULT]=se.PREVENT_DEFAULT;}
return config;},_getRoot=function(node,subscriber){return subscriber._extra.root||(node.get(NODE_TYPE)===9)?node:node.get(OWNER_DOCUMENT);},_normTouchFacade=function(touchFacade,touch,params){touchFacade.pageX=touch.pageX;touchFacade.pageY=touch.pageY;touchFacade.screenX=touch.screenX;touchFacade.screenY=touch.screenY;touchFacade.clientX=touch.clientX;touchFacade.clientY=touch.clientY;touchFacade[TARGET]=touchFacade[TARGET]||touch[TARGET];touchFacade[CURRENT_TARGET]=touchFacade[CURRENT_TARGET]||touch[CURRENT_TARGET];touchFacade[BUTTON]=(params&&params[BUTTON])||1;},_prevent=function(e,preventDefault){if(preventDefault){if(!preventDefault.call||preventDefault(e)){e.preventDefault();}}},define=Y.Event.define;define(GESTURE_MOVE_START,{on:function(node,subscriber,ce){subscriber[_MOVE_START_HANDLE]=node.on(EVENT[START],this._onStart,this,node,subscriber,ce);},delegate:function(node,subscriber,ce,filter){var se=this;subscriber[_DEL_MOVE_START_HANDLE]=node.delegate(EVENT[START],function(e){se._onStart(e,node,subscriber,ce,true);},filter);},detachDelegate:function(node,subscriber,ce,filter){var handle=subscriber[_DEL_MOVE_START_HANDLE];if(handle){handle.detach();subscriber[_DEL_MOVE_START_HANDLE]=null;}},detach:function(node,subscriber,ce){var startHandle=subscriber[_MOVE_START_HANDLE];if(startHandle){startHandle.detach();subscriber[_MOVE_START_HANDLE]=null;}},processArgs:function(args,delegate){var params=_defArgsProcessor(this,args,delegate);if(!(MIN_TIME in params)){params[MIN_TIME]=this.MIN_TIME;}
if(!(MIN_DISTANCE in params)){params[MIN_DISTANCE]=this.MIN_DISTANCE;}
return params;},_onStart:function(e,node,subscriber,ce,delegate){if(delegate){node=e[CURRENT_TARGET];}
var params=subscriber._extra,fireStart=true,minTime=params[MIN_TIME],minDistance=params[MIN_DISTANCE],button=params.button,preventDefault=params[PREVENT_DEFAULT],root=_getRoot(node,subscriber),startXY;if(e.touches){if(e.touches.length===1){_normTouchFacade(e,e.touches[0],params);}else{fireStart=false;}}else{fireStart=(button===undefined)||(button===e.button);}
if(fireStart){_prevent(e,preventDefault);if(minTime===0||minDistance===0){this._start(e,node,ce,params);}else{startXY=[e.pageX,e.pageY];if(minTime>0){params._ht=Y.later(minTime,this,this._start,[e,node,ce,params]);params._hme=root.on(EVENT[END],Y.bind(function(){this._cancel(params);},this));}
if(minDistance>0){params._hm=root.on(EVENT[MOVE],Y.bind(function(em){if(Math.abs(em.pageX-startXY[0])>minDistance||Math.abs(em.pageY-startXY[1])>minDistance){this._start(e,node,ce,params);}},this));}}}},_cancel:function(params){if(params._ht){params._ht.cancel();params._ht=null;}
if(params._hme){params._hme.detach();params._hme=null;}
if(params._hm){params._hm.detach();params._hm=null;}},_start:function(e,node,ce,params){if(params){this._cancel(params);}
e.type=GESTURE_MOVE_START;node.setData(_MOVE_START,e);ce.fire(e);},MIN_TIME:0,MIN_DISTANCE:0,PREVENT_DEFAULT:false});define(GESTURE_MOVE,{on:function(node,subscriber,ce){var root=_getRoot(node,subscriber),moveHandle=root.on(EVENT[MOVE],this._onMove,this,node,subscriber,ce);subscriber[_MOVE_HANDLE]=moveHandle;},delegate:function(node,subscriber,ce,filter){var se=this;subscriber[_DEL_MOVE_HANDLE]=node.delegate(EVENT[MOVE],function(e){se._onMove(e,node,subscriber,ce,true);},filter);},detach:function(node,subscriber,ce){var moveHandle=subscriber[_MOVE_HANDLE];if(moveHandle){moveHandle.detach();subscriber[_MOVE_HANDLE]=null;}},detachDelegate:function(node,subscriber,ce,filter){var handle=subscriber[_DEL_MOVE_HANDLE];if(handle){handle.detach();subscriber[_DEL_MOVE_HANDLE]=null;}},processArgs:function(args,delegate){return _defArgsProcessor(this,args,delegate);},_onMove:function(e,node,subscriber,ce,delegate){if(delegate){node=e[CURRENT_TARGET];}
var fireMove=subscriber._extra.standAlone||node.getData(_MOVE_START),preventDefault=subscriber._extra.preventDefault;if(fireMove){if(e.touches){if(e.touches.length===1){_normTouchFacade(e,e.touches[0]);}else{fireMove=false;}}
if(fireMove){_prevent(e,preventDefault);e.type=GESTURE_MOVE;ce.fire(e);}}},PREVENT_DEFAULT:false});define(GESTURE_MOVE_END,{on:function(node,subscriber,ce){var root=_getRoot(node,subscriber),endHandle=root.on(EVENT[END],this._onEnd,this,node,subscriber,ce);subscriber[_MOVE_END_HANDLE]=endHandle;},delegate:function(node,subscriber,ce,filter){var se=this;subscriber[_DEL_MOVE_END_HANDLE]=node.delegate(EVENT[END],function(e){se._onEnd(e,node,subscriber,ce,true);},filter);},detachDelegate:function(node,subscriber,ce,filter){var handle=subscriber[_DEL_MOVE_END_HANDLE];if(handle){handle.detach();subscriber[_DEL_MOVE_END_HANDLE]=null;}},detach:function(node,subscriber,ce){var endHandle=subscriber[_MOVE_END_HANDLE];if(endHandle){endHandle.detach();subscriber[_MOVE_END_HANDLE]=null;}},processArgs:function(args,delegate){return _defArgsProcessor(this,args,delegate);},_onEnd:function(e,node,subscriber,ce,delegate){if(delegate){node=e[CURRENT_TARGET];}
var fireMoveEnd=subscriber._extra.standAlone||node.getData(_MOVE)||node.getData(_MOVE_START),preventDefault=subscriber._extra.preventDefault;if(fireMoveEnd){if(e.changedTouches){if(e.changedTouches.length===1){_normTouchFacade(e,e.changedTouches[0]);}else{fireMoveEnd=false;}}
if(fireMoveEnd){_prevent(e,preventDefault);e.type=GESTURE_MOVE_END;ce.fire(e);node.clearData(_MOVE_START);node.clearData(_MOVE);}}},PREVENT_DEFAULT:false});},'3.3.0',{requires:['node-base','event-touch','event-synthetic']});YUI.add('event-gestures',function(Y){},'3.3.0',{use:['event-flick','event-move']});