/**
*  @author William Malone (www.williammalone.com)
*/

WM.maskItem = function (GLOBAL, WM, options) {
	
	var that = WM.actor(GLOBAL, WM, options);
		//states = {},
		//currentState,
		//userInteracting = false,
		//userInteractionStart,
		//minSwipeDist = 5;	

	that.type = "MASK";
	that.foundOnTouch = options && options.foundOnTouch;
	that.wiggleOnTouch = options && options.wiggleOnTouch;
	that.touchDisabled = options && options.touchDisabled;
	/*
	that.setState = function (type) {
		
		// State type is not case sensitive
		type = type.toUpperCase();
		
		if (states[type] === undefined) {

		} else {
			//WM.debug("Set State: " + type);
			currentState = type;
		}
	}
	that.addState = function (spec) {
		
		// State type is not case sensitive
		spec.type = spec.type.toUpperCase();
		
		states[spec.type] = WM.view(GLOBAL, WM, spec.ctx, {
			type: spec.type,
			imageResource: spec.imageResource,
			x: spec.x,
			y: spec.y,
			draggable: spec.draggable
		});
	};
	
	that.wiggle = function () {
		states[currentState].wiggle();
	};
	
	that.getBounds = function () {
		return 	{
			x: states[currentState].x,
			y: states[currentState].y,
			width: states[currentState].width,
			height: states[currentState].height
		};
	};
	
	that.update = function () {
		states[currentState].update();
	};
	
	that.render = function () {
		// TODO: not always dirty
		states[currentState].dirty = true;
		states[currentState].render();
	};
	
	that.touchStart = function (point) {
		userInteracting = true;
		userInteractionStart = {x: point.x, y: point.y};
		states[currentState].touchStart(point);
	};
	that.touchMove = function (point) {	
		var dx,
			dy;
			
		if (userInteracting) {
			dx = point.x - userInteractionStart.x;
			dy = point.y - userInteractionStart.y;
			
			if (WM.math.vectors.dist(point, userInteractionStart) > minSwipeDist) {
			
				if (dy < 0) {
					if (Math.abs(dy) > Math.abs(dx)) {
						that.setState("SwipeUp");
					} else {
						if (dx > 0) {
							that.setState("SwipeRight");
						} else {
							that.setState("SwipeLeft");
						}
					}
				} else {
					if (Math.abs(dy) > Math.abs(dx)) {
						that.setState("SwipeDown");
					} else {
						if (dx > 0) {
							that.setState("SwipeRight");
						} else {
							that.setState("SwipeLeft");
						}
					}
				}
			}
		}
		states[currentState].touchMove(point);
	};
	that.touchEnd = function (point) {
		userInteracting = false;
		states[currentState].touchEnd(point);
	};
	that.rectangleCollisionDetection = function (rect) {
		return states[currentState].rectangleCollisionDetection(rect);
	};
	that.getDistanceDragged = function () {
		return states[currentState].getDistanceDragged();
	};*/
	
	return that;
}