// (c) 2007 Kool Community
// by Christer Kaitila
// www.orangeviewgames.com

var CACHEURL = 'cache.php?f='; // 'cache/';

function playbunch()
{
	addlog('Playing Bunch.');
	if (window.minigame) minigame(0);
}

function playsudoku()
{
	addlog('Playing Sudoku.');
	if (window.minigame) minigame(1);
}

function playbuster()
{
	addlog('Playing Cube Buster.');
	if (window.minigame) minigame(2);
}

function playpool()
{
	addlog('Playing pool.');
	if (window.minigame) minigame(3);
}

function playpiano()
{
	addlog('Playing piano.');
	if (window.game_sfxpiano) game_sfxpiano();
}

function playtoilet()
{
	addlog('Flushing toilet.');
	if (window.game_sfxtoilet) game_sfxtoilet();
}

function hoverplayable()
{
	addlog('Click to play.');
	if (window.game_sfxhover) game_sfxhover();
	if (window.xhair) xhair_change_frame(2); // hand
}

function outplayable()
{
	if (window.xhair) xhair_change_frame(0); // hand
}

// level editor definitions: tl,br,foot,radius,hovercallback,clickcallback,outcallback,zofs (999=rug)
var buildables = Array();
buildables['piano'] = [[0,0],[40,40],[20,30],20,hoverplayable,playpiano,outplayable,0]; //  CLICKABLE
buildables['pool table'] = [[40,0],[96,40],[32,32],26,hoverplayable,playpool,outplayable,0]; // CLICKABLE
buildables['roundtable'] = [[96,0],[112,16],[8,10],8,null,null,null,0];
buildables['white chair'] = [[112,0],[136,24],[10,12],16,null,null,null,0];
buildables['bar stool'] = [[136,0],[144,16],[4,12],4,null,null,null,0];
buildables['white couch'] = [[144,0],[191,31],[20,24],20,null,null,null,0];
buildables['bar diagonal'] = [[192,0],[239,32],[20,26],20,null,null,null,0];
buildables['computer desk'] = [[0,40],[40,64],[20,32],-32,hoverplayable,playsudoku,outplayable,0]; //  CLICKABLE rect uses negative collideradius for spawn2008 to use aabb
buildables['glass table'] = [[47,44],[82,64],null,-18,null,null,null,0]; // rect
buildables['kitchen table'] = [[98,28],[154,58],null,-28,null,null,null,0]; // rect
buildables['rainbow rug'] = [[168,40],[228,80],null,0,null,null,null,-999];
buildables['white couch horiz'] = [[240,32],[308,60],null,-32,null,null,null,0]; // rect
buildables['rainbow rug'] = [[168,40],[228,80],null,0,null,null,null,-999];
buildables['toilet vert'] = [[4,66],[25,85],null,10,hoverplayable,playtoilet,outplayable,0]; // CLICKABLE
buildables['yellow chair'] = [[80,64],[102,86],null,10,null,null,null,0];
buildables['kitchen counter'] = [[6,92],[100,120],null,-32,null,null,null,0]; // rect
buildables['lamp'] = [[114,84],[147,123],[5,17],8,null,null,null,0];
buildables['glass table horiz'] = [[154,88],[175,128],null,16,null,null,null,0];
buildables['small shelf horiz'] = [[32,70],[60,85],null,-16,null,null,null,0]; // rect
buildables['small shelf vert'] = [[183,90],[192,124],null,-16,null,null,null,0]; // rect
buildables['fridge'] = [[204,86],[222,124],null,-16,null,null,null,0]; // rect
buildables['glass table horiz'] = [[154,88],[175,128],null,16,null,null,null,0];
buildables['kitchen table vert'] = [[230,66],[255,125],null,-16,null,null,null,0]; //rect
buildables['couch west'] = [[262,76],[290,124],null,-16,null,null,null,0]; // rect
//buildables['towel rack'] = [[16,134],[28,145],null,0,null,null,null,0];
buildables['couch horiz'] = [[38,125],[85,154],null,-16,null,null,null,0]; // rect
buildables['green drawers'] = [[92,136],[112,154],null,-16,null,null,null,0]; // rect
buildables['red chair'] = [[116,126],[140,154],null,-16,null,null,null,0]; // rect
buildables['yellow chair diag'] = [[150,128],[172,152],null,10,null,null,null,0];
buildables['red drawers'] = [[177,130],[210,152],null,-16,null,null,null,0];//
buildables['entertainment unit'] = [[222,130],[288,152],null,-32,hoverplayable,playbuster,outplayable,0];// CLICKABLE
buildables['white couch vert'] = [[0,148],[28,215],null,-32,null,null,null,0];//
buildables['toilet horiz'] = [[34,168],[53,194],null,-16,hoverplayable,playtoilet,outplayable,0];// CLICKABLE
buildables['computer desk vert'] = [[56,162],[75,208],null,-32,hoverplayable,playbunch,outplayable,0];// CLICKABLE
buildables['white couch vert'] = [[0,148],[28,215],null,32,null,null,null,0];
buildables['stove'] = [[82,162],[102,188],null,-32,null,null,null,0];//
buildables['green drawers vert'] = [[116,162],[130,190],null,-32,null,null,null,0];//
buildables['blue shelf unit'] = [[80,194],[108,210],null,-32,null,null,null,0];//
buildables['round rug'] = [[116,194],[134,212],null,0,null,null,null,-999];
buildables['checkered rug'] = [[144,160],[192,214],null,0,null,null,null,-999];
buildables['modern rug'] = [[198,162],[256,206],null,0,null,null,null,-999];
buildables['dining table'] = [[260,166],[308,208],null,-32,null,null,null,0];//
// wicked arcade machines 16x36 Bunch, Sudoku, Cube Buster,Pool
buildables['Bunch'] = [[0,217],[15,248],[8,24],8,hoverplayable,playbunch,outplayable,32];
buildables['Sudoku'] = [[20,217],[35,248],[8,24],8,hoverplayable,playsudoku,outplayable,32];
buildables['Cube Buster'] = [[40,217],[55,248],[8,24],8,hoverplayable,playbuster,outplayable,32];




var leveleditor_all_the_time = true;
var gohome_toggles_leveleditor = false; // if false, no editor gui
var txtmsgenabled = true;

var walkcycle_loop_numframes = 3; //5; // frame cycle.. but direction_to_frame uses *this
var walkcycle_loop = 1; // .anim_loop constant
var walkcycle_1213 = 2; // .anim_loop constant
var avatar_walkcycle_mode = walkcycle_1213;

//var loginfaces = ['suave','amazon','redshirt','warrior']; // must agree with ajax.php bots
var highdef_avatars = false; // standard gif sprite sheet
var avatar_file_extension = '.gif'; // for login GUI images only...

var specific_start_x = 5088; // near west side apts
var specific_start_y = 4888;

//var specific_start_x = 5024; //5950; // at crossroads // must match css
//var specific_start_y = 4892; //5150;

//var specific_start_x = 4100;
//var specific_start_y = 4200;
//var specific_viewport_start_x = 3800; // must agree with css div.level
//var specific_viewport_start_y = 3800;


var loginfaces = ['spike','tails','braids','norm','red','blue']; // duped in php for bots
//ms6 var AVATARW = 20;
//ms6 var AVATARH = 50;
var AVATARW = 10;
var AVATARH = 25;

var viewport_can_scroll = false;	// allow camera to move?
var smooth_scroll_viewport = false; 	// smooth chase camera movement
var floor_scale = 0.5; 			// half as big and half as far apart
var floor_offset = 2222;		// shifted over to account for scale
var props_scale = 1.0; //0.5; 			// half as big and half as far apart
var props_offset = 0;//2222;		// shifted over to account for scale
var props_default_radius = 32; 		// ms5: 64


// minigame flash wrapper html
var mini_html_start = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='100%' height='100%'><param name='quality' value='high' /><param name='menu' value='false' /><param name='movie' value='cache.php?f=";
var mini_html_mid   ="' /><embed src='cache.php?f=";
var mini_html_end   ="' menu='false' quality='high' name='acidfactory' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' width='100%' height='100%' /></object>";
var minigame_s_margin = 128;
var minigame_t_margin = 70;
var minigame_b_margin = 242;

var precache_many_images = false;
var cache_padpad_hover_gif = new Image();
var cache_arcade_hover_gif = new Image();
var cache_padpad_hover_src = CACHEURL+'phatpad_outside_mouseover.jpg';
var cache_arcade_hover_src = CACHEURL+'arcade_outside_800x600_hover.gif';
var cache_button_gif = new Image();
var cache_button_hover_gif = new Image();
var cache_blank_gif = new Image();
var cache_login_gif = new Image();
var cache_login_over_gif = new Image();
var cache_avatars_gif = new Image();
var cache_phone_button = new Image();
var cache_chat_gif = new Image();
var cache_chat_over_gif = new Image();
var cache_help_gif = new Image();
var cache_help_over_gif = new Image();
var cache_login_leftarrow_gif = new Image();
var cache_login_rightarrow_gif = new Image();
var cache_login_head_blue = new Image();
var cache_login_head_spike = new Image();
var cache_login_head_red = new Image();
var cache_login_head_norm = new Image();
var cache_login_head_tails = new Image();
var cache_login_head_braids = new Image();
var cache_floors = new Image(); cache_floors.src = CACHEURL+'floors.jpg'; // CACHE NOW IE6
var cache_blank_gif_src = CACHEURL+'blank.gif';
var cache_login_gif_src = CACHEURL+'login_button.gif';
var cache_login_over_gif_src = CACHEURL+'login_button_over.gif';
var cache_avatars_gif_src = CACHEURL+'avatars.gif';
var cache_phone_button_src = CACHEURL+'phone_button.gif';
var cache_chat_gif_src = CACHEURL+'comm_chat_116x69.gif';
var cache_chat_over_gif_src = CACHEURL+'comm_chat_116x69_hover.gif';
var cache_help_gif_src = CACHEURL+'comm_help_69x69.gif';
var cache_help_over_gif_src = CACHEURL+'comm_help_69x69_hover.gif';
var cache_login_leftarrow_gif_src = CACHEURL+'login_arrow_left.gif';
var cache_login_rightarrow_gif_src = CACHEURL+'login_arrow_right.gif';
var cache_login_head_blue_src = CACHEURL+'head_blue.gif';
var cache_login_head_spike_src = CACHEURL+'head_spike.gif';
var cache_login_head_red_src = CACHEURL+'head_red.gif';
var cache_login_head_norm_src = CACHEURL+'head_norm.gif';
var cache_login_head_tails_src = CACHEURL+'head_tails.gif';
var cache_login_head_braids_src = CACHEURL+'head_braids.gif';
var cache_button_gif_src = CACHEURL+'button.gif';
var cache_button_hover_gif_src = CACHEURL+'buttonhover.gif';

// the minigame runs in an iframe
var minigame_iframe_html = "<iframe onclick='minigameclick()' id='minigameframe' src='http://www.orangeviewgames.com/community/puzzle/index.php' border='0' marginheight='0' marginwidth='0' frameborder='0' scrolling='no' noresize='noresize' allowtransparency='true'></iframe>";
var minigame_idle_html = "<img src='"+CACHEURL+"findandwin_overlay.jpg'>";



function load_level(levelnum)
{ // spawn a bunch of prefabs - hardcoded fixme
	if (debug) addlog('Loading level...');

	// city v2 - north shore
	queue("spawnaabb([0,0],[9999,4848]);");

	//function spawn2008(spawnxy,tiletl,tilebr,footxy,collideradius,sheetclass,divclass,hovercallback,clickcallback,outcallback,zofs,nocollide)

	// CITY OVERLAY!
	
	// 0,0 in overlay is 4389,4538
	//var offx = 4389; var offy = 4538;
	//queue("spawn2008([770+offx,542+offy],[770,542],[900,650],[70,98],8,'city_fg','overlay',null,null,null,0,false);");

	// far left nogo big
	queue("spawnaabb([4380,4739],[4452,6666]);");
	// west side big tree:
	queue("spawn2008([5160,5083],[770,542],[900,650],[70,98],8,'city_fg','overlay',null,null,null,0,false);");
	// west side X bushes
	queue("spawn2008([5278,5077],[936,610],[975,642],[22,22],12,'city_fg','overlay',null,null,null,0,false);");
	// fudge the one X bush coords
	queue("spawn2008([5346,5078],[936,610],[975,642],[22,22],12,'city_fg','overlay',null,null,null,0,false);");
	queue("spawn2008([5369,5005],[936,610],[975,642],[22,22],12,'city_fg','overlay',null,null,null,0,false);");
	// far left partial
	queue("spawnaabb([4448,4828],[4715,4917]);");
	// far left big tree, x,x,x
	//[4550,5080],[4667,5078],[4724,5079],[4744,4995],
	// DEF building
	queue("spawnaabb([5261,4832],[5382,4981]);");
	// far left 3 streetlights
	//[4605,5148],[5420,5127],[5445,4990],
	// hidden light
	//[5701,4991],
	// hospital nogo big
	queue("spawnaabb([4496,5449],[5327,6666]);");
	// crossroads streetlights
	//[5246,5305],[5698,5329],[5653,5490],[5878,5146],
	// hidden blue building xroads
	queue("spawnaabb([5852,4000],[6052,5025]);");
	// Flynns
	queue("spawnaabb([5820,5401],[5965,5499]);");
	// downtown light
	//[6701,5146],
	// uptown x,x,tree,tree
	//[6452,5340],[6454,5364],[6658,5512],[6687,5363],
	// STORE building aabb partial perfect!
	queue("spawn2008([6551,5429],[2154,862],[2296,994],[77,123],[[-78,-50],[67,5]],'city_fg','overlay',null,null,null,0,false);");
	// far right building
	queue("spawnaabb([7080,4800],[9999,5181]);");
	// PQR
	queue("spawnaabb([6701,4785],[7147,5082]);");
	// MNO
	queue("spawnaabb([6394,4788],[6661,5089]);");
	// blue building
	queue("spawnaabb([6090,4740],[6287,4971]);");
	// VWXYZ
	queue("spawnaabb([6249,5643],[6465,6666]);");
	// uptown nogo: flyns+big to bottom
	queue("spawnaabb([5938,5400],[6274,6666]);");
	// bottom of crossroads and below nogo
	queue("spawnaabb([5300,5700],[9999,6666]);");
	// bottom right mini building big
	queue("spawnaabb([7201,5417],[9999,6666]);");
	
	
	
	
	
	
	
	// buildings that should be overlays: fixme poo
	// white spawn building
	queue("spawnaabb([4936,4871],[5075,5106]);");
	// ghi
	queue("spawnaabb([4735,5013],[5001,6666]);");
	// jkl
	queue("spawnaabb([4972,5199],[5153,5473]);");
	// jkl lower + tree
	queue("spawnaabb([5129,5310],[5315,5465]);");
	// huge mid building overlay
	queue("spawnaabb([5936,4992],[6273,5405]);");
	// small mid over and trees (STU building)
	queue("spawnaabb([6225,4910],[6397,5531]);");
	// rightmost big overlay partial
	queue("spawnaabb([6840,5095],[9999,6666]);");
	// tree+right over
	queue("spawnaabb([6651,5279],[9999,6666]);");
	
	
	
	
	
	
	
	
	
	
	// new mini apartment 2008
	// big outer walls
	queue("spawnaabb([7000,7000],[9000,7650]);"); // back wall plus
	queue("spawnaabb([7000,7780],[9000,9000]);"); // front wall plus
	queue("spawnaabb([7000,7000],[7634,9000]);"); // left wall plus
	queue("spawnaabb([8080,7000],[9000,9000]);"); // right wall plus
	// six thin vertical walls |||
	queue("spawnaabb([7776,7616],[7786,7712]);");
	queue("spawnaabb([7872,7616],[7882,7712]);");
	queue("spawnaabb([7680,7712],[7690,7744]);");
	queue("spawnaabb([7744,7712],[7754,7712]);");
	queue("spawnaabb([7744,7744],[7754,7808]);");
	queue("spawnaabb([7944,7744],[7954,7808]);");
	// five thin horiz walls and partial stairs ---
	queue("spawnaabb([7658,7700],[7754,7710]);");
	queue("spawnaabb([7778,7722],[7842,7732]);");
	queue("spawnaabb([7870,7722],[7958,7732]);");
	queue("spawnaabb([7616,7754],[7744,7764]);");
	queue("spawnaabb([7808,7754],[7914,7764]);");
	// UPSTAIRS
	// big outer walls only
	queue("spawnaabb([17000,17000],[19000,17650]);");
	queue("spawnaabb([17000,17772],[19000,19000]);");
	queue("spawnaabb([17000,17000],[17634,19000]);");
	queue("spawnaabb([18080,17000],[19000,19000]);");
	// stairs
	queue("spawnaabb([17792,17736],[17864,17800]);");



	// mini store milestone 6 800x400 rectangle
	queue("spawnaabb([-474,7471],[762,7630]);"); // top
	queue("spawnaabb([-475,7474],[-380,8194]);"); // left
	queue("spawnaabb([-474,7940],[774,8232]);"); // bottom
	queue("spawnaabb([380,7475],[600,8205]);"); // right
	// the counter C
	queue("spawnaabb([-47,7708],[68,7770]);"); // top
	queue("spawnaabb([36,7746],[77,7838]);"); // right
	queue("spawnaabb([-47,7820],[68,7888]);"); // bottom
	



	// mini arcade milestone 6 800x400 rectangle
	queue("spawnaabb([-474,17471],[762,17630]);"); // top
	queue("spawnaabb([-475,17474],[-380,18194]);"); // left
	queue("spawnaabb([-474,17940],[774,18232]);"); // bottom
	queue("spawnaabb([380,17475],[600,18205]);"); // right
	// fake props 
	queue("spawnaabb([-497,17455],[-52,17652]);");
	queue("spawnaabb([-132,17642],[-72,17675]);");
	queue("spawnaabb([230,17563],[415,17707]);");









	/*
	// city version one milestone 5
	// the kool city bubbles north
	queue("spawn_circle_collider([4570,4720],64);");
	queue("spawn_circle_collider([4730,4690],64);");
	queue("spawn_circle_collider([4950,4740],64);");
	queue("spawn_circle_collider([5160,4710],90);");
	queue("spawn_circle_collider([5390,4760],100);");
	// south block
	queue("spawn_circle_collider([4545,5020],200);");
	queue("spawn_circle_collider([4986,5030],52);");
	queue("spawn_circle_collider([5110,5130],200);");
	// river
	queue("spawnaabb([0,0],[9999,4645]);");
	queue("spawnaabb([5330,0],[9999,4700]);");
	*/

	/*
	// test inventory loop works
	var itemlist = 'apple,banana,book,brocoli,bucket,cherry,chocolate0,chocolate1,chocolate2,chocolate3,chocolates,coffee,coin,cookie,corn,cupcake,dessert,flower0,flowers,gemcircle,gemsquare,gemtear,glove,lemon,lily,loaf,mushroom,newspaper,novel,onion,orange,pea,pepper,pie,pizza,popcorn,soap,soda,strawberry,teapot,tissue,trumpet,violin,wagon,watermelon';
	var itemarray = itemlist.split(',');
	var itemx = 4000;
	var itemy = 5000;
	var itemcount = 0;
	var itemxofs = 64;
	var itemyofs = 0;
	for (nextone in itemarray)
	{
		cuethis = "spawnpickup('"+itemarray[nextone]+"',"+(itemx+(itemxofs*itemcount))+","+(itemy+(itemyofs*itemcount))+");";
		itemcount++;
		queue(cuethis);
	}
	*/

	// items near spawn
	queue("spawnpickup('novel',4869,4952);");
	queue("spawnpickup('banana',5135,4829);");
	queue("spawnpickup('pie',5324,4751);");
	queue("spawnpickup('cupcake',5376,5025);");
	queue("spawnpickup('bucket',5058,5063);");
	// items near crossroads
	queue("spawnpickup('cherry',5429,5311);");
	queue("spawnpickup('chocolate0',5338,5445);");
	queue("spawnpickup('pie',5644,5564);");
	queue("spawnpickup('coffee',5888,5373);");
	queue("spawnpickup('newspaper',5682,5139);");
	queue("spawnpickup('cupcake',5765,5373);");
	queue("spawnpickup('novel',5395,5333);");
	// items near downtown
	queue("spawnpickup('newspaper',6428,5136);");
	queue("spawnpickup('lily',6738,5138);");
	queue("spawnpickup('pie',6717,4961);");
	queue("spawnpickup('chocolate1',7082,4999);");
	queue("spawnpickup('soda',7037,5078);");
	queue("spawnpickup('coin',6803,5337);");
	queue("spawnpickup('soap',6358,5004);");
	// items near westside
	queue("spawnpickup('lily',6548,5518);");
	queue("spawnpickup('coin',6363,5553);");
	queue("spawnpickup('pie',6374,5405);");
	queue("spawnpickup('chocolate2',6737,5389);");
	queue("spawnpickup('newspaper',6526,5724);");
	queue("spawnpickup('chocolate3',6275,5558);");
	queue("spawnpickup('novel',6506,5461);");
	queue("spawnpickup('soda',6597,5458);");

	/*
	// 48 hidden items scattered all over
	queue("spawnpickup('apple',5090,5336);"); // under mid street tree
	queue("spawnpickup('banana',3438,4959);"); // far left dead end tree
	queue("spawnpickup('book',3873,5493);"); // sidewalk by far left car
	queue("spawnpickup('brocoli',8029,5502);"); // by signpost far right
	queue("spawnpickup('bucket',7016,4327);"); // north beach
	queue("spawnpickup('cherry',13971,14464);"); // in arcade top left
	queue("spawnpickup('chocolate0',8877,5266);"); // far right dead end top
	queue("spawnpickup('chocolate1',8877,5480);"); // far right dead end bot
	queue("spawnpickup('chocolate2',8116,4247);"); // far right sidewalk middle
	queue("spawnpickup('chocolate3',13948,14580);"); // arcade near door
	queue("spawnpickup('chocolates',13923,14610);"); // arcade near door
	queue("spawnpickup('coffee',7885,5236);"); // farther right sidewalk
	queue("spawnpickup('coin',6973,4608);"); // mini island
	queue("spawnpickup('cookie',7116,5374);"); // middle of road far right
	queue("spawnpickup('corn',7208,4202);"); // top picnic
	queue("spawnpickup('cupcake',14543,14335);"); // arcade top right
	queue("spawnpickup('dessert',14452,14335);"); // arcade top right
	queue("spawnpickup('flower0',5402,5772);"); // font door of far right lower house
	queue("spawnpickup('flowers',4556,14266);"); // in house right window
	queue("spawnpickup('gemcircle',3904,4991);"); // inside traffic circle top
	queue("spawnpickup('gemsquare',3904,5248);"); // inside traffic circle bottom
	queue("spawnpickup('gemtear',7236,4862);"); // bottom mid shore
	queue("spawnpickup('glove',5649,4007);"); // north car door
	queue("spawnpickup('lemon',6395,3970);"); // north dead end right
	queue("spawnpickup('lily',5351,4932);"); // front next door
	queue("spawnpickup('loaf',5954,3851);"); // top left sidewalk
	queue("spawnpickup('mushroom',5088,4359);"); // north back yards
	queue("spawnpickup('newspaper',4736,4950);"); // by front door mid house
	queue("spawnpickup('novel',5787,5009);"); // nearby right signpost
	queue("spawnpickup('onion',5084,5927);"); // south front yards
	queue("spawnpickup('orange',4153,5001);"); // sidewalk corner nearest arcade
	queue("spawnpickup('pea',5784,5390);"); // crossroads sourth west lawn
	queue("spawnpickup('pepper',5847,5869);"); // crossroads south deadend corner
	queue("spawnpickup('pie',5450,5232);"); // mid street lower sidewalk
	queue("spawnpickup('pizza',14308,14530);"); // arcade middle
	queue("spawnpickup('popcorn',14264,14530);"); // arcade middle
	queue("spawnpickup('soap',4206,14330);"); // house left wall
	queue("spawnpickup('soda',4546,14565);"); // house middle
	queue("spawnpickup('strawberry',6836,5130);"); // beach road top sidewalk
	queue("spawnpickup('teapot',4218,14279);"); // in house by window
	queue("spawnpickup('tissue',4313,14279);"); // in house by window
	queue("spawnpickup('trumpet',7617,4614);"); // far east beach
	queue("spawnpickup('violin',8384,4225);"); // far east tree
	queue("spawnpickup('wagon',6702,4735);"); // on beach
	queue("spawnpickup('watermelon',6542,4868);"); // by picnic
	*/

	// table inside the house
	//queue("sid('umbrellas',[[6496,4832],[7104,4256],[4555,14520]],64);");


	/* milestone 5 perfect, working, large, scrolling, level
	// IE fixme
	// in IE6, each sprite adds 2-8 megs of RAM use!
	// This inits insanely slow and IE uses 350 megs of ram.
	// Once inits are over, the FPS is high... but inits > 60 sec
	// In firefox, ram use is medium (35meg) and speed is very high (2 sec)
	// overall: make all non-animated sprites individual imgs speed+ram - no SHEETs unless animated!
	// load level: fixme: make this a server ajax response for >1 level!
	// big road and two intersections
	queue("f(1,[5120,5056],1);f(1,[5248,5056],1);f(1,[5376,5056],1);f(1,[5504,5056],1);f(1,[5632,5056],1);f(1,[5760,5056],1);f(0,[5888,5056],2);f(1,[6016,5056],2);f(2,[6016,5184],2);f(3,[5888,5184],2);f(3,[5760,5184],1);f(3,[5632,5184],1);f(3,[5504,5184],1);f(3,[5376,5184],1);f(3,[5248,5184],1);f(3,[5120,5184],1);f(3,[4992,5184],1);f(3,[4864,5184],1);f(3,[4736,5184],1);f(3,[4608,5184],1);f(3,[4480,5184],1);f(3,[4352,5184],1);f(3,[4224,5184],1);f(2,[4096,5184],2);f(3,[3968,5184],2);f(0,[3968,5056],2);f(1,[4096,5056],2);f(1,[4224,5056],1);f(1,[4352,5056],1);f(1,[4480,5056],1);f(1,[4608,5056],1);f(1,[4736,5056],1);f(1,[4864,5056],1);f(1,[4992,5056],1);");
	// arcade street
	queue("f(0,[7936,5184],1);f(0,[7936,5056],1);f(0,[7936,4928],1);f(0,[7936,4800],1);f(0,[7936,4672],1);f(0,[7936,4544],1);f(0,[7936,4416],1);f(0,[7936,4288],1);f(0,[7936,4160],1);f(3,[7936,4032],2);f(3,[7808,4032],1);f(3,[7680,4032],1);f(3,[7552,4032],1);f(3,[7424,4032],1);f(3,[7296,4032],1);f(3,[7168,4032],1);f(3,[7040,4032],1);f(3,[6912,4032],1);f(3,[6784,4032],1);f(3,[6656,4032],1);f(3,[6528,4032],1);f(3,[6400,4032],9);f(0,[6400,3904],9);f(1,[6528,3904],1);f(1,[6656,3904],1);f(1,[6784,3904],1);f(1,[6912,3904],1);f(1,[7040,3904],1);f(1,[7168,3904],1);f(1,[7296,3904],1);f(1,[7424,3904],1);f(1,[7552,3904],1);f(1,[7680,3904],1);f(1,[7808,3904],1);f(1,[7936,3904],1);f(1,[8064,3904],9);f(2,[8064,4032],1);f(2,[8064,4160],1);f(2,[8064,4288],1);f(2,[8064,4416],1);f(2,[8064,4544],1);f(2,[8064,4672],1);f(2,[8064,4800],1);f(2,[8064,4928],1);f(2,[8064,5056],1);f(2,[8064,5184],1);f(1,[8192,5312],1);f(1,[8320,5312],1);f(1,[8448,5312],1);f(1,[8576,5312],1);f(1,[8704,5312],1);f(1,[8832,5312],9);f(2,[8832,5440],9);f(3,[8704,5440],1);f(3,[8576,5440],1);f(3,[8448,5440],1);f(3,[8320,5440],1);f(3,[8192,5440],1);");
	// west road loopy
	queue("f(3,[3968,4928],2);f(2,[3840,4928],2);f(1,[3840,5056],2);f(2,[3840,5184],2);f(1,[3840,5312],2);f(0,[3968,5312],2);f(2,[4096,4928],1);f(2,[4096,5312],1);f(1,[4096,4800],9);f(2,[4096,5440],9);f(3,[3968,5440],1);f(3,[3840,5440],1);f(0,[3712,5312],1);f(0,[3712,5184],1);f(0,[3712,5056],1);f(1,[3968,4800],1);f(1,[3840,4800],1);f(0,[3712,4800],9);f(3,[3712,5440],9);f(0,[3712,4928],1);");
	// signposts
	queue("sid('signposts',[[4224,5008],[5760,5008],[8000,5496]],16);");
	// road to the right of house
	queue("f(0,[5888,4928],1);f(0,[5888,4800],1);f(0,[5888,4672],1);f(0,[5888,4544],1);f(0,[5888,4416],1);f(0,[5888,4288],1);f(0,[5888,4160],1);f(3,[5888,4032],2);f(2,[6016,4032],2);f(3,[5760,4032],1);f(2,[6016,4160],1);f(2,[6016,4288],1);f(2,[6016,4416],1);f(2,[6016,4544],1);f(2,[6016,4672],1);f(2,[6016,4800],1);f(2,[6016,4928],1);");
	// south shore
	queue("f(1,[6528,4928],3);f(1,[6656,4928],3);f(1,[6400,4928],4);f(2,[6400,4800],3);f(2,[6528,4800],0);f(2,[6656,4800],0);f(1,[6656,4672],5);f(3,[6784,4672],7);f(1,[6784,4800],6);f(3,[6912,4800],7);f(1,[6912,4928],6);f(1,[7040,4928],5);f(0,[7168,4928],6);f(2,[7168,4800],7);f(3,[7296,4800],7);f(2,[7424,4800],7);f(1,[7296,4928],6);f(0,[7424,4928],6);");
	// perfect top shore
	queue("f(1,[6528,4672],6);f(2,[6528,4544],6);f(0,[6656,4544],7);f(0,[6784,4416],7);f(2,[6656,4416],6);f(2,[6784,4288],6);f(3,[6912,4288],6);f(1,[6912,4416],7);f(3,[7040,4416],5);f(3,[7168,4416],6);f(1,[7168,4544],7);f(0,[7296,4544],7);f(1,[7424,4544],7);f(3,[7552,4544],6);f(1,[7552,4672],7);f(3,[7680,4672],6);f(0,[7680,4800],6);f(1,[7552,4800],5);f(2,[7296,4416],6);f(3,[7424,4416],6);");
	// the lake and island
	queue("f(3,[6784,4544],0);f(2,[6912,4544],7);f(3,[7040,4544],7);f(0,[7040,4672],7);f(1,[6912,4672],7);f(3,[7040,4800],0);f(3,[7168,4672],0);f(3,[7296,4672],0);f(3,[7424,4672],0);");
	// north shore missing certain corners
	queue("f(2,[6400,4672],3);f(2,[6400,4544],3);f(3,[6784,4160],3);f(3,[6912,4160],3);f(3,[7040,4160],3);f(3,[7168,4160],3);f(3,[7296,4160],4);f(3,[7424,4288],3);f(0,[7808,4672],3);f(0,[7808,4800],3);f(1,[6912,5056],3);f(1,[7040,5056],3);f(1,[7168,5056],3);f(1,[7296,5056],3);f(1,[7424,5056],3);f(1,[7680,4928],3);f(0,[7552,5056],4);f(0,[7808,4928],4);f(1,[6784,5056],4);f(2,[6400,4416],4);f(2,[6656,4160],4);f(2,[7040,4288],0);f(2,[7168,4288],0);");
	// fixed extra corners of shore
	queue("f(3,[6784,4928],8);f(0,[6528,4416],8);f(1,[7296,4288],8);f(1,[7552,4416],8);f(1,[7680,4544],8);f(2,[7552,4928],8);f(0,[6656,4288],8);f(2,[6528,4288],4);f(3,[7680,4416],4);f(3,[7552,4288],4);f(3,[7808,4544],4);");
	// nice tree locations:
	queue("sid('trees',[[4320,4896],[5640,4940],[6144,4512],[7104,5152],[5070,5300],[5760,5312],[4360,5312],			 [5952,5952],[6496,5440],[7392,5568],[8384,5184],[8544,5568],[7648,4160],[7424,4192],[6464,3776],[5120,4000],[5440,4288]],40);");
	// leaves that belong to trees:
	//queue("f(0,[[5536,4768],[5440,4800],[5760,5312],[4512,5312]],0);");
	// patio furniture: two on the beach radius 64
	queue("sid('umbrellas',[[6496,4832],[7104,4256]],64);");
	// north T road cap
	queue("f(3,[5632,4032],9);f(0,[5632,3904],9);f(1,[6272,3904],9);f(2,[6272,4032],9);f(1,[5760,3904],1);f(1,[5888,3904],1);f(1,[6016,3904],1);f(1,[6144,3904],1);f(3,[6144,4032],1);");
	// seaside road
	queue("f(1,[6144,5056],1);f(1,[6272,5056],1);f(1,[6400,5056],1);f(1,[6528,5056],1);f(1,[6656,5056],9);f(1,[6656,5184],2);f(1,[6784,5184],1);f(1,[6912,5184],9);f(3,[6144,5184],1);f(3,[6272,5184],1);f(3,[6400,5184],1);f(3,[6528,5184],2);f(1,[6912,5312],2);f(1,[7040,5312],1);f(1,[7168,5312],1);f(1,[7296,5312],1);f(1,[7424,5312],1);f(1,[7552,5312],1);f(1,[7680,5312],1);f(1,[7808,5312],1);f(0,[7936,5312],2);f(1,[8064,5312],2);f(3,[8064,5440],1);f(3,[7936,5440],1);f(3,[7808,5440],1);f(3,[7680,5440],1);f(3,[7552,5440],1);f(3,[7424,5440],1);f(3,[7296,5440],1);f(3,[7168,5440],1);f(3,[7040,5440],1);f(3,[6912,5440],1);f(3,[6784,5440],9);f(3,[6528,5312],9);f(3,[6784,5312],2);f(3,[6656,5312],1);f(2,[6016,5312],1);f(2,[6016,5440],1);f(2,[6016,5568],1);f(2,[6016,5696],1);f(2,[6016,5824],9);f(3,[5888,5824],9);f(0,[5888,5696],1);f(0,[5888,5568],1);f(0,[5888,5440],1);f(0,[5888,5312],1);");
	// cars
	queue("sid('cars',[[3780,5408],[5700,3968],[8768,5320]],104);");
	// arcade path
	//queue("f(2,[3584,5120],0);f(3,[3584,4992],3);f(1,[3584,5248],3);");
	// old outside arcade games
	//queue("sid('rgames',[[2742,5068],[2742,5132],[2742,5196],[2742,5260],[2912,5184],[2976,5120]],36);");
	//queue("sid('lgames',[[3472,5068],[3264,5184],[3200,5120]],36);");
	// pink tree locations:
	queue("sid('pinktrees',[[3616,4992],[5060,4950]],40);");//[4200,4700],
	// phatpad_inside fullscreen house walls
	// fixme make HUGE outside blockers for bot spawn inside only!
	// left wall
	queue("spawnaabb([4045,14100],[4200,15000]);");
	// right wall
	queue("spawnaabb([4672,14100],[4844,15000]);");
	// top wall
	queue("spawnaabb([4150,14086],[4777,14274]);");
	// swimming top bit
	queue("spawnaabb([4340,14100],[4542,14362]);");
	// bottom wall
	queue("spawnaabb([4045,14700],[4777,18888]);");
	// arcade interior walls
	// bottom wall
	queue("spawnaabb([13696,14632],[15168,14880]);");
	// left wall
	queue("spawnaabb([13792,14112],[13932,14752]);");
	// top left wall and 
	queue("spawnaabb([13856,14112],[14336,14456]);");
	// top right wall
	queue("spawnaabb([14336,14112],[15008,14374]);");
	// right wall
	queue("spawnaabb([14912,14240],[15104,14784]);");
	// arcade interior games
	//queue("sid('lgames',[[14880,14400],[14784,14400],[14688,14400],[14880,14528],[14784,14528],[14688,14528]],36);");
	//queue("sid('rgames',[[14372,14400],[14372,14528],[13968,14464],[13952,14528],[13936,14592]],36);");
	// new mini games arcace machine front facing 
	//queue("sid('machine0',[[14080,14464],[14176,14464],[14240,14464]],36);");
	//queue("sid('machine1',[[14880,14400],[14784,14400],[14688,14400],[14592,14400],[14880,14528],[14784,14528],[14688,14528],[14592,14528]],36);");
	//queue("sid('machine2',[[14372,14400],[14372,14528],[13968,14464],[13952,14528],[13936,14592]],36);");
	//queue("sid('machine3',[[14180,14464],[14276,14464],[14340,14464]],36);");
	queue("sid('machine2',[[4555,4944],[4444,14320]],36);"); // ouside and in the HOUSE
	queue("sid('machine0',[[14880,14400],[14592,14528]],36);");
	queue("sid('machine1',[[14784,14400],[14688,14528]],36);");
	queue("sid('machine2',[[14688,14400],[14784,14528]],36);");
	queue("sid('machine3',[[14592,14400],[14880,14528]],36);");
	queue("sid('machine0',[[14496,14400]],36);");
	queue("sid('machine1',[[14400,14400]],36);");
	queue("sid('machine2',[[14496,14528]],36);");
	queue("sid('machine3',[[14400,14528]],36);");
	// colliders for the outside houses: fixme: spawn them like sid()
	// must be queued or it destroys the everything[] array!
	queue("spawn_circle_collider([4444,4444],256);");
	queue("spawn_circle_collider([5200,4444],256);");
	queue("spawn_circle_collider([3200,3333],256);");
	queue("spawn_circle_collider([4444,5280],256);");
	queue("spawn_circle_collider([5200,5280],256);");
	queue("spawn_circle_collider([6080,4280],256);");
	// and one centered in the arcade but adjusted higher due to non square shape
	queue("spawn_circle_collider([3480,4100-180],400);");
	*/




	/*
	// milestone 3 old level ugly
	// flowers and leaves in front of house
	queue("f(1,[4864,4928],0);f(0,[4320,4896],0);");
	// house pathways:
	queue("f(0,[5248,4928],3);f(2,[5120,4928],3);f(1,[5408,4608],3);f(3,[5408,4480],3);f(3,[5536,4480],3);f(3,[5664,4480],4);f(1,[5536,4608],3);f(0,[5664,4608],4);");
	// house interior props
	queue("sid('lcorners',[[4492,4580]]);");
	queue("sid('rcorners',[[5180,4580]]);");
	queue("sid('chairs',[[4750,4620]],40);");
	queue("sid('tables',[[4680,4690]],40);");
	// house walls - back white wall
	w(1,[[4588,4548],[4652,4548],[4892,4548],[5020,4548],[5072,4548]]); // left,overlapping left,__WINDOW__,dip,right,overlapping right portion
	w(5,[[4460,4828]]); // bottom left corner
	//w(3,[[5148,4836]]); // porch door left corner wall - gets in the way...
	w(4,[[4572,4836],[4828,4836],[5052,4836]]); // bottom wall horiz
	w(7,[[4940,4828]]); // bottom window
	w(6,[[4764,4548]]); // top window
	// puzzle bottom wall
	w(4,[[2752,5340],[2976,5340],[3232,5340],[3456,5340]]); // l,l,_w_,r,r
	// puzzle bottom windows
	w(7,[[2864,5348],[3344,5348]]);
	// avoid the aabb for the left wall of house: (plus extra on each side due to circle avatar radius overlap)
	spawnaabb([4444-16,4498-8],[4460+16,4810+8]);
	// aabb of the right house wall
	spawnaabb([5212-16,4484-8],[5228+16,4778+8]);
	// the porch top railing
	spawnaabb([5226-16,4484-8],[5342+16,4510+8]);
	// porch side rail, fattened
	spawnaabb([5312-16,4576-8],[5322+16,4843+8]);
	//porch bottom rail
	spawnaabb([5220-16,4814-8],[5322+16,4843+8]);
	// the entire puzzle wall
	spawnaabb([2674,4492],[3536,5060]);
	*/
	// grass everywhere?
	//sid('grasses',[[4600,4890],[4700,4990],[4800,5090]],0); // 0 radius = no collide //
}

var chatlogison = true; // turned on after login...
function butchat()
{
	if (window.game_sfxclick) game_sfxclick();
	var cl = document.getElementById('chatlog');
	if (cl)
	{
		if (chatlogison)
		{
			cl.style.display = 'none';
			chatlogison = false;
		}
		else
		{
			cl.style.display = 'block';
			chatlogison = true;
		}
	}
}

function buthelp()
{
	if (window.game_sfxclick) game_sfxclick();
	alert_show('<font color=red>Kool Community Help</font><br><br>'+
		   'Click anywhere to walk around.  '+
		   'To chat, click the bottom white bar, type and '+
		   'press ENTER.<br><br>'+
		   'Add people to your '+
		   "<a class='help' title='Click for additional help' href='javascript://' onclick='help_friendlist()'>Friend List</a> "+
		   'by clicking their name.  '+
		   '<br><br>There are four gold buttons at the bottom right.  '+
		   'Be sure to try them all. Enjoy!');
}

function help_friendlist()
{
	alert_show('<font color=red>Friend List Help</font><br><br>'+
		   'You can add another user to your friend list '+
		   'by clicking the name that is above their avatar.'+
		   'To send a private text message, click a friend, '+
		   'then click the TEXT button.  '+
		   'You can also send inventory items '+
		   'as GIFTS by clicking an item from your inventory '+
		   'then clicking a friend.  To visit a friend, click '+
		   'the VISIT button.  '+
		   'See how many FRIENDSHIP POINTS you can earn!');
}

function help_leveleditor()
{
	alert_show('<font color=red>Renovating Your Home</font><br><br>'+
		   'You can customize your home with '+
		   'furniture, plants, decorations and arcade games. '+
		   'Use the menu on the right to place furniture and '+
		   'decorations, as well as to lock your door or '+
		   'invite friends over.  Visitors cannot steal your '+
		   'items, so have fun and show off your creation!');
}

function help_inventory()
{
	alert_show('<font color=red>Inventory Help</font><br><br>'+
		   'Your inventory is the collection of '+
		   'items that you own.  This can include '+
		   'flowers, chocolates, newspapers, '+
		   'treasure and more.  Click the HAND icon to open and close it.<br><br>'+
		   'Click an item in your inventory, then '+
		   'click another person to give them a gift.  '+
		   'You can also put items on the ground, '+
		   'or into your recycle bin to delete it.');
}

var butinve_on = false; // toggle
var butinve_help_first_time = true;
function butinve()
{
	if (window.game_sfxclick) game_sfxclick();

	if (butinve_help_first_time)
	{
		help_inventory();
		butinve_help_first_time = false;
	}

	if (butinve_on)
	{
		if (window.inventory_gui_hide) inventory_gui_hide();
		if (window.inventory_gui_shrink) inventory_gui_shrink();
		butinve_on = false;
	}
	else
	{
		if (window.inventory_gui_grow) inventory_gui_grow();
		if (window.inventory_gui_show) inventory_gui_show();
		butinve_on = true;
	}

}

function buthome()
{
	if (window.game_sfxclick) game_sfxclick();
	if (condoison)
	{
		alert_yesno('<font color=red>Go ouside?</font><br><br>'+
			'You are currently inside a home. '+
			'Outside, you can chat with people, '+
			'find new items and go into other buildings '+
			'like the store and the arcade.<br><br>'+
			'Click the YES button if you want '+
			'to go to go outside to the city.<br><br>'+
			'Click the NO button to stay here.',gohomenow,null);
	}
	else
	{
		alert_yesno('<font color=red>Go to your custom home?</font><br><br>'+
			'At home, you can decorate your apartment '+
			'with furniture, plants and playable video games.<br><br>'+
			'You can also invite friends over!<br><br>'+
			'Click the YES button if you want '+
			'to go to your personalized condo.<br><br>'+
			'Click the NO button to remain outside for public chat.',gohomenow,null);
	}
}

function pin_lock()
{
	if (window.game_sfxclick) game_sfxclick();
	var thepin = document.getElementById('pin');
	if (thepin)
	{
		if (thepin.value.length==3)
		{
			addlog("You locked your door.");
			var builddata = "level="+global_user_name+"&lock=Y&pin="+thepin.value;
			;;; if (debug) addlog('DEBUG: pin_lock ' + builddata);
			var pendingbuildrequest = new ajax(builddata,"level.php?");		// save pin
			alert_show(	"<font color=red>Door locked.</font><br><br>  You can have private parties by sharing your pin number."+
						"<br><br>Text message a friend with your secret access code (<font color=red>"+thepin.value+"</font>) anytime."+
						"<br><br>To change your PIN or to unlock the door, click the key icon again.",null,null);
		}
		else
		{
			alert_show(	"You can only lock your door if your PIN is exactly three numbers in length.  "+
						"<br><br>To lock your door, try again and make sure your pin is not blank.",null,null);
		}
	}
	else
	{
		;;; if (debug) addlog("ERROR: unable to obtain PIN form value.");
	}
}

function pin_unlock()
{
	if (window.game_sfxclick) game_sfxclick();
	var thepin = document.getElementById('pin');
	if (thepin)
	{
		alert_show(	"<font color=red>Door unlocked.</font><br><br>Guests can now visit anytime.  "+
					"<br><br>Your items cannot be taken so it is safe to leave your "+
					"door unlocked even when you are not online.",null,null);
		addlog("Unlocking your door...");
		var builddata = "level="+global_user_name+"&user="+global_user_name+"&lock=N";//&pin="+thepin.value;
		;;; if (debug) addlog('DEBUG: pin_unlock ' + builddata);
		var pendingbuildrequest = new ajax(builddata,"level.php?");		// save pin
	}
	else
	{
		;;; if (debug) addlog("ERROR: unable to obtain PIN form value.");
	}
}

function try_a_pin() // if house locked, this submits guest pin
{
	if (window.game_sfxclick) game_sfxclick();
	var thepin = document.getElementById('pin');
	if (thepin)
	{
		if (thepin.value.length==3)
		{
			addlog("You enter a pin number...");
			if (window.download_buildings) download_buildings(previous_location_name,thepin.value);
			return;
		}
	}
	gooutside(); // invalid input = fail
}

function ask_pin() // when visiting a locked friend
{
	if (window.game_sfxclick) game_sfxclick();
	alert_yesno('<font color=red>Do you have the PIN?</font><br><br>'+
			'This apartment has been locked.  If you know the PIN number you can enter.  '+
			'Please enter a 3-digit pin number and click YES.<br><br>'+
			"PIN NUMBER: <input id='pin' name='pin' type='text' length='3' size='3' value=''><br><br>"+
			'To return outside, click NO.',try_a_pin,gooutside); // poo fixme: re-submit level load ajax with pin
	// focus after render
	setTimeout("document.getElementById('pin').value='';document.getElementById('pin').focus();",1);
}

function set_your_pin()
{
	if (window.game_sfxclick) game_sfxclick();
	alert_yesno('<font color=red>Lock your door?</font><br><br>'+
			'If you wish to restrict access to your home, '+
			'enter a 3-digit pin number and click YES.<br><br>'+
			"PIN NUMBER: <input id='pin' name='pin' type='text' length='3' size='3' value='123'><br><br>"+
			'If you want to allow anybody to visit, '+
			'click the NO button to leave the doors unlocked.  Guests cannot take items, so it is safe to leave your door unlocked.',pin_lock,pin_unlock);
	// focus after render
	setTimeout("document.getElementById('pin').focus();",1);
}

function downloaduserlist(l1,l2,l3,l4,l5,l6)
{
	var thequery = "";
	if (l1) thequery += 'startswith1='+l1;
	if (l2) thequery += '&startswith2='+l2;
	if (l3) thequery += '&startswith3='+l3;
	if (l4) thequery += '&startswith4='+l4;
	if (l5) thequery += '&startswith5='+l5;
	if (l6) thequery += '&startswith6='+l6;
	//alert('debug: userlist query:\n'+thequery);
	var userlistrequest = new ajax(thequery,"userlist.php?");
}

var visit_msg_delim = '_v_';
function inviteallmyfriends()
{
	var theresult = 'Sending party invitations:<br><br>';
	var invitecount = 0;
	if (window.friends) // exists?
	{
		for (nextone in friends)
		{
			if (friends[nextone])
			{
				theresult += '<li>'+friends[nextone].name+'</li>';
				
				// poo fixme: use magic string instead and in tm() function parse like inv
				var msg_body = 'You have been invited to visit.'+ //to visit ' + chat_user_name + '.'+
								visit_msg_delim + chat_user_name + visit_msg_delim;
								

				if (window.send_txt) // able to send texe messages?
				{	
					invitecount++;
					send_txt(chat_user_name,chat_avatar,friends[nextone].name,msg_body);
				}

				}
		}
	}
	theresult += '<br>'+invitecount+' invitations sent.';
	alert_show(theresult);
}

function invite_friends_over()
{
	if (window.game_sfxclick) game_sfxclick();
	
	// open friendlist force ajax load
	if (window.phonebuttonclick)
	{
		if (!flon) phonebuttonclick();
	}
	
	alert_yesno('<font color=red>Invite your friends over?</font><br><br>'+
			'If you wish to invite all the people in your friendlist '+
			'to come over for a party, simply click the YES button.<br><br>'+
			'To send individual invitations, click NO and use the '+
			'friendlist to send text messages one at a time.',inviteallmyfriends,null);
}

// these are the correct locations:
var condo_xy = [7777,7777]; // location of house iteself
var condo_start_pos = [7860,7730]; // where avatar appears
var condo_upstairs_xy = [17777,17777]; // upstairs is exactly 10000 away
var condo_upstairs_start_pos = [17860,17730]; // top of stairs

function exithome()
{
		if (debug) addlog('DEBUG: exithome destroy previous location: '+previous_location_name);
		if (window.destroy_buildings) destroy_buildings(previous_location_name);
		condoison = false;
		if (gohome_toggles_leveleditor) leveleditor_hide();
		
		// hide housebuttons
		if (document.getElementById('housebuttons')) document.getElementById('housebuttons').style.display = 'none';

}

function gooutside()
{
	addlog('You exit the building.');
	if (condoison) exithome();
	warptoxy(game.playerone.exit_interior_xy);
}

var condoison = false;
var firsttimeinside = true;
var previous_location_name = '';
function gohomenow(thislocation) // toggler...
{
	if (!thislocation) thislocation = global_user_name;
	if (debug) addlog('DEBUG: gohomenow');
	if (!window.game) addlog ('ERROR: gohomenow: no game object.');
	if (!window.game.playerone) addlog ('ERROR: gohomenow: no game.playerone object.');
	if (window.game_sfxlogin) game_sfxlogin();

	if (condoison)
	{
		exithome();
		warptoxy(game.playerone.exit_interior_xy);
		addlog('You go outside.');
	}
	else
	{
		previous_location_name = thislocation;
		if (debug) addlog('DEBUG: download_buildings: '+thislocation);
		if (window.download_buildings) download_buildings(thislocation);
		condoison = true;
		game.playerone.exit_interior_xy = game.playerone.xy; // remember current location
		warptoxy(condo_start_pos);

		// turn on lock/invite buttons
		if (document.getElementById('housebuttons')) document.getElementById('housebuttons').style.display = 'block';
		
		var welcometext = "Welcome to<br><font color=red>"+thislocation+"'s</font><br>Apartment.";
		if (thislocation==global_user_name)
		{

			addlog('You are in your house.');
		
			welcometext = welcometext +
			"<br><br>This is YOUR home.<br>"+
			"You can <a class='help' title='Click here to set your PIN number.' href='javascript://' onclick='set_your_pin();'>lock</a> it "+
			"or <a class='help' title='Click here to invite all your friends to visit.' href='javascript://' onclick='invite_friends_over();'>invite guests</a>.";

		}
		else
		{
					addlog("You are in "+thislocation+"'s house.");
		}
		welcometext = welcometext +
			"<br><br>When you want to leave, click the house icon on the bottom right of your screen."+
			"<br><br><a class='help' href='javascript://' title='Click here to read more about user homes.' onclick='help_leveleditor();'>Click here for more help</a>.";

		alert_show(welcometext);

		if (thislocation==global_user_name)
		{
			if (gohome_toggles_leveleditor) leveleditor_show(); // ugly build menu
		}

		if (firsttimeinside)
		{	// need to download the house images
			firsttimeinside = false;
			// load the apartment images on demand - this works in FF etc but not IE - zIndex problems... put into index.php hardcoded
			//addlog('DEBUG: loading apartment images...');
			//comments: spawn2008(spawnxy,tiletl,tilebr,footxy,collideradius,sheetclass,divclass,hovercallback,clickcallback,outcallback,zofs)
			//var aptfloor = spawn2008(condo_xy,[0,0],[480,186],[160,160],0,null,'apartmentfloor',null,null,null,-500);
			//var aptwalls = spawn2008(condo_xy,[0,0],[480,186],[160,160],0,null,'apartmentwalls');
			//var aptupfloor = spawn2008(condo_upstairs_xy,[0,0],[480,186],[160,160],0,null,'apartmentfloorupstairs',null,null,null,-500);
		}
	}
}

var yesvisitname = '';
function yesvisit()
{
	if (yesvisitname.length>0)
	{
		gohomenow(yesvisitname);
	}
}
function visitme(namelinkelement)
{
	yesvisitname = namelinkelement.innerHTML;
	//alert_show('<font color=red>Coming Soon</font><br><br>The insides of apartments are coming very soon.  Currently the database routines and level editor functionality is complete, but the art is not ready and there are still some bugs to fix.  When Milestone 6 is ready you will be able to buy furniture, plants, arcade machines and MUCH MORE for your custom home, it is almost ready!  I have programmed most of it but it needs a few days more work.');
	alert_yesno("Do you want to visit<br><font color=red>"+yesvisitname+"'s</font><br>Apartment?<br><br>Click YES to travel to the inside of this person's custom home.<br><br>Click NO to stay outside on the city street where you are right now.",yesvisit,null);
}

function goupstairs()
{
	;;; if (debug) addlog('going upstairs...');
	addlog('You go upstairs.');
	warptoxy(condo_upstairs_start_pos);
}

function godownstairs()
{
	;;; if (debug) addlog('going downstairs...');
	addlog('You go back downstairs.');
	warptoxy(condo_start_pos);
}


function citymapover(zonenum)
{
	gui_owns_clicks = true;
	if (window.game_sfxhover) game_sfxhover();
}

function citymapout(zonenum)
{
	gui_owns_clicks = false;
}

function citymapwarp(zonenum)
{
	if (condoison) exithome();
	
	gui_owns_clicks = false;
	if (window.game_sfxlogin) game_sfxlogin();
	switch(zonenum)
	{
		case 0: addlog('You are in the West Side.'); warpto(5020,5150); break; // west side
		case 1: addlog('You are at the Crossroads.'); warpto(5664,5400); break; // crossroads
		case 2: addlog('You are downtown.'); warpto(6688,5150); break; // downtown
		case 3: addlog('You are uptown.'); warpto(6540,5564); break; // east side
		default: warpto(5664,5400); break; // crossroads
	}
}

function buyme()
{
	var closest = closest_thing([game.mouselevelx,game.mouselevely],200);
	if (closest)
	{
		if (debug>1) addlog('DEBUG: closest thing is named ' + closest.name);
		thisone = closest.name;
	}
	else
	{
		if (debug) addlog('DEBUG: click was not near anything.');
		return;
	}

	if (debug) addlog('DEBUG: buyme ' +thisone);
	game.playerone.xy = game.playerone.exit_interior_xy; // previous one used when entering home so exit doesn't bring you to empty store
	gohomenow(); // enter home
	if (store_came_from_upstairs) goupstairs(); // maybe upstairs
	addlog('Choose a location for your new '+thisone+'.');
	startbuilding(thisone);
}

function a_an(thisnoun)
{
	var vowels = 'aeiouAEIOU'; 
	var letter = thisnoun.charAt(0);
	if (vowels.indexOf(letter) == -1)
		return 'a '+thisnoun;
	else
		return 'an '+thisnoun;
}

function buymeover()
{
	if (debug) addlog('DEBUG: buymeover near ' + [game.mouselevelx,game.mouselevely]);
	if (window.game_sfxhover) game_sfxhover();
	if (window.xhair) xhair_change_frame(2); // hand
	
	// handy helper
	var closest = closest_thing([game.mouselevelx,game.mouselevely],200);
	if (closest)
	{
		if (debug) addlog('DEBUG: closest thing is named ' + closest.name);
		c('Store Clerk|blue|19|7799|This is '+a_an(closest.name)+'.');
	}
}

function buymeout()
{
	if (debug) addlog('DEBUG: buymeout');
	if (window.xhair) xhair_change_frame(0); // pointer
}

var store_first_time = true;
var store_came_from_upstairs = false; // for buyme
function gostorenow(fromupstairs) // called from index.php <a>
{
	
	if (fromupstairs) 
		store_came_from_upstairs = true; 
	else
		store_came_from_upstairs = false; 
	
	if (condoison) 
	{
		exithome();
	}
	else
	{
		game.playerone.exit_interior_xy = game.playerone.xy; // remember where we stood if outside
	}
	
	addlog('You are in the furniture store.');
	if (window.game_sfxlogin) game_sfxlogin();
	warpto(-20,7777); // inside the store
	//if (store_first_time) // need to regen each time due to house destroying items
	//{
		if (debug) addlog('DEBUG: Unpacking store inventory...');
		store_first_time = false;
		// cycle thru all builables
		var choicecount = 0;
		var choicestartx = -360;
		var choicestarty = 7648;
		var choicex = 0;
		var choicey = 0;
		var choicexofs = 64;
		var choiceyofs = 80;
		for (nextchoice in buildables)
		{
			if (debug) addlog('DEBUG: item '+choicecount+' = '+nextchoice+' '+choicex+','+choicey);
			newsprite = spawnbuilding(nextchoice,[choicestartx+choicex,choicestarty+choicey],false,buymeover,buyme,buymeout); 
			newsprite.name = nextchoice; // give the sprite a prop name for buyme()
			if (!newsprite.radius) // eg rugs need a fake one so you can click (to buy nearest)
			{
				newsprite.radius = 1;
				everything[everythingcount] = newsprite; // remember only for the store copy... dupes would happen if store re-spawned inventory
				everythingcount++; // everything_countpoo
			}
			choicex += choicexofs;
			choicecount++;
			if (choicecount==11) { choicey = choiceyofs; choicex = 0; }
			if (choicecount==23) { choicey = choiceyofs*2; choicex = 0; }
			if (choicecount==28) { choicex += 180; }
			if (choicecount==32) { choicey = choiceyofs*3; choicex = 0; }
			if (choicecount==37) { choicex += 180; }
			if (choicecount==41) { choicey = choiceyofs*3; choicex = 0; }
			if (choicecount==53) { choicey = choiceyofs*3; choicex = 0; }
			if (choicecount==65) { choicey = choiceyofs*3; choicex = 0; }
		}
		// fake bot cashier!
		//var rrr = randy(0,3); if (rrr==0) 
		c('Store Clerk|blue|20|7800|How can I help you?');
		//if (rrr==1) c('Store Clerk|blue|22|7800|Welcome to the store.');
		//if (rrr==2) c('Store Clerk|blue|20|7802|Everything is on sale today!');
		//if (rrr==3) c('Store Clerk|blue|22|7802|Shop till you drop!');
	//}
}

var arcade_first_time = true;
function goarcadenow() // called from index.php <a>
{
	addlog("Welcome to Flynn's Arcade.");
	if (window.game_sfxlogin) game_sfxlogin();
	game.playerone.exit_interior_xy = game.playerone.xy; // remember current location
	warpto(0,17777); // inside the arcade

	if (debug) addlog('DEBUG: turning on game machines...');
	arcade_first_time = false;
	// cycle thru all builables
	var choicecount = 0;
	var choicestartx = 40;
	var choicestarty = 17628;
	var choicex = 0;
	var choicey = 0;
	var choicexofs = 64;
	var choiceyofs = 72;
	
	newsprite = spawnbuilding("Bunch",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Sudoku",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Cube Buster",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;

	choicex = 0; choicey += choiceyofs;
	newsprite = spawnbuilding("Sudoku",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Cube Buster",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Bunch",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;

	choicex = 0; choicey += choiceyofs;
	newsprite = spawnbuilding("Cube Buster",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Bunch",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Sudoku",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	
	choicex = 0; choicey += choiceyofs;
	newsprite = spawnbuilding("Bunch",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Cube Buster",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("Sudoku",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	
	choicex = 0; choicey += choiceyofs;
	newsprite = spawnbuilding("pool table",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("pool table",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;
	newsprite = spawnbuilding("pool table",[choicestartx+choicex,choicestarty+choicey]); 
	choicex += choicexofs;

	c('Flynn|norm|-200|17900|Welcome to the Arcade!');

}

var done_loading_project_specific_vars = true;