package gamecontrol {
	import flash.display.*;
	import flash.geom.*;
  import flash.events.*;
  import flash.net.*;
	import com.terry.engine.*;
	import flash.utils.Dictionary;
	import flash.text.TextField;
	
	public class control {
	  public static function init():void {
			gamecookie = SharedObject.getLocal("movingstories");
			
			for (var i:int = 0; i < 30; i++){
				items.push(new itemclass);
			}
			numitems = 0;
			
			gamephase = GAMEPHASE_PACKING;
			
			suitcasexpos = (def.SCREENWIDTH / 2) - (3 * def.TILESIZE);
	    suitcaseypos = (def.SCREENHEIGHT / 2) - (3 * def.TILESIZE);
			catcagexpos = (def.SCREENWIDTH / 2) - ((3 * def.TILESIZE)/2)+7;
	    catcageypos = (def.SCREENHEIGHT / 2) - ((3 * def.TILESIZE)/2)+8;
			
			for (var j:int = 0; j < 6; j++) {
				for (i = 0; i < 6; i++) {					
					suitcase.push(0);
				}
			}
			
			additem("cat");
			additem("passport");
			additem("travelcard");
			additem("smalldildo"); updatedildo();
			additem("fork");
			additem("knife");
			additem("hand");
			additem("bottle");
			additem("gun");
			additem("mug");
			additem("earplugs");
			additem("mouse");
			additem("book");
			additem("chocolate");
			additem("postit");
			additem("razor");
			additem("scarf"); changescarfname();
			additem("picture");
			additem("teddy");
			additem("ukelele");
			additem("suit1");
			additem("suit2");
			additem("normalclothes");
			additem("partyclothes");
			additem("sunflower");
			itemindex["bin"] = numitems;
			
			if (gamecookie.data.playcount == undefined) {
        gamecookie.data.playcount = 0;
      } else {
        playcount = gamecookie.data.playcount;
      }
			
			reset();
			
			ordertrash();
			
			creditsorder = int(Math.random() * 2);
		}
		
		public static function saveplaycount(t:int):void {
			//set the save cookie!
			gamecookie.data.playcount = t;
		}
		
		public static function updatedildo():void {
			var t:int = itemindex["smalldildo"];
			
			if (playcount % 11 < 5) {
				items[t].position.setTo(61.5, 163);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(2, 1);
				items[t].tile = 71;
				items[t].bintile = 172;
			}else if (playcount % 11 == 5) {
				items[t].position.setTo(49, 151);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(3, 1);
				items[t].tile = 732;
				items[t].bintile = 172;
			}else if (playcount % 11 == 6) {
				items[t].position.setTo(158, 211.5);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(4, 1);
				items[t].tile = 752;
				items[t].bintile = 172;
			}else if (playcount % 11 == 7) {
				items[t].position.setTo(161, 204);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(4, 2);
				items[t].tile = 772;
				items[t].bintile = 152;
			}else if (playcount % 11 == 8) {
				items[t].position.setTo(162, 205);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(5, 2);
				items[t].tile = 812;
				items[t].bintile = 152;
			}else if (playcount % 11 == 9) {
				items[t].position.setTo(153, 203);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(6, 2);
				items[t].tile = 852;
				items[t].bintile = 152;
			}else if (playcount % 11 == 10) {
				items[t].position.setTo(11, 139);
				items[t].initposition.setTo(items[t].position.x, items[t].position.y);
			  items[t].size.setTo(7, 4);
				items[t].tile = 892;
				items[t].bintile = 152;
			}
		}
		
		public static function changescarfname():void {
			boyfriendname();
			items[itemindex["scarf"]].printedname = boyfriend + "'s Scarf";
		}
		
		public static function updatecar():void {
			if (cardelay > 0) {
				cardelay--;
				carposition++;
			}else {
				cardelay = (4 * 60) + (Math.random() * 120);
				carposition = 0;
				cartype = int(Math.random() * 7);
				music.playef("traffic" + String(int(Math.random() * 3) + 1));
			}
		}
		
		public static function initcars():void {
			cardelay = 3*60;
			carposition = 3*60;
		  cartype = 0;
		}
		
		public static function reset():void {
			saveplaycount(playcount);
			playcount++;
			initcars();
			
			showcontrols = 0;
		  showactionmessagetime = 0;
			
			seconds = 0;
			minutes = 0;
			hours = 5;
			
			catframe = 0;
			catframedelay = 0;
			showborders = true;
			
			aim = false;
			chocolatemode = 0;
			shittyworkdinners = false;
			
			bintile = 0;
			buttonpos = 0;
			
			itemmessagetime = 0;
			itemmessage = "";
			
			outcome = MOVING_IN;
			guest = "mum";
			noclothes = false;
			
			xdest = -1; ydest = -1;
			destset = false;
			
			everythingtrashed = false;
			carryingcatcage = false;
			suitcasepacked = false;
			carryingtrash = false;
			catcollected = false;
			dooropened = false;
			catpacked = false;
			bininflat = true;
			carryingsuitcase = false;
			showplayer = true;
			catclicks = 0;
			naked = false;
			
			gamephase = GAMEPHASE_PACKING;
			emptysuitcase();
			
			trashrotationmode = 0;
			trashrotation = 0;
			
			nexttrash = -1;
			previoustrash = -1;
			trashlerp = 0;
			
			starrotation = 0;
			starposition1 = 0;
			starpositiony1 = 0;
			starposition2 = 120;
			starpositiony2 = 0;
			starposition3 = 240;
			starpositiony3 = 0;
			starposition4 = 320;
			starpositiony4 = 0;
			starposition5 = 60;
			starpositiony5 = 0;
			
			catstate = "sleeping";
			catstatedelay = 0;
			
			starinit();
			
			currentitem = "nothing";
		  itemoffset.setTo(0, 0);
			
		  highlighted = "nothing";
			
			highlighttext = "nothing";
			highlighttext_xp = 0;
			highlighttext_yp = 0;
			
			creditsorder = int(Math.random() * 2);
			
			for (var i:int = 0; i < numitems; i++) {
				items[i].create(items[i].name);
			}
			changescarfname();
			updatedildo();
			
			//Occasional items:
			items[itemindex["hand"]].usedingame = (playcount >= 4);
			items[itemindex["bottle"]].usedingame = (playcount >= 3);
			items[itemindex["gun"]].usedingame = (playcount >= 2);
			
			if (playcount == 2) setitemmessage("New item: " + items[itemindex["gun"]].printedname+"!");
			if (playcount == 3) setitemmessage("New item: " + items[itemindex["bottle"]].printedname+"!");
			if (playcount == 4) setitemmessage("Last new item: " + items[itemindex["hand"]].printedname+"!");
		}
		
		public static function ordertrash():void {
			numtrash = 0;
			addtrash("normalclothes");
			addtrash("partyclothes");
			addtrash("suit1");
			addtrash("suit2");
			addtrash("sunflower");
			addtrash("cat");
			addtrash("travelcard");
			addtrash("smalldildo");
			addtrash("fork");
			addtrash("knife");
			addtrash("hand");
			addtrash("bottle");
			addtrash("gun");
			addtrash("mug");
			addtrash("earplugs");
			addtrash("mouse");
			addtrash("book");
			addtrash("chocolate");
			addtrash("razor");
			addtrash("postit");
			addtrash("scarf");
			addtrash("picture");
			addtrash("teddy");
			addtrash("ukelele");
			addtrash("passport");
		}
		
		public static function addtrash(t:String):void {
			trashorder[t] = numtrash;
			trashordernum.push(t);
			numtrash++;
		}
		
		public static function gettransx(t:int):int {
			if (t >= numitems) return 16;
			return (items[t].size.x * def.TILESIZE) / 2;
		}
		
		public static function gettransy(t:int):int {
			if (t == numitems) return 24;
			if (t == numitems + 1) return 16;
			return (items[t].size.y * def.TILESIZE) / 2;
		}
		
		public static function getoutcome():void {
			if (insuitcase("normalclothes")) {
				outcome = MOVING_IN;
				guest = "mum";
			}else if (insuitcase("partyclothes")) {
				outcome = BREAKING_UP;
				guest = "ex";
			}else if (insuitcase("suit1") || insuitcase("suit2")) {
				if (insuitcase("gun")) {
					outcome = SPY;
					guest = "spy";
				}else{
					outcome = NEW_JOB;
					guest = "coworker";
				}
			}else {
				outcome = BREAKING_UP;
				guest = "ex";
				noclothes = true;
			}
		}
		
		public static function dildo_ukelele():Boolean {
			var i:int = 0, j:int = 0;
			for (i = 0; i < numitems; i++) {
				if (items[i].usedingame) {
					if (items[i].insuitcase) {
						j++;
					}
				}
			}
		  if (j != 2) return false;
			if (insuitcase("smalldildo") && insuitcase("ukelele")) return true;
			return false;
		}
		
		public static function dildo_teddy():Boolean {
			var i:int = 0, j:int = 0;
			for (i = 0; i < numitems; i++) {
				if (items[i].usedingame) {
					if (items[i].insuitcase) {
						j++;
					}
				}
			}
		  if (j != 2) return false;
			if (insuitcase("smalldildo") && insuitcase("teddy")) return true;
			return false;
		}
		
		public static function spycase():Boolean {
			if (insuitcase("gun")) {
				if (insuitcase("suit1") || insuitcase("suit2")) {
					if (!insuitcase("normalclothes") && !insuitcase("partyclothes")) {
						return true;
					}
				}
			}
			return false;
		}
		
		public static function emptysuitcase():void {
			for (var j:int = 0; j < 6; j++) {
				for (var i:int = 0; i < 6; i++) {
					suitcase[i + (j * 6)] = 0;
				}
			}
		}
		
		public static function fillsuitcase(x:int, y:int, w:int, h:int):void {
			for (var j:int = y; j < y + h; j++) {
				for (var i:int = x; i < x + w; i++) {
					suitcase[i + (j * 6)] = 1;
				}
			}
		}
		
		public static function removesuitcaseitem(x:int, y:int, w:int, h:int):void {
			for (var j:int = y; j < y + h; j++) {
				for (var i:int = x; i < x + w; i++) {
					suitcase[i + (j * 6)] = 0;
				}
			}
		}
		
		public static function issuitcaseempty():Boolean {
			var i:int = 0, j:int = 0;
			for (i = 0; i < numitems; i++) {
				if (items[i].usedingame) {
					if (items[i].insuitcase) {
						j++;
					}
				}
			}
		  if (j == 0) return true;
			return false;
		}
		
		public static function trashed(t:String):Boolean {
			//Did we trash t?
			if (items[itemindex[t]].trashed) return true;
			return false;
		}
		
		public static function gotpassport():Boolean {
			//Has the passport, or has an empty suitcase
			if (issuitcaseempty()) return true;
			return items[itemindex["passport"]].insuitcase;
		}
		
		public static function insuitcase(t:String):Boolean {
			//Has the passport, or has an empty suitcase
			return items[itemindex[t]].insuitcase;
		}
		
		public static function additem(t:String):void {
			items[numitems].create(t);
			itemindex[t] = numitems;
			numitems++;
		}
		
		public static function persondir(t:String):int {
			if (t == "up") return 1;
			if (t == "down") return 0;
			if (t == "left") return 3;
			if (t == "right") return 2;
			return 0;
		}
		
		public static function start(t:int):void {
			//Init game state from position t
			switch(t) {
				case 0:
					if (obj.nentity > 0) {
						obj.nentity = 0;
						obj.createentity(184, 176, "player");
					}else {
						obj.createentity(184, 176, "player");
					}
					map.loadlevel("movinggame", "apartment");
				break;
			}
		}
		
		public static function gethighlighted():String {
			var i:int = 0;
			while (i < numitems) {
				if (items[i].usedingame && !items[i].binit) {
					if (help.inboxw(mouse.x / 2, mouse.y / 2, items[i].position.x, items[i].position.y, items[i].size.x * def.TILESIZE, items[i].size.y * def.TILESIZE)) {
						return items[i].name;
					}
				}
				i++;
			}
			return "nothing";
		}
		
		public static function getmultihighlighted():String {
			var i:int = 0, t:String = "";
			while (i < numitems) {
				if (items[i].usedingame && !items[i].binit) {
					if (items[i].highlight) {
						if (t == "") {
							t += items[i].printedname;
						}else {
							t += " + " + items[i].printedname;
						}
					}
				}
				i++;
			}
			if (t == "") return "nothing";
			return t;
		}
		
		public static function getspymultihighlighted():String {
			var i:int = 0, t:String = "";
			while (i < numitems) {
				if (items[i].usedingame && !items[i].binit) {
					if (items[i].highlight) {
						if (t == "") {
							t += "Spy " + items[i].printedname;
						}else {
							t += " + " + "Spy " + items[i].printedname;
						}
					}
				}
				i++;
			}
			if (t == "") return "nothing";
			return t;
		}
		
		public static function getxpos(i:int):void {
			if (gamephase == GAMEPHASE_CATPACKING) {
				xpos = items[i].position.x - catcagexpos + 8;
			}else{
				xpos = items[i].position.x - suitcasexpos + 8;
			}
			if (xpos < 0) xpos -= 16;
			xpos = (xpos - (xpos % def.TILESIZE)) / def.TILESIZE;
		}
		
		public static function getypos(i:int):void {
			if (gamephase == GAMEPHASE_CATPACKING) {
				ypos = items[i].position.y - catcageypos + 8;
			}else{
				ypos = items[i].position.y - suitcaseypos + 8;
			}
			if (ypos < 0) ypos -= 16;
			ypos = (ypos - (xpos % def.TILESIZE)) / def.TILESIZE;
		}
		
		public static function moveitems():void {
			for (var i:int = 0; i < numitems; i++) {
				if (items[i].usedingame) {
					if (items[i].binit) {
						if (items[i].cannotbin) {
							items[i].binit = false;
							items[i].returntoinitposition = true;
							items[i].placedinsuitcase = false;
						}else if (items[i].name == "cat") {
							items[i].binit = false;
							items[i].returntoinitposition = true;
							items[i].placedinsuitcase = false;
						}else{
							if (items[i].position.x < def.SCREENWIDTH - (3 * def.TILESIZE)) {
								items[i].position.x += 16;
							}
							
							if (items[i].position.y < def.SCREENHEIGHT - (4 * def.TILESIZE)) {
								items[i].position.y += 10;
							}
							
							if (items[i].position.x >= def.SCREENWIDTH - (4 * def.TILESIZE) &&
									items[i].position.y >= def.SCREENHEIGHT - (5 * def.TILESIZE)) {
								bintile = items[i].bintile;
								items[i].usedingame = false;
								items[i].binit = false;
							}
						}
					}else	if (items[i].returntoinitposition) {
						if (items[i].placedinsuitcase && autobinning) {
							items[i].binit = true;
						}else if (items[i].name == "cat") {
							items[i].binit = false;
							items[i].returntoinitposition = true;
							items[i].placedinsuitcase = false;
						}else{
							if (items[i].position.x < items[i].initposition.x) {
								items[i].position.x += 16;
								if (items[i].position.x > items[i].initposition.x) {
									items[i].position.x = items[i].initposition.x;
								}
							}else if (items[i].position.x > items[i].initposition.x) {
								items[i].position.x -= 16;
								if (items[i].position.x < items[i].initposition.x) {
									items[i].position.x = items[i].initposition.x;
								}
							}
							
							if (items[i].position.y < items[i].initposition.y) {
								items[i].position.y += 10;
								if (items[i].position.y > items[i].initposition.y) {
									items[i].position.y = items[i].initposition.y;
								}
							}else if (items[i].position.y > items[i].initposition.y) {
								items[i].position.y -= 10;
								if (items[i].position.y < items[i].initposition.y) {
									items[i].position.y = items[i].initposition.y;
								}
							}
							
							if (items[i].position.x == items[i].initposition.x &&
									items[i].position.y == items[i].initposition.y) {
								items[i].returntoinitposition = false;		
							}
						}
					}
				}
			}
		}
		
		public static function updatecat():void {
			if (catframedelay > 0) {
				catframedelay--;
			}else {
				if (catstate == "sleeping") {
					catframe = (catframe + 1) % 2;
					catframedelay = 45;
				}else if (catstate == "pickedup") {
					catframe = (catframe + 1) % 3;
					catframedelay = 8;
				}else if (catstate == "bothered2") {
					catframe = (catframe + 1) % 2;
					catframedelay = 10;
				}else if (catstate == "bothered7") {
					catframe = (catframe + 1) % 2;
					catframedelay = 16;
				}else {
					catframe = 0;
				}
			}
			
			if (catstate == "bothered1") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "bothered2";
					catstatedelay=15;
				}
			}else if (catstate == "bothered2") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "bothered3";
					catstatedelay=15;
				}
			}else if (catstate == "bothered3") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "bothered4";
					catstatedelay=6;
				}
			}else if (catstate == "bothered4") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "bothered5";
					catstatedelay=8;
				}
			}else if (catstate == "bothered5") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "bothered6";
					catstatedelay=90;
				}
			}else if (catstate == "bothered6") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "bothered7";
				}
			}else if (catstate == "bothered7") {
				//Make your way back to bed
				var i:int = itemindex["cat"];
				if (int(items[i].position.x) > 10) items[i].position.x -= 1;
				if (int(items[i].position.y) < 200) items[i].position.y += 1;
				if (int(items[i].position.x) < 10) items[i].position.x += 1;
				if (int(items[i].position.y) > 200) items[i].position.y -= 1;
				
				if (int(items[i].position.x) == 10 && int(items[i].position.y) == 200) {
					catstate = "bothered8";
					catstatedelay=90;
				}
			}else if (catstate == "bothered8") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sitdown1";
				}
			}else if (catstate == "sitdown1") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sitdown2";
					catstatedelay=6;
				}
			}else if (catstate == "sitdown2") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sitdown3";
					catstatedelay=6;
				}
			}else if (catstate == "sitdown3") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sitdown4";
					catstatedelay=6;
				}
			}else if (catstate == "sitdown4") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sitdown5";
					catstatedelay=6;
				}
			}else if (catstate == "sitdown5") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sitdown6";
					catstatedelay=6;
				}
			}else if (catstate == "sitdown6") {
				catstatedelay--;
				if (catstatedelay <= 0) {
					catstate = "sleeping";
				}
			}
		}
		
		public static function fadelogic():void {
			if (gfx.fademode == def.FADED_IN && obj.activedoor != "null") {
				gfx.fademode = def.FADE_OUT; gfx.fadeaction = def.FADEACTION_CHANGEROOM;
				obj.activedoordest = obj.activedoor;
			}
			
			if (gfx.fademode == def.FADED_OUT && !game.running) {
				if (gfx.fadeaction == def.FADEACTION_CHANGEROOM) {
					map.change(obj.activedoordest); 
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					game.load("closedoorbehindyou");
					control.dooropened = true;
					control.initcars();
				}else if (gfx.fadeaction == def.FADEACTION_PACKINGMODE) {
					game.gamestate = def.PACKINGMODE;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					game.load("suitcase_opened");
					
				}else if (gfx.fadeaction == def.FADEACTION_AFTERPACKING) {
					game.gamestate = def.WALKABOUTMODE;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					showactionmessagetime = 0;
					
					if (control.dildo_teddy() || control.dildo_ukelele()) {
						game.load("weirdendings");
					}else{
						game.load("suitcase_packed");
					}
					
					items[itemindex["cat"]].position.setTo(11, 199);
					
					if ( control.issuitcaseempty() || control.dildo_teddy() || control.dildo_ukelele()) {
						music.play("endingweird");
					}else if (!control.catpacked) {
						music.play("outdoors");
				  }
				}else if (gfx.fadeaction == def.FADEACTION_TRASHMODE) {
					game.gamestate = def.TRASHMODE;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					showactionmessagetime = 0;
					game.load("takeoutthetrash");
					
					//music.play("packingreview");
					music.play("throwingouttrash");
				}else if (gfx.fadeaction == def.FADEACTION_AFTERTRASH) {
					game.gamestate = def.WALKABOUTMODE;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					showactionmessagetime = 0;
					game.load("everythingtrashed");
				}else if (gfx.fadeaction == def.FADEACTION_INTRO) {
					game.gamestate = def.WALKABOUTMODE;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					showactionmessagetime = 0;
					game.gamestate = def.WALKABOUTMODE;
					game.load("intro");
					
					music.play("initialapartment");
				}else if (gfx.fadeaction == def.FADEACTION_GAMEOVER) {
					game.gamestate = def.GAMEOVER;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					showactionmessagetime = 0; 
				}else if (gfx.fadeaction == def.FADEACTION_TITLE) {
					game.gamestate = def.TITLEMODE;
					gfx.fademode = def.FADE_IN; gfx.fadeaction = def.FADEACTION_NOTHING;
					showactionmessagetime = 0; 
					control.reset();
					
					music.play("titlescreen");
				}
			}
		}
		
		public static function updatetime():void {
			if(!game.running){
				seconds++;
				if (seconds > 60) {
					seconds -= 60;
					minutes--;
					if (minutes < 0) {
						minutes += 60;
						hours--;
					}
					if (minutes > 60) {
						minutes -= 60;
						hours++;
					}
				}
			}
		}
		
		public static function showactionmessage(t:String):void {
			if(!game.running){
				actionmessage = t;
				showactionmessagetime+=10;
				if (showactionmessagetime > 20) showactionmessagetime = 20;
				
				if (mouse.leftpressed()) {
					destinationaction = t;
				}
		  }
		}
		
		public static function getgametime():String {
			if (hours < 0) {
				return "0:00";
			}
			return String(hours) + ":" + help.twodigits(minutes);
		}
		
		public static function starinit():void {
			starpositiony1 = 16;
			starpositiony2 = 48 + (Math.random() * (gfx.screenheight - 96));
			starpositiony3 = 48 + (Math.random() * (gfx.screenheight - 96));
			starpositiony4 = 48 + (Math.random() * (gfx.screenheight - 96));
			starpositiony5 = (gfx.screenheight - 48);
		}
		
		public static function updatestars():void {
			starrotation++;
			if (starrotation > 360) starrotation -= 360;
			
			starposition1 += 2;
			if (starposition1 > gfx.screenwidth + 16) {
				starposition1 -= gfx.screenwidth + 48;
				starpositiony1 = 16;
			}
			
			starposition2 += 1;
			if (starposition2 > gfx.screenwidth + 16) {
				starposition2 -= gfx.screenwidth + 48;
				starpositiony2 = 48 + (Math.random() * (gfx.screenheight - 96));
			}
			
			starposition3 += 2;
			if (starposition3 > gfx.screenwidth + 16) {
				starposition3 -= gfx.screenwidth + 48;
				starpositiony3 = 48 + (Math.random() * (gfx.screenheight - 96));
			}
			
			starposition4 += 2;
			if (starposition4 > gfx.screenwidth + 16) {
				starposition4 -= gfx.screenwidth + 48;
				starpositiony4 = 48 + (Math.random() * (gfx.screenheight - 96));
			}
			
			starposition5 += 2;
			if (starposition5 > gfx.screenwidth + 16) {
				starposition5 -= gfx.screenwidth + 48;
				starpositiony5 = (gfx.screenheight - 48);
			}
			
			if (trashrotationmode == 0) {
				trashrotation += 8;
				if (trashrotation >= 360) trashrotation -= 360;
			}else if (trashrotationmode == 1) {
				if (trashrotation > 10) {
					trashrotation += 8;
					if (trashrotation >= 360) trashrotation = 0;
				}else {
					trashrotation = 0;
				}
			}
			
			if (chocolatemode == 1) {
				if (trashlerp > -gfx.screenheight) {
					trashrotationmode = 0;
					trashlerp -= 4;
				}else {
					trashlerp = -gfx.screenheight;
					chocolatemode = 2;
				}
			}else if (chocolatemode == 2) {
				if (trashlerp > -gfx.screenheight * 2) {
					trashrotationmode = 0;
					trashlerp -= 4;
				}else {
					trashlerp = -gfx.screenheight;
					chocolatemode = 3;
				}
			}else if (chocolatemode == 3) {
				trashrotationmode = 0;
				trashlerp += 4;
				if (trashlerp > 0) {
					trashlerp = 0;
					chocolatemode = 0;
					trashrotationmode = 1;
				}
			}else{
				if (trashlerp > 0) {
					trashrotationmode = 0;
					trashlerp -= 4;
					if (trashlerp < 0) trashlerp = 0;
				}else {
					trashrotationmode = 1;
				}
			}
		}
		
		public static function trashitem(t:int):void {
			trashlerp = gfx.screenheight;
			previoustrash = nexttrash;
			nexttrash = t;
			chocolatemode = 0;
			if (items[t].name == "chocolate" && outcome == BREAKING_UP) {
				chocolatemode = 1;
			}
		}
		
		public static var items:Vector.<itemclass> = new Vector.<itemclass>;
		public static var itemindex:Dictionary = new Dictionary;
		public static var trashorder:Dictionary = new Dictionary;
		public static var trashordernum:Vector.<String> = new Vector.<String>;
 		public static var numitems:int, numtrash:int;
		
		public static var currentitem:String;
		public static var itemoffset:Point = new Point(0, 0);
		
		public static var highlighted:String;
		
		public static var highlighttext:String;
		public static var highlighttext_xp:int;
		public static var highlighttext_yp:int;
		
		public static var suitcase:Vector.<int> = new Vector.<int>;
		
		public static var catframe:int;
		public static var catframedelay:int;
		
		public static var catstate:String = "sleeping";
		public static var catstatedelay:int = 0;
		
		public static var suitcasexpos:int;
	  public static var suitcaseypos:int;
		
		public static var catcagexpos:int;
	  public static var catcageypos:int;
		public static var xpos:int, ypos:int;
		
		public static var bintile:int;
		public static var autobinning:Boolean = false;
		
		public static var trashrotationmode:int = 0;
		public static var trashrotation:int = 0;
		
		public static var nexttrash:int = -1;
		public static var previoustrash:int = -1;
		public static var trashlerp:int = 0;
		
		public static var starrotation:int = 0;
		public static var starposition1:int = 0;
		public static var starpositiony1:int = 0;
		public static var starposition2:int = 120;
		public static var starpositiony2:int = 0;
		public static var starposition3:int = 240;
		public static var starpositiony3:int = 0;
		public static var starposition4:int = 320;
		public static var starpositiony4:int = 0;
		public static var starposition5:int = 60;
		public static var starpositiony5:int = 0;
		
		public static var gametime:int;
		public static var seconds:int, minutes:int, hours:int;
		
		public static var readytoclick:Boolean = false;
		
		public static var gamephase:int;
		public static var gamephasedelay:int;
		public static var gamephasestate:int;
		
		public static var suitcasepacked:Boolean;
		public static var everythingtrashed:Boolean;
		public static var catpacked:Boolean;
		public static var catcollected:Boolean;
		
		public static var buttonpos:int;
		public static var showborders:Boolean;
		
		public static var outcome:int;
		public static var MOVING_IN:int = 0;
		public static var BREAKING_UP:int = 1;
		public static var NEW_JOB:int = 2;
		public static var SPY:int = 3;
		public static var noclothes:Boolean;
		public static var chocolatemode:int;
		
		public static var xdest:int, ydest:int;
		public static var lastxpos:int, lastypos:int;
		public static var lastxpos2:int, lastypos2:int;
		public static var destset:Boolean;
		public static var nexttile:Boolean;
		public static var troublemode:int;
		public static var troubledir:int;
		
		public static var destinationaction:String = "null";
		
		public static var actionmessage:String = "";
		public static var showactionmessagetime:int;
		
		public static var catname:String = "Mittens";
		
		public static function boyfriendname():void {
			if (playcount <= 1) boyfriend = "Mark";
			if (playcount == 2) boyfriend = "Brad";
			if (playcount == 3) boyfriend = "Jack";
			if (playcount == 4) boyfriend = "Will";
			if (playcount == 5) boyfriend = "Paul";
			if (playcount == 6) boyfriend = "Jimm";
			if (playcount == 7) boyfriend = "Eddd";
			if (playcount == 8) boyfriend = "Wxyz";
			if (playcount >= 9) boyfriend = randomletter().toUpperCase() + randomletter() + randomletter() + randomletter();
		}
		
		public static function randomletter():String {
			return letters[int(Math.random() * 26)];
		}
		
		public static var letters:Array = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
		
		public static var boyfriend:String = "Mark";
		
		public static var binname:String = "Rubbish";
		public static var suitcasename:String = "Suitcase";
		public static var flowername:String = "Sunflower";
		public static var exitname:String = "Exit";
		public static var dumpstername:String = "Dumpster";
		public static var flatname:String = "Flat";
		public static var cagename:String = "Transport Box";
		public static var carryingtrash:Boolean;
		public static var carryingcatcage:Boolean;
		public static var carryingsuitcase:Boolean;
		public static var bininflat:Boolean;
		public static var showplayer:Boolean;
		public static var naked:Boolean;
		
		public static var catclicks:int;
		
		public static var GAMEPHASE_PACKING:int = 0;
		public static var GAMEPHASE_ENDPACKING:int = 1;
		public static var GAMEPHASE_CATPACKING:int = 2;
		public static var GAMEPHASE_CATPACKED:int = 3;
		
		public static var dooropened:Boolean;
		
		public static var creditsorder:int;
		
		public static var guest:String;
		public static var aim:Boolean;
		
		public static var showcontrols:int = 0;
		public static var shittyworkdinners:Boolean;
		
		public static var cardelay:int = 0;
		public static var carposition:int = 0;
		public static var cartype:int = 0;
		
		public static function setitemmessage(t:String):void {
			itemmessagetime = 180;
			itemmessage = t;
		}
		
		public static var itemmessagetime:int = 0;
		public static var itemmessage:String = "";
		
		public static var playcount:int = 0;
		
		public static var gamecookie:SharedObject;
		
	}
}