function Machine(){
                  this.targGuy = -1;
                  this.oldTargGuy = -1;
                  this.targCount = 0;
                  this.targPose = 0;
	this.xco = 160;
	this.yco = 178;
	this.offY = 0;
	this.offX = 0;
	this.tog = 0;
	this.dragging = 0;
                  this.renderMachine = renderMachine;
	this.handleMachineTouch = handleMachineTouch;
	this.handleMachineDrag = handleMachineDrag;
}

function renderMachine(){
   var elem = document.getElementById( "xRealm" );
   elem.style.clip = "rect( " + (this.yco-50 + this.tog ) + "px " + (this.xco + 50 ) + "px " + (this.yco + 50 ) + "px " + (this.xco-50) + "px)";                
   elem = document.getElementById( "machine" );
   elem.style.left = (this.xco - 58) + "px";
   elem.style.top = (this.yco - 102 ) + "px";
   elem = document.getElementById( "targ" );
   elem.style.backgroundPosition = ( -30 * this.targPose ) + "px 0px";
}

function handleMachineTouch(){
	var hit = 0;
   	if ( Math.abs( touchX - this.xco ) <  35 ){
    	if ( touchY > this.yco - 122 && touchY < this.yco - 58 ) hit = 1;
        if ( touchY < this.yco + 122 && touchY > this.yco + 58 ) hit = 1;
    }
	if ( hit ){
		this.dragging = 1;
		this.offX = this.xco - touchX;
    	this.offY = this.yco - touchY;
	}
    return hit;
}

function handleMachineDrag(){
	if ( this.dragging ){
		this.xco = touchX + this.offX;
    	this.yco = touchY + this.offY;
	}
}
   