--[[

     	      SSSSSSSSSSSSSSS         CCCCCCCCCCCCC
	     SS:::::::::::::::S     CCC::::::::::::C
	    S:::::SSSSSS::::::S   CC:::::::::::::::C
	    S:::::S     SSSSSSS  C:::::CCCCCCCC::::C
	    S:::::S             C:::::C       CCCCCC
	    S:::::S            C:::::C              
	     S::::SSSS         C:::::C              
	      SS::::::SSSSS    C:::::C              
	        SSS::::::::SS  C:::::C              
	           SSSSSS::::S C:::::C              
	                S:::::SC:::::C              
	                S:::::S C:::::C       CCCCCC
	    SSSSSSS     S:::::S  C:::::CCCCCCCC::::C
	    S::::::SSSSSS:::::S   CC:::::::::::::::C
	    S:::::::::::::::SS      CCC::::::::::::C
	     SSSSSSSSSSSSSSS           CCCCCCCCCCCCC


    __  ___/___  __________________  /____(_)___________ 
    _____ \_  / / /_  __ \_  ___/_  __ \_  /__  __ \  _ \
    ____/ // /_/ /_  / / /(__  )_  / / /  / _  / / /  __/
    /____/ \__,_/ /_/ /_//____/ /_/ /_//_/  /_/ /_/\___/ 
                                                     
		    _________             _____                         
		    __  ____/___  __________  /_____________ ___________
		    _  /    _  / / /_  ___/  __/  __ \_  __ `__ \_  ___/
		    / /___  / /_/ /_(__  )/ /_ / /_/ /  / / / / /(__  ) 
		    \____/  \__,_/ /____/ \__/ \____//_/ /_/ /_//____/  


     ______________________________________________________________________
    |                                                                      |
    | Creator     : Emmet Mc Poland (emcp)                                 |   
    |                                                                      |
    | Version     : Version 1                                              |
    |                                                                      |
    | Released    : Nov 10th 2007, 08:15 PM                                |
    |                                                                      |
    | Description :                                                        |
    |               Homebrew Application For The Sony Playstation Portable |
    |               which allows modification of cars in Grand Theft Auto: |
    |               Vice City Stories using Edison Carters Cheatdevice     |
    |                                                                      |
    |______________________________________________________________________|

Copyright (C) 2007  Emmet Mc Poland, Sunshine Customs,  For More Details See License.txt
    For More Infomation on how to use this progarm please refer to README.txt

]]--

--DoFiles
dofile("Save.lua")

--Creates Colors
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
grey = Color.new(226, 226, 226)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)

--[[
MainColor = Color.new(65, 192, 215)
MainFader:clear(Color.new(65, 192, 215, 20))
SideFader:clear(Color.new(204, 204, 204, 100))
SelectColor = Color.new(217, 217, 75)
UnSelectColor = Color.new(0, 0, 0)
BarBgColor = Color.new(226, 226, 226)
BarColor = Color.new(0, 0, 255)
MenuSelectorColor = Color.new(204, 204, 204)
]]--

--blue = Color.new(0, 108, 255)
--red = Color.new(255, 0, 108)
--green = Color.new(108, 255, 0)


Helpbg = Image.load("Images/help.png")
PauseImg = Image.load("Images/pause.png")
StartScreenPic = Image.load("Images/start.png")

MainFader = Image.createEmpty(480, 272)
MainFader:clear(Color.new(255, 255, 255, 10))

SideFader = Image.createEmpty(81, 272)
--SideFader:clear(Color.new(204, 204, 204, 100))

OSKFader = Image.createEmpty(480, 272)
OSKFader:clear(Color.new(204,204,204, 200))

OSKSel = Image.createEmpty(23, 23)
OSKSel:clear(Color.new( 65, 192, 215, 100))


--Loads Images
check = Image.load("Images/check.png")
check_tick = Image.load("Images/check_t.png")


--Option Settings
Options = false
curOp = 1
BarText = ""
MainCol = 1
SideCol = 1
SelCol = 1
UnSelCol = 1
BarBgCol = 1
BarCol = 1
MenuSelCol = 1


USB = false


---Text Alignment/Line Wrapping
Int_TextWidth = 75;
Int_StartLineY = 50;
Int_LineHeight = 9;

myColors = {}
myColors = table.load("myColors.pal")

OptionSet = {
	{65, 192, 215}, --MainColor 
	{204, 204, 204}, --SideColor 
	{217, 217, 75}, --SelectColor
	{0, 0, 0}, --UnSelectColor
	{226, 226, 226}, --BarBgColor
	{0, 0, 255}, -- BarColor
	{204, 204, 204} -- MenuSelectorColor
}

--table.save(OptionSet, "Settings.cfg")

OptionSet = table.load("Settings.cfg")

MainColor = Color.new(OptionSet[1][1], OptionSet[1][2], OptionSet[1][3])
--MainFader:clear(Color.new(OptionSet[1][1], OptionSet[1][2], OptionSet[1][3], 20))
SideFader:clear(Color.new(OptionSet[2][1], OptionSet[2][1], OptionSet[2][1], 100))
SelectColor = Color.new(OptionSet[3][1], OptionSet[3][2], OptionSet[3][3])
UnSelectColor = Color.new(OptionSet[4][1], OptionSet[4][2], OptionSet[4][3])
BarBgColor = Color.new(OptionSet[5][1], OptionSet[5][2], OptionSet[5][3])
BarColor = Color.new(OptionSet[6][1], OptionSet[6][2], OptionSet[6][3])
MenuSelectorColor = Color.new(OptionSet[7][1], OptionSet[7][2], OptionSet[7][3])


VehicleIDs = {
--{ IMAGE, NAME, CAR ID, NEON = NEON ADDRESS, VMS = STARTING ADDRESS},

--[[

VMS ADDRESSES FOUND - 5

Stallion - 0x9630800
Caddy - 0x962f3e0
Deluxo - 0x962f680
Phoenix - 0x96334A0
ATV - 0x9631d60
Sabre Turbo - 0x9634420
Sabre - 0x9634340
Washington - 0x9634800
Senteniel XS - 0x9634500
Regina - 0x9634260
Infernus - 0x9634180
Gang Rancher - 0x9633fc0
FBI Rancher - 0x9633ee0
Comet - 0x96340a0
Mesa Grande - 0x9633200
Pheonix - 0x96334a0
BF Injection - 0x96333c0
Stinger - 0x9633120
Virgo - 0x96332e0
Forklift - 0x9632f20
Rhino - 0x9632ac0
Sandking - 0x96329e0
Mr Whoopie - 0x9632900
Cuban - 0x9633d20
Yankee - 0x9632820
Trashmaster - 0x9632660
Securicar - 0x9632580
Voodoo - 0x96324a0
Mule - 0x9632200
Coach - 0x9632120
Benson - 0x96322e0
Boxville - 0x96323c0
Enforcer - 0x9631ac0
Stretch - 0x96319e0
Ambulance - 0x9631660
Taxi - 0x9631ba0
Rumpo - 0x9631820
Moonbeam - 0x9631740
Barracks OL - 0x9630fe0
Flatbed - 0x9631440
Barracks OL 2 - 0x96311a0
Walton - 0x96310c0
Linerunner - 0x9631280
Sentinel - 0x9630b80
Pony - 0x9630aa0
Patriot - 0x96309c0
Police Cruiser - 0x96308e0
Police Cheetah - 0x9630480
Oceanic - 0x9630560
Manana - 0x96302c0
Landstalker - 0x96301e0
Idaho - 0x9630020
Hermes - 0x962ff40
Greenwood - 0x962fe60
Glendale - 0x962fd80
Firetruck - 0x962fae0
FBI washington - 0x962fca0
Polaris V8 - 0x962f4c0
Cabbie - 0x962eea0
Burrito - 0x962f220
Bulldozer - 0x962ef80
Bobcat - 0x962f140
Blista Compact - 0x962edc0
Perennial - 0x962ece0
Baggage Handler - 0x962ec00
Admiral - 0x962eb20
Spiltz-6 ATV - 0x962e7a0
VCPD Wintergreen - 0x962fa00
Wintergreen - 0x962f920
Bover '64' - 0x9630100
Biker Angel - 0x9631f60
Freeway - 0x9631e40
Sanchez - 0x9630640
ATV - 0x9631d60
Faggio - 0x9631c80
PCJ-600 - 0x9630c60
Streetfighter - 0x9633000
Ventosso - 0x96303a0
BMX-Girl - 0x962f300
BMX - 0x962f060
Domstobot - 0x9630720


TODO

Boats
Jetski
Helicopters
Planes

]]--
{ "Images/Vehicles/170.png", "Splitz-6 ATV", id = 170, vms = "0x962e7a0", tyre = "0x935E198", neon = "0x0972EFF0", name = "0x98a2eaa"},
{ "Images/Vehicles/171.png", "Admiral", id = 171, vms = "0x962eb20", tyre = "0x935E438", neon = "0x0972EFF0", name = "0x98a30e2"},
{ "Images/Vehicles/172.png", "Cheetah", id = 172, vms = "0x962ea40", tyre = "0x935E6D8", neon = "0x0972EFF0", name = "0x98a33b8"},
--{ "Images/Vehicles/173.png", "Little Willie", id = 173, neon = "0x09730070"},
{ "Images/Vehicles/174.png", "Baggage Handler", id = 174, vms = "0x962ec00", tyre = "0x935EC18", neon = "0x0972EFF0", name = "0x98a35c0"},
{ "Images/Vehicles/175.png", "Banshee", id = 175, vms = "0x96334A0", tyre = "0x936C358", neon = "0x0972EFF0", name = "0x98a3106"},
{ "Images/Vehicles/176.png", "Perennial", id = 176, vms = "0x962ece0", tyre = "0x935F158", neon = "0x0972EFF0", name = "0x98a30f2"},
{ "Images/Vehicles/177.png", "Blista Compact", id = 177, vms = "0x962edc0", tyre = "0x935F3F8", neon = "0x0972EFF0", name = "0x98a3116"},
{ "Images/Vehicles/178.png", "BMX", id = 178, vms = "0x962f060", neon = "0x097272d0", name = "0x98a2e10"},
{ "Images/Vehicles/179.png", "BMX-Girl", id = 179, vms = "0x962f300", neon = "0x097272d0", name = "0x98a2e18"},
{ "Images/Vehicles/180.png", "Bobcat", id = 180, vms = "0x962f140", tyre = "0x935FBD8", neon = "0x0972EFF0", name = "0x98a3134"},
{ "Images/Vehicles/181.png", "Bulldozzer", id = 181, vms = "0x962ef80", tyre = "0x935FE78", neon = "0x0972EFF0", name = "0x98a2dfc"},
{ "Images/Vehicles/182.png", "Burrito", id = 182, vms = "0x962f220", tyre = "0x9360118", neon = "0x0972EFF0", name = "0x98a3142"},
{ "Images/Vehicles/183.png", "Cabbie", id = 183, vms = "0x962eea0", tyre = "0x93603B8", neon = "0x0972EFF0", name = "0x98a3152"},
{ "Images/Vehicles/184.png", "Caddy", id = 184, vms = "0x962f3e0", tyre = "0x9360658", neon = "0x0972EFF0", name = "0x98a3160"},
{ "Images/Vehicles/186.png", "Polaris V8", id = 186, vms = "0x962f4c0", tyre = "0x9360B98", neon = "0x0972EFF0", name = "0x98a2edc"},
{ "Images/Vehicles/187.png", "Deluxo", id = 187, vms = "0x962f680", tyre = "0x9360E38", neon = "0x0972EFF0", name = "0x98a316c"},
--{ "Images/Vehicles/188.png", "Armadillo", id = 188, neon = "0x09730070"},
--{ "Images/Vehicles/189.png", "Air Ambulance", id = 189, neon = "0x09730070"},
{ "Images/Vehicles/190.png", "WinterGreen", id = 190, vms = "0x962f920", neon = "0x097272d0", name = "0x98a2f0a"},
{ "Images/Vehicles/191.png", "VCPD WinterGreen", id = 191, vms = "0x962fa00", neon = "0x097272d0", name = "0x98a2f22"},
{ "Images/Vehicles/192.png", "Esperanto", id = 192, vms = "0x962fbc0", tyre = "0x9361B58", neon = "0x0972EFF0", name = "0x98a3174"},
{ "Images/Vehicles/193.png", "FBI Washington", id = 193, vms = "0x962fca0", tyre = "0x9361DF8", neon = "0x0972EFF0", name = "0x98a318e"},
{ "Images/Vehicles/194.png", "Fire Truck", id = 194, vms = "0x962fae0", tyre = "0x9362098", neon = "0x0972EFF0", name = "0x98a31ac"},
{ "Images/Vehicles/195.png", "Glendale", id = 195, vms = "0x962fd80", tyre = "0x9362338", neon = "0x0972EFF0", name = "0x98a351c"},
{ "Images/Vehicles/196.png", "Greenwood", id = 196, vms = "0x962fe60", tyre = "0x93625D8", neon = "0x0972EFF0", name = "0x98a364e"},
{ "Images/Vehicles/197.png", "Hermes", id = 197, vms = "0x962ff40", tyre = "0x9362878", neon = "0x0972EFF0", name = "0x98a31c2"},
{ "Images/Vehicles/198.png", "Bovver '64", id = 198, vms = "0x9630100", neon = "0x0972EFF0", name = "0x98a2f60"},
{ "Images/Vehicles/199.png", "Idaho", id = 199, vms = "0x9630020", tyre = "0x9362DB8", neon = "0x0972EFF0", name = "0x98a31d0"},
{ "Images/Vehicles/200.png", "Landstalker", id = 200, vms = "0x96301e0", tyre = "0x9363058", neon = "0x0972EFF0", name = "0x98a31dc"},
{ "Images/Vehicles/201.png", "Manana", id = 201, vms = "0x96302c0", tyre = "0x93632F8", neon = "0x0972EFF0", name = "0x98a31f4"},
{ "Images/Vehicles/202.png", "Ventoso", id = 202, vms = "0x96303a0", neon = "0x097272d0", name = "0x98a2e70"},
{ "Images/Vehicles/203.png", "Oceanic", id = 203, vms = "0x9630560", tyre = "0x9363838", neon = "0x0972EFF0", name = "0x98a3202"},
{ "Images/Vehicles/204.png", "VCPD Cheetah", id = 204, vms = "0x9630480", tyre = "0x9363AD8", neon = "0x0972EFF0", name = "0x98a2fee"},
{ "Images/Vehicles/205.png", "Sanchez", id = 205, vms = "0x9630640", neon = "0x097272d0", name = "0x98a322a"},
{ "Images/Vehicles/206.png", "Stallion", id = 206, vms = "0x9630800", tyre = "0x9364018", neon = "0x0972EFF0", name = "0x98a323a"},
{ "Images/Vehicles/207.png", "VCPD Cruiser", id = 207, vms = "0x96308e0", tyre = "0x93642B8", neon = "0x0972EFF0", name = "0x98a3084"},
{ "Images/Vehicles/208.png", "Domestobot", id = 208, vms = "0x9630720", tyre = "0x9364558", neon = "0x0972EFF0", name = "0x98a6136"},
{ "Images/Vehicles/209.png", "Patriot", id = 209, vms = "0x96309c0", tyre = "0x93647F8", neon = "0x0972EFF0", name = "0x98a325a"},
{ "Images/Vehicles/210.png", "Pony", id = 210, vms = "0x9630aa0", tyre = "0x9364A98", neon = "0x0972EFF0", name = "0x98a326a"},
{ "Images/Vehicles/211.png", "Sentinel", id = 211, vms = "0x9630b80", tyre = "0x9364D38", neon = "0x0972EFF0", name = "0x98a3274"},
{ "Images/Vehicles/212.png", "PCJ 600", id = 212, vms = "0x9630c60", neon = "0x097272d0", name = "0x98a3286"},
--{ "Images/Vehicles/213.png", "Maverick", id = 213, neon = "0x09730070"},
--{ "Images/Vehicles/214.png", "Reefer", id = 214},
--{ "Images/Vehicles/215.png", "Speeder", id = 215},
{ "Images/Vehicles/216.png", "Linerunner", id = 216, vms = "0x9631280", tyre = "0x9365A58", neon = "0x0972EFF0", name = "0x98a32b4"},
{ "Images/Vehicles/217.png", "Walton", id = 217, vms = "0x96310c0", tyre = "0x9365CF8", neon = "0x0972EFF0", name = "0x98a3588"},
{ "Images/Vehicles/218.png", "Barracks OL 2", id = 218, vms = "0x96311a0", tyre = "0x9365F98", neon = "0x0972EFF0", name = "0x98a32d8"},
--{ "Images/Vehicles/219.png", "Predator", id = 219},
{ "Images/Vehicles/220.png", "Flatbed", id = 220, vms = "0x9631440", tyre = "0x93664D8", neon = "0x0972EFF0", name = "0x98a3302"},
{ "Images/Vehicles/221.png", "Barracks OL", id = 221, vms = "0x9630fe0", tyre = "0x9366778", neon = "0x0972EFF0", name = "0x98a32d8"},
--{ "Images/Vehicles/222.png", "Biplane", id = 222},
{ "Images/Vehicles/223.png", "Moonbeam", id = 223, vms = "0x9631740", tyre = "0x9366CB8", neon = "0x0972EFF0", name = "0x98a3312"},
{ "Images/Vehicles/224.png", "Rumpo", id = 224, vms = "0x9631820", tyre = "0x9366F58", neon = "0x0972EFF0", name = "0x98a3324"},
--{ "Images/Vehicles/225.png", "Yola", id = 225, neon = "0x0972EFF0"},
{ "Images/Vehicles/226.png", "Taxi", id = 226, vms = "0x9631ba0", tyre = "0x9367498", neon = "0x0972EFF0", name = "0x98a3330"},
{ "Images/Vehicles/227.png", "Ambulance", id = 227, vms = "0x9631660", tyre = "0x9367738", neon = "0x0972EFF0", name = "0x98a333a"},
{ "Images/Vehicles/228.png", "Stretch", id = 228, vms = "0x96319e0", tyre = "0x93679D8", neon = "0x0972EFF0", name = "0x98a334e"},
{ "Images/Vehicles/229.png", "Faggio", id = 229, vms = "0x9631c80", neon = "0x097272d0", name = "0x98a335e"},
{ "Images/Vehicles/230.png", "ATV", id = 230, vms = "0x9631d60", tyre = "0x9367f18", neon = "0x0972EFF0", name = "0x98a2e20"},
{ "Images/Vehicles/231.png", "Biker Angel", id = 231, vms = "0x9631f60", neon = "0x097272d0", name = "0x98a2ef2"},
{ "Images/Vehicles/232.png", "Freeway", id = 232, vms = "0x9631e40", neon = "0x097272d0", name = "0x98a350c"},
--{ "Images/Vehicles/233.png", "Jetski", id = 233},
{ "Images/Vehicles/234.png", "VCPD Enforcer", id = 234, vms = "0x9631ac0", tyre = "0x9368998", neon = "0x0972EFF0", name = "0x98a309e"},
{ "Images/Vehicles/235.png", "Boxville", id = 235, vms = "0x96323c0", tyre = "0x9368C38", neon = "0x0972EFF0", name = "0x98a2fc4"},
{ "Images/Vehicles/236.png", "Benson", id = 236, vms = "0x96322e0", tyre = "0x9368ED8", neon = "0x0972EFF0", name = "0x98a3008"},
{ "Images/Vehicles/237.png", "Coach", id = 237, vms = "0x9632120", tyre = "0x9369178", neon = "0x0972EFF0", name = "0x98a3474"},
{ "Images/Vehicles/238.png", "Mule", id = 238, vms = "0x9632200", tyre = "0x9369418", neon = "0x0972EFF0", name = "0x98a33ae"},
{ "Images/Vehicles/239.png", "Voodoo", id = 239, vms = "0x96324a0", tyre = "0x93696B8", neon = "0x0972EFF0", name = "0x98a3008"},
{ "Images/Vehicles/240.png", "Securicar", id = 240, vms = "0x9632580", tyre = "0x9369958", neon = "0x0972EFF0", name = "0x98a3430"},
{ "Images/Vehicles/241.png", "Trashmaster", id = 241, vms = "0x9632660", tyre = "0x9369BF8", neon = "0x0972EFF0", name = "0x98a3384"},
{ "Images/Vehicles/243.png", "Yankee", id = 243, vms = "0x9632820", tyre = "0x936A138", neon = "0x0972EFF0", name = "0x98a34de"},
{ "Images/Vehicles/244.png", "Mr Whoopie", id = 244, vms = "0x9632900", tyre = "0x936A3D8", neon = "0x0972EFF0", name = "0x98a33de"},
{ "Images/Vehicles/245.png", "Sandking", id = 245, vms = "0x96329e0", tyre = "0x936A678", neon = "0x0972EFF0", name = "0x98a2fb2"},
{ "Images/Vehicles/246.png", "Rhino", id = 246, vms = "0x9632ac0", tyre = "0x936A91A", neon = "0x0972EFF0", name = "0x98a3444"},
--{ "Images/Vehicles/247.png", "Dinghy", id = 247},
--{ "Images/Vehicles/248.png", "Marquis", id = 248},
--{ "Images/Vehicles/249.png", "Rio", id = 249},
{ "Images/Vehicles/251.png", "Forklift", id = 251, vms = "0x9632f20", neon = "0x0972EFF0", name = "0x98a2f84"},
{ "Images/Vehicles/252.png", "StreetFighter", id = 252, vms = "0x9633000", neon = "0x097272d0", name = "0x98a2f44"},
{ "Images/Vehicles/253.png", "Virgo", id = 253, vms = "0x96332e0", tyre = "0x936BB78", neon = "0x0972EFF0", name = "0x98a3642"},
{ "Images/Vehicles/254.png", "Stinger", id = 254, vms = "0x9633120", tyre = "0x936BE18", neon = "0x0972EFF0", name = "0x98a336c"},
{ "Images/Vehicles/255.png", "BF Injection", id = 255, vms = "0x96333c0", tyre = "0x936C0B8", neon = "0x0972EFF0", name = "0x98a33f6"},
{ "Images/Vehicles/256.png", "Pheonix", id = 256, vms = "0x96334a0", tyre = "0x936C358", neon = "0x0972EFF0", name = "0x98a30ba"},
--{ "Images/Vehicles/257.png", "Squalo", id = 257},
--{ "Images/Vehicles/258.png", "Jetmax", id = 258},
{ "Images/Vehicles/259.png", "Mesa Grande", id = 259, vms = "0x9633200", tyre = "0x936CB38", neon = "0x0972EFF0", name = "0x98a30ca"},
--{ "Images/Vehicles/260.png", "VCN Maverick", id = 260, neon = "0x09730070"},
--{ "Images/Vehicles/261.png", "Police Maverick 2", id = 261, neon = "0x09730070"},
--{ "Images/Vehicles/262.png", "Sparrow", id = 262, neon = "0x09730070"},
--{ "Images/Vehicles/263.png", "Sea Sparrow", id = 263, neon = "0x09730070"},
--{ "Images/Vehicles/264.png", "Violator", id = 264},
{ "Images/Vehicles/265.png", "Cholo Sabre", id = 265, vms = "0x9633880", tyre = "0x936DAF8", neon = "0x0972EFF0", name = "0x98a2ec4"},
{ "Images/Vehicles/266.png", "Comet", id = 266, vms = "0x96340a0", tyre = "0x936DD98", neon = "0x0972EFF0", name = "0x98a35a4"},
{ "Images/Vehicles/267.png", "Cuban Hermes", id = 267, vms = "0x9633d20", tyre = "0x936E038", neon = "0x0972EFF0", name = "0x98a3450"},
{ "Images/Vehicles/268.png", "FBI Rancher", id = 268, vms = "0x9633ee0", tyre = "0x936E2D8", neon = "0x0972EFF0", name = "0x98a362a"},
{ "Images/Vehicles/269.png", "Gang Rancher", id = 269, vms = "0x9633fc0", tyre = "0x936E578", neon = "0x0972EFF0", name = "0x98a34b6"},
{ "Images/Vehicles/270.png", "Infernus", id = 270, vms = "0x9634180", tyre = "0x936E818", neon = "0x0972EFF0", name = "0x98a339c"},
{ "Images/Vehicles/271.png", "Regina", id = 271, vms = "0x9634260", tyre = "0x936EAB8", neon = "0x0972EFF0", name = "0x98a3596"},
{ "Images/Vehicles/272.png", "Sabre", id = 272, vms = "0x9634340", tyre = "0x936ED58", neon = "0x0972EFF0", name = "0x98a3564"},
{ "Images/Vehicles/273.png", "Sabre Turbo", id = 273, vms = "0x9634420", tyre = "0x936EFF8", neon = "0x0972EFF0", name = "0x98a2fd6"},
{ "Images/Vehicles/274.png", "Sentinel XS", id = 274, vms = "0x9634500", tyre = "0x936F298", neon = "0x0972EFF0", name = "0x98a3212"},
--{ "Images/Vehicles/275.png", "Hunter", id = 275, neon = "0x09730070"},
{ "Images/Vehicles/276.png", "Washington", id = 276, vms = "0x9634800", tyre = "0x936F7D8", neon = "0x0972EFF0", name = "0x98a33c8"},
--{ "Images/Vehicles/277.png", "Coast Guard", id = 277},
--{ "Images/Vehicles/278.png", "Skimmer", id = 278},
--{ "Images/Vehicles/279.png", "Police Maverick", id = 279, neon = "0x09730070"},
}

Garages = {
{ "Images/Garages/The Clymenus Suite.png", "The Clymenus Suite", "0x8C73B30", " 268.31, -174.98, 11.50"},
{ "Images/Garages/101 Bayshore Avenue.png", "101 Bayshore Avenue", "0x08C739B0", " -806.04, -1185.04, 11.0"},
{ "Images/Garages/The Compound.png", "The Compound", "0x8C73A70", " -1087.31, 356.47, 11.27"},
{ "Images/Garages/None.png", "None", "", ""}
}

Backgrounds = {
"Images/backgrounds/Basics.png",
"Images/backgrounds/Wheels.png",
"Images/backgrounds/Engine.png",
"Images/backgrounds/Suspension.png",
"Images/backgrounds/Handling.png",
"Images/backgrounds/Effects.png" ,
--"Images/backgrounds/Effects.png"
}


SideBar = Image.load("Images/side.png")

--Loads Fonts
Plain = Font.load("Plain.ttf")
Plain:setPixelSizes( 0, 12)

--starting screen
StartScreen = Timer.new()
StartScreen:start()


--Sets Pause To Its Default Off Position
pause = false
SelPause = 1

Load = false
Save = false
Import = false
Export = false


curSave = 1
curFile = 1

Handling = {}
HandlingParsed = {}
HandlingSave = {}
VehicleHandling = {}

--Sets Help To Its Default Off Position
Help = false

--Sets Start To Its Default Off Position
Start = false

--Sets Palette To Its Default Off Position
curPalette = 1

--Sets Several Other Variable To Their Default
lineColor = 1

--Creates Empty Palette For Colors To Be Loaded Into In Future
DoPalette = false


DoOSK = false


--Creates A Value To Change Current Value In Table Vehicle
curValue = 1

--Creates A Value To Change Current Page
curPage = 1

--Creates A Table Named Vehicle To Store Vehicle Data
Vehicle = { 
--[[
{1},--Pic
{r = 255, g = 255, b = 255},--Palette
{val = 0, on = 20, off = 0},--Check
{val = 275, min = 250, max = 1000},--Bar
{1}--Text Scroll
{txt = "test", max = 10}--osk
]]--

{1},--Vehilces
{1},--Garages
{txt = "", max = 0},--Vehicle Name
{r = 255, g = 255, b = 255},--Base Color
{r = 0, g = 0, b = 255},--Strip Color
{val = 1, on = 1, off = 0},--Teleport

{val = 0.7, min = 0.35, max = 2.40, inc = 0.01},--Tyre Size
{val = 0.75, min = 0.45, max = 20, inc = 0.01},--Traction Multiplier
{val = 0.85, min = 0.45, max = 2, inc = 0.01},--Traction loss
{val = 0.50, min = 0.05, max = 0.60, inc = 0.01},--Traction Bias

{1},
{1},
{1},

{val = 0.35, min = 0.05, max = 0.47, inc = 0.01},--Suspension Upper Limit
{val = -0.15, min = -0.30, max = -0.04, inc = 0.01},--Suspension Lower Limit
{val = 0.08, min = 0, max = 0.40, inc = 0.01},--Suspension Damping Level
{val = 1.00, min = 0.40, max = 3.00, inc = 0.01},--Suspension Force Level
{val = 0.50, min = 0.20, max = 0.60, inc = 0.01},--Suspension Bias
{val = 0, min = 0, max = 1, inc = 0.1},--Anti-Dive Multiplier

{val = 30, min = 20, max = 50, inc = 1},--Steering Lock
{val = 1500, min = 100, max = 25000, inc = 50},--Vehilce Mass
{val = 1500, min = 100, max = 250000, inc = 50},--Turn Mass
{val = 0.00, min = -1.5, max = 1.5, inc = 0.01},--Centre of Mass - X
{val = 0.00, min = -1.5, max = 1.5, inc = 0.01},--Centre of Mass - Y
{val = 0.00, min = -1.5, max = 1.5, inc = 0.01},--Centre of Mass - Z

{val = 0, on = 1, off = 0},--Exhaust Smoke
{val = 0, on = 1, off = 0},--Neon/Shadow 
{r = 255, g = 255, b = 255},--Exhaust Smoke Color
{r = 255, g = 255, b = 255}--Neon/Shadow Color
}

Pages = {
{"Basic", min = 1, max = 6},
{"Wheels", min = 7, max = 10},
{"Engine", min = 11, max = 13},
{"Suspension", min = 14, max = 19},
{"Handling", min = 20, max = 25},
{"Effects", min = 26, max = 29}
}

LoadedPic = {}

Drive = {
{"Rear Wheel Drive", "R"},
{"Front Wheel Drive", "F"},
{"Four Wheel Drive", "4"}
}

Engine = {
{"Petrol", "P"},
{"Diesel", "D"},
{"Electric", "E"}
}

Gears = {
{ "1", "1"},
{ "2", "2"},
{ "3", "3"},
{ "4", "4"},
{ "5", "5"},
{ "6", "6"}
}


----ON SCREEN KEYBOARD SETTINGS
OSK = {
	Keys = {
                 { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"},
	       { "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"},
	          { "A", "S", "D", "F", "G", "H", "J", "K", "L"},
	               { "Z", "X", "C", "V", "B", "N", "M"},
	      { "\[", "\]", "(", ")", "/", "\\", "|", "\"", ",", "."}
	},

	Row = 1,
	Key = 1,

	XY = {
		{ 60, { 46, 86, 127, 169, 208, 249, 289, 330, 370, 411}},
		{ 101, { 46, 86, 127, 169, 208, 249, 289, 330, 370, 411}},
		{ 139, { 67, 107, 148, 190, 229, 270, 310, 351, 391}},
		{ 178, { 107, 147, 188, 230, 269, 310, 350}},
		{ 216, { 46, 86, 127, 169, 208, 249, 289, 330, 370, 411}}
	}
}



--FUNCTIONS

function DrawDebug( x, y)
	screen:print( x, y, "Some Debugging :", UnSelectColor)
	screen:print( x, y+10, "Current Page : " .. curPage, UnSelectColor)
	screen:print( x, y+20, "Current Table/Selection : " .. curValue, UnSelectColor)
	screen:print( x, y+30, "Number Of Tables In Table : " .. table.getn(Vehicle[curValue]), UnSelectColor)
	screen:print( x+300, y, System.getFreeMemory() .. "mb", UnSelectColor)
end

--Center Text Function
function printCentered(font, center, y, text, color)
	screen:fontPrint(font, center - ((font:getTextSize(text)["width"])/2), y, text, color)
end

function Split(str, delim, maxNb) -- from: http://lua-users.org/wiki/StringRecipes
	-- Eliminate bad cases...
	if string.find(str, delim) == nil then
        		return { str }
    	end
    	if maxNb == nil or maxNb < 1 then
        		maxNb = 0    -- No limit
    	end
    	local result = {}
    	local pat = "(.-)" .. delim .. "()"
    	local nb = 0
    	local lastPos
    	for part, pos in string.gfind(str, pat) do
        		nb = nb + 1
        		result[nb] = part
        		lastPos = pos
        		if nb == maxNb then break end
    		end
    		-- Handle the last field
    		if nb ~= maxNb then
        			result[nb + 1] = string.sub(str, lastPos)
    		end
return result
end

function scaleImage(newX, newY, theImage) 
	resizedImage = Image.createEmpty(newX, newY) 
	for x = 1, newX do 
		for y = 1, newY do 
			resizedImage:blit(x,y , theImage,
			math.floor(x*(theImage:width()/newX)),
			math.floor(y*(theImage:height()/newY)),1,1) 
		end 
	end 
	return resizedImage 
end

function CheatText(text)
local CheatString = ""
	for a = 1,string.len(text) do
		CheatString = CheatString .. "\'" .. string.sub(text,a,a) .. "\',"
	end
return CheatString
end

function DrawOSK( x, y, text, description, vehicleValue)

	if Help == false then

		Image:fontPrint(Plain, x, y, text, UnSelectColor)

		if curValue == vehicleValue then
			Image:fillRect(x, y+Plain:getTextSize(text)["height"]-5, 70+4, 10+4, SelectColor)
		else
			Image:fillRect(x, y+Plain:getTextSize(text)["height"]-5, 70+4, 10+4, UnSelectColor)
		end


		Image:fillRect(x+2, y+5, 70, 10, white)

		if string.len(Vehicle[vehicleValue].txt) <= 11 then
			Image:fontPrint(Plain, x+4, y+15, Vehicle[vehicleValue].txt, black)
		else
			Image:fontPrint(Plain, x+4, y+15, string.sub( Vehicle[vehicleValue].txt, 1, 11) .. "...", black)
		end
		
	elseif curValue == vehicleValue then
		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, Helpbg, true)
		Image:blit(0,0,MainFader, true)	

		-- Get the current length of the screen
		local Int_LengthOfString = string.len(description);

		-- Get the number of lines in the string
		local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);

		Int_CurrentLine = 0;
		for i=0,Int_NumberOfLines do
	   	 local Str_Line = string.sub(description, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
			Image:fontPrint(Plain, 50, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line, UnSelectColor)
	    	Int_CurrentLine = Int_CurrentLine + 1;
		end
	end

end

function DrawText( x, y, text, description, txttable, vehicleValue, debug)

	if Help == false then
		if curValue == vehicleValue and DoPalette == false then
		
			if pad:right() and pad:right() ~= oldpad:right() then
				Vehicle[vehicleValue][1] = Vehicle[vehicleValue][1]+1
				if Vehicle[vehicleValue][1] > table.getn(txttable) then
					Vehicle[vehicleValue][1] = 1
				end
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				Vehicle[vehicleValue][1] = Vehicle[vehicleValue][1]-1
				if Vehicle[vehicleValue][1] < 1 then
					Vehicle[vehicleValue][1] = table.getn(txttable) 
				end
			end

			Image:fontPrint(Plain, x, y, text .. " : " .. txttable[Vehicle[vehicleValue][1]][1], SelectColor)
		elseif curValue ~= vehicleValue then
			Image:fontPrint(Plain, x, y, text .. " : " .. txttable[Vehicle[vehicleValue][1]][1], UnSelectColor)
		end

		if debug == "debug" then
			screen:print(x,y,Vehicle[vehicleValue][1], UnSelectColor)
		end

          	elseif curValue == vehicleValue then
		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, Helpbg, true)
		Image:blit(0,0,MainFader, true)	

	-- Get the current length of the screen
	local Int_LengthOfString = string.len(description);

	-- Get the number of lines in the string
	local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);

	Int_CurrentLine = 0;
	for i=0,Int_NumberOfLines do
	    local Str_Line = string.sub(description, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
		Image:fontPrint(Plain, 50, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line, UnSelectColor)
	    Int_CurrentLine = Int_CurrentLine + 1;
	end	
	end
end


function DrawPic( x, y, text, description, pictable, vehicleValue, debug)

	
	if Help == false then

	if LoadedPic[vehicleValue] == nil then
			 LoadedPic[vehicleValue] = Image.load(pictable[Vehicle[vehicleValue][1]][1])	
	end



		if curValue == vehicleValue and DoPalette == false  then
		
			if pad:right() then
				Vehicle[vehicleValue][1] = Vehicle[vehicleValue][1]+1
				if Vehicle[vehicleValue][1] > table.getn(pictable) then
					Vehicle[vehicleValue][1] = 1
				end
				LoadedPic[vehicleValue] = Image.load(pictable[Vehicle[vehicleValue][1]][1])
				collectgarbage()
			end
			if pad:left() then
				Vehicle[vehicleValue][1] = Vehicle[vehicleValue][1]-1
				if Vehicle[vehicleValue][1] < 1 then
					Vehicle[vehicleValue][1] = table.getn(pictable) 
				end
				LoadedPic[vehicleValue] = Image.load(pictable[Vehicle[vehicleValue][1]][1])
				collectgarbage()
			end

		Image:fillRect(x, y, LoadedPic[vehicleValue]:width()+4, LoadedPic[vehicleValue]:height()+4, SelectColor)
		else
		Image:fillRect(x, y, LoadedPic[vehicleValue]:width()+4, LoadedPic[vehicleValue]:height()+4, UnSelectColor)
		end

		Image:fontPrint(Plain, x, y-5, text, UnSelectColor)

		Image:blit( x+2, y+2, LoadedPic[vehicleValue])
		Image:fontPrint(Plain, (x+(LoadedPic[vehicleValue]:width()+4)/2)-((Plain:getTextSize(pictable[Vehicle[vehicleValue][1]][2])["width"])/2), y+LoadedPic[vehicleValue]:height()+15, pictable[Vehicle[vehicleValue][1]][2], UnSelectColor)

	if debug == "debug" then
		screen:print(x+Plain:getTextSize(text)["width"]+10,y-12,Vehicle[vehicleValue][1], UnSelectColor)
	end

          	elseif curValue == vehicleValue then
		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, Helpbg, true)
		Image:blit(0,0,MainFader, true)
	
	-- Get the current length of the screen
	local Int_LengthOfString = string.len(description);

	-- Get the number of lines in the string
	local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);

	Int_CurrentLine = 0;
	for i=0,Int_NumberOfLines do
	    local Str_Line = string.sub(description, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
		Image:fontPrint(Plain, 50, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line, UnSelectColor)
	    Int_CurrentLine = Int_CurrentLine + 1;
	end	


	end
end


function DrawCheck( x, y, text, description, vehicleValue, debug)

	if Help == false then
		if vehicleValue == curValue then
			Image:fillRect((x+Plain:getTextSize(text)["width"]+10)-2, (y-Plain:getTextSize(text)["height"]-2)-2, 17, 17, SelectColor)
		end
		if Vehicle[vehicleValue].val == Vehicle[vehicleValue].off then
			Image:blit(x+Plain:getTextSize(text)["width"]+10, y-Plain:getTextSize(text)["height"]-2, check)
       		end
		if Vehicle[vehicleValue].val == Vehicle[vehicleValue].on then
			Image:blit(x+Plain:getTextSize(text)["width"]+10, y-Plain:getTextSize(text)["height"]-2, check_tick)
       		end

		Image:fontPrint(Plain, x, y, text .. " : ", UnSelectColor)

		if debug == "debug" then
			screen:print( x, y+10, "(Debug : " .. Vehicle[vehicleValue].val .. ")", UnSelectColor)
        		end
          	elseif curValue == vehicleValue then
		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, Helpbg, true)
		Image:blit(0,0,MainFader, true)

	-- Get the current length of the screen
	local Int_LengthOfString = string.len(description);

	-- Get the number of lines in the string
	local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);

	Int_CurrentLine = 0;
	for i=0,Int_NumberOfLines do
	    local Str_Line = string.sub(description, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
		Image:fontPrint(Plain, 50, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line, UnSelectColor)
	    Int_CurrentLine = Int_CurrentLine + 1;
	end	
	
	end

end



--Creates A Function
function DrawBar( x, y, text, description, vehicleValue, debug)

       	  --Gets Precentage Of The Value In The Current Bar 
	dis =((Vehicle[vehicleValue].val-Vehicle[vehicleValue].min)/(Vehicle[vehicleValue].max-Vehicle[vehicleValue].min))*70

	if Help == false then
      	    --Blits A Bar
		if curValue ~= vehicleValue then
			Image:fillRect(x, y+Plain:getTextSize(text)["height"]-5, 70+4, 10+4, UnSelectColor)
		end
		if curValue == vehicleValue then
			Image:fillRect(x, y+Plain:getTextSize(text)["height"]-5, 70+4, 10+4, SelectColor)
		end
		
		Image:fillRect(x+2, y+Plain:getTextSize(text)["height"]-3, 70, 10, BarBgColor)
		Image:fillRect(x+2, y+Plain:getTextSize(text)["height"]-3, dis, 10, BarColor)

		--Blits description and value of bar in %
		dis = math.floor(dis/70*100)
		Image:fontPrint(Plain, x, y, text .. " : " .. Vehicle[vehicleValue].val, UnSelectColor) --- dis for precentage

       	   --Enters Debug Mode
		if debug == "debug" then
			screen:print( x+100+60, y, "(Debug :" .. Vehicle[vehicleValue].val .. ")", UnSelectColor)
		end
	elseif curValue == vehicleValue then
		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, Helpbg, true)
		Image:blit(0,0,MainFader, true)

	-- Get the current length of the screen
	local Int_LengthOfString = string.len(description);

	-- Get the number of lines in the string
	local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);

	Int_CurrentLine = 0;
	for i=0,Int_NumberOfLines do
	    local Str_Line = string.sub(description, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
		Image:fontPrint(Plain, 50, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line, UnSelectColor)
	    Int_CurrentLine = Int_CurrentLine + 1;
	end	
	end
end


function DrawPalette( x, y, text, description, vehicleValue)


	if Help == false then
   	       --Blits A Bar
		if curValue ~= vehicleValue then
			Image:fillRect(x, y+Plain:getTextSize(text)["height"]-5, 70+4, 10+4, UnSelectColor)
		end
		if curValue == vehicleValue then
			Image:fillRect(x, y+Plain:getTextSize(text)["height"]-5, 70+4, 10+4, SelectColor)
		end

		Image:fillRect(x+2, y+Plain:getTextSize(text)["height"]-3, 70, 10, Color.new( Vehicle[vehicleValue].r, Vehicle[vehicleValue].g, Vehicle[vehicleValue].b))	
		Image:fontPrint(Plain, (x+37)-(Plain:getTextSize(text)["width"]/2), y, text, UnSelectColor)



	elseif curValue == vehicleValue then		
		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, Helpbg, true)
		Image:blit(0,0,MainFader, true)	

		-- Get the current length of the screen
		local Int_LengthOfString = string.len(description);

		-- Get the number of lines in the string
		local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);

		Int_CurrentLine = 0;
		for i=0,Int_NumberOfLines do
		    local Str_Line = string.sub(description, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
			Image:fontPrint(Plain, 50, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line, UnSelectColor)
		    Int_CurrentLine = Int_CurrentLine + 1;
		end	

	end
	
end

--Strat Loop Gives Pad A Value And Clears The Screen
oldpad = Controls.read()
while true do
screen:clear()
pad = Controls.read()         

	if pad:select() and pad:select() ~= oldpad:select() then
		Image:save( "Screenshot.png" )
	end



	if pause == true and Start == true then

		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:blit( 0, 0, PauseImg, true)
		Image:blit(0,0,MainFader, true)

		Plain:setPixelSizes( 0, 20)

		if pad:start() and pad:start() ~= oldpad:start() then
			pause = false
		end

		if pad:up() and pad:up() ~= oldpad:up() then
			SelPause = SelPause - 1
		end
		if pad:down() and pad:down() ~= oldpad:down() then
			SelPause = SelPause + 1
		end

		if SelPause > 8 then
			SelPause = 1
		end
		if SelPause < 1 then
			SelPause = 8
		end

		if SelPause == 1 then		
	 		printCentered(Plain, 240, 70, "Resume", SelectColor) 
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				pause = false
				PauseBg = nil
			end
		else
			printCentered(Plain, 240, 70, "Resume", UnSelectColor) 
		end

		if SelPause == 2 then
	 		printCentered(Plain, 240, 90, "Load", SelectColor)
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				Load = true
				pause = false
				PauseBg = nil

				CarDir = System.listDirectory("Showroom/")
				table.remove(CarDir, 1)
				table.remove(CarDir, 1)
			end
		else
			printCentered(Plain, 240, 90, "Load", UnSelectColor)
		end

		if SelPause == 3 then
	 		printCentered(Plain, 240, 110, "Save", SelectColor)
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				Save = true
				pause = false
				PauseBg = nil

				CarDir = System.listDirectory("Showroom/")
				table.remove(CarDir, 1)
				table.remove(CarDir, 1)
			end
		else
	 		printCentered(Plain, 240, 110, "Save", UnSelectColor) 
		end

		if SelPause == 4 then		
		printCentered(Plain, 240, 130, "Import",SelectColor)  
			if pad:cross() and pad:cross() ~= oldpad:cross() then


				for line in io.lines("Handling/HANDLING.CFG") do
				if string.sub(line, 1, 1) ~= ";" and string.sub(line, 1, 1) ~= "$" and string.sub(line, 1, 1) ~= "!" and string.sub(line, 1, 1) ~= "%" and string.sub(line, 1, 1) ~= "^" then
						table.insert(Handling, line)
					end
				end



				for a = 1,table.getn(Handling) do
					Handling[a] = Split(Handling[a], "%s+")
				end
				Import = true
				pause = false
				SelPause = 1	

			end
		else
			printCentered(Plain, 240, 130, "Import",UnSelectColor) 
		end

		if SelPause == 5 then
	 		printCentered(Plain, 240, 150, "Export", SelectColor) 
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				Export = true
				pause = false
				SelPause = 1

				if System.listDirectory("ms0:/cheats/vcs/") ~= nil then
					CheatDir = System.listDirectory("ms0:/cheats/vcs/")
				else
					CheatDir = System.listDirectory("./Cheats/")
				end
				table.remove(CheatDir, 1)
				table.remove(CheatDir, 1)
			end
		else
	 		printCentered(Plain, 240, 150, "Export", UnSelectColor) 
		end

		if SelPause == 6 then
			printCentered(Plain, 240, 170, "Options", SelectColor) 
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				Options = true
				pause = false
				PauseBg = nil
			end
	 	else
			printCentered(Plain, 240, 170, "Options", UnSelectColor) 
		end

		if SelPause == 7 then
			printCentered(Plain, 240, 190, "USB", SelectColor) 
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				USB = true
				pause = false
				PauseBg = nil
			end
	 	else
			printCentered(Plain, 240, 190, "USB", UnSelectColor) 
		end

		if SelPause == 8 then
			printCentered(Plain, 240, 210, "Exit", SelectColor) 
			if pad:cross() and pad:cross() ~= oldpad:cross() then
				os.exit()
			end
	 	else
			printCentered(Plain, 240, 210, "Exit", UnSelectColor) 
		end

	elseif DoPalette == true then

			if pad:square() and pad:square() ~= oldpad:square() and table.getn(myColors) < 100 then
				table.insert(myColors, {})
				table.insert(myColors[table.getn(myColors)], Vehicle[curValue].r)
				table.insert(myColors[table.getn(myColors)], Vehicle[curValue].g)
				table.insert(myColors[table.getn(myColors)], Vehicle[curValue].b)
				table.save( myColors , "myColors.pal")
			end
			if pad:triangle() and pad:triangle() ~= oldpad:triangle() and curPalette > 3 and table.getn(myColors) > 1 then
				table.remove( myColors, curPalette-3)
				table.save( myColors , "myColors.pal")
			end

			Image:fillRect(0, 0, 480, 272, MainColor)
			Image:blit( 0, 0, PaletteBG, true)
			Image:blit(0,0,MainFader, true)

			for a = 1, table.getn(myColors) do
				local  y = 130
				local x =35+(a*14)
				if a > 10 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 20 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 30 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 40 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 50 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 60 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 70 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 80 then 
					y = y+14
					x = x-(14*10)
				end
				if a > 90 then 
					y = y+14
					x = x-(14*10)
				end
				if curPalette == a+3 then  
					Image:fillRect(x, y, 10+4, 10+4, SelectColor)
				else
					Image:fillRect(x, y, 10+4, 10+4, UnSelectColor)
				end

				Image:fillRect(x+2, y+2, 10, 10, Color.new( myColors[a][1], myColors[a][2], myColors[a][3]))
			end

			if curPalette <= 3 then
				if pad:up() and pad:up() ~= oldpad:up() then
					curPalette = curPalette-1
				end
				if pad:down() and pad:down() ~= oldpad:down() then
					curPalette = curPalette+1
				end

			elseif curPalette > 3 then
				if pad:up() and pad:up() ~= oldpad:up() then
					curPalette = curPalette-10
				end
				if pad:down() and pad:down() ~= oldpad:down() then
					curPalette = curPalette+10
				end
				if pad:left() and pad:left() ~= oldpad:left() then
					curPalette = curPalette-1
				end
				if pad:right() and pad:right() ~= oldpad:right() then
					curPalette = curPalette+1
				end

				if pad:cross() and pad:cross() ~= oldpad:cross() then
					Vehicle[curValue].r = myColors[curPalette-3][1]
					Vehicle[curValue].g = myColors[curPalette-3][2]
					Vehicle[curValue].b = myColors[curPalette-3][3]
				end
			end
		


			if curPalette > 3+table.getn(myColors) then
				curPalette = 1
			end
			if curPalette < 1 then
				curPalette = table.getn(myColors)+3
			end
		
			if pad:right() and pad:cross() then
				if curPalette == 1 then
					Vehicle[curValue].r = Vehicle[curValue].r + 10
				end
				if curPalette == 2 then
					Vehicle[curValue].g = Vehicle[curValue].g + 10
				end
				if curPalette == 3 then
					Vehicle[curValue].b = Vehicle[curValue].b + 10
				end
			elseif pad:right() then
				if curPalette == 1 then
					Vehicle[curValue].r = Vehicle[curValue].r + 1
				end
				if curPalette == 2 then
					Vehicle[curValue].g = Vehicle[curValue].g + 1
				end
				if curPalette == 3 then
					Vehicle[curValue].b = Vehicle[curValue].b + 1
				end
			end
			if pad:left() and pad:cross() then
				if curPalette == 1 then
					Vehicle[curValue].r = Vehicle[curValue].r - 10
				end
				if curPalette == 2 then
					Vehicle[curValue].g = Vehicle[curValue].g - 10
				end
				if curPalette == 3 then
					Vehicle[curValue].b = Vehicle[curValue].b - 10
				end
			elseif pad:left() then
				if curPalette == 1 then
					Vehicle[curValue].r = Vehicle[curValue].r - 1
				end
				if curPalette == 2 then
					Vehicle[curValue].g = Vehicle[curValue].g - 1
				end
				if curPalette == 3 then
					Vehicle[curValue].b = Vehicle[curValue].b - 1
				end
			end

			if Vehicle[curValue].r > 255 then
				Vehicle[curValue].r = 255
			end
			if Vehicle[curValue].r < 0 then
				Vehicle[curValue].r = 0
			end
			if Vehicle[curValue].g > 255 then
				Vehicle[curValue].g = 255
			end
			if Vehicle[curValue].g < 0 then
				Vehicle[curValue].g = 0
			end
			if Vehicle[curValue].b > 255 then
				Vehicle[curValue].b = 255
			end
			if Vehicle[curValue].b < 0 then
				Vehicle[curValue].b = 0
			end
		
		
			if curPalette ~= 1 then
				Image:fillRect(50-2, 50-2, 70+4, 10+4, UnSelectColor)
			end
			if curPalette == 1 then
				Image:fillRect(50-2, 50-2, 70+4, 10+4, SelectColor)
			end
			Image:fontPrint(Plain, 50-2, 50-Plain:getTextSize("Red : " .. Vehicle[curValue].r)["height"]+3, "Red : " .. Vehicle[curValue].r, UnSelectColor)
			Image:fillRect( 50, 50, 70, 10, grey)
			Image:fillRect( 50, 50,  Vehicle[curValue].r/255*70, 10, red)	


			if curPalette ~= 2 then
				Image:fillRect(50-2, 80-2, 70+4, 10+4, UnSelectColor)
			end
			if curPalette == 2 then
				Image:fillRect(50-2, 80-2, 70+4, 10+4, SelectColor)
			end
			Image:fontPrint(Plain, 50-2, 80-Plain:getTextSize("Green : " .. Vehicle[curValue].g)["height"]+3, "Green : " .. Vehicle[curValue].g, UnSelectColor)
			Image:fillRect( 50, 80, 70, 10, grey)
			Image:fillRect( 50, 80,  Vehicle[curValue].g/255*70, 10, green)


			if curPalette ~= 3 then
				Image:fillRect(50-2, 110-2, 70+4, 10+4, UnSelectColor)
			end
			if curPalette == 3 then
				Image:fillRect(50-2, 110-2, 70+4, 10+4, SelectColor)
			end

			Image:fontPrint(Plain, 50-2, 110-Plain:getTextSize("Blue : " .. Vehicle[curValue].b)["height"]+3, "Blue : " .. Vehicle[curValue].b, UnSelectColor)
			Image:fillRect( 50, 110, 70, 10, grey)
			Image:fillRect( 50, 110,  Vehicle[curValue].b/255*70, 10, blue)

			Image:fontPrint(Plain, 135-2, 50-Plain:getTextSize("Preview")["height"]+3, "Preview", UnSelectColor)
			Image:fillRect( 135-2, 50-2,  50+4, 70+4, UnSelectColor)
			Image:fillRect( 135, 50,  50, 70, Color.new( Vehicle[curValue].r, Vehicle[curValue].g, Vehicle[curValue].b))

			if pad:circle() and pad:circle() ~= oldpad:circle() then
				DoPalette = false
				PaletteBG = nil
				collectgarbage()
			end

	elseif Load == true or Save == true and Start == true then

		Image:fillRect( 0, 0, 480, 272, MainColor)

		for a = 1, 4 do


			if a <= 2 then
				if curSave == a then
					Image:fillRect( (60*a+(150*(a-1)))-2, 34-2, 150+4, 85+4, SelectColor)
				else
					Image:fillRect( (60*a+(150*(a-1)))-2, 34-2, 150+4, 85+4, UnSelectColor)
				end

				if CarDir[a] ~= nil then
					--Image:fillRect( 60*a+(150*(a-1)), 34, 150, 85, white)
					Image:blit( 60*a+(150*(a-1)), 34, Image.load("Images/Vehicles/" ..  tonumber(string.sub(CarDir[a].name, string.len(CarDir[a].name)-7,string.len(CarDir[a].name)-5)) .. ".png"))
				else
					Image:blit( 60*a+(150*(a-1)), 34, Image.load("Images/None.png"))
				end
			else
				if curSave == a then
					Image:fillRect( (60*(a-2)+150*(a-3))-2, 153-2, 150+4, 85+4, SelectColor)
				else
					Image:fillRect( (60*(a-2)+150*(a-3))-2, 153-2, 150+4, 85+4, UnSelectColor)
				end

				if  CarDir[a] ~= nil then
				--	Image:fillRect( 60*(a-2)+150*(a-3), 153, 150, 85, white)
					Image:blit( 60*(a-2)+150*(a-3), 153, Image.load("Images/Vehicles/" ..  tonumber(string.sub(CarDir[a].name, string.len(CarDir[a].name)-7,string.len(CarDir[a].name)-5)) .. ".png"))
				else
					Image:blit( 60*(a-2)+150*(a-3), 153, Image.load("Images/None.png"))
				end				
			end
		end

		if pad:right() and pad:right() ~= oldpad:right() then
			curSave = curSave+1
		end
		if pad:left() and pad:left() ~= oldpad:left() then
			curSave = curSave-1
		end
		if pad:up() and pad:up() ~= oldpad:up() and curSave ~= 2 then
			curSave = curSave-2
		end
		if pad:down() and pad:down() ~= oldpad:down() and curSave ~= 3 then
			curSave = curSave+2
		end

		if pad:circle() and pad:circle() ~= oldpad:circle() then
			Load = false
			Save = false
			pause = true

			curSave = 1
		end

		if curSave > 4 then
			curSave = 4
		end
		if curSave < 1 then
			curSave = 1
		end
						
		if Load == true then
			if pad:cross() and pad:cross() ~= oldpad:cross() and CarDir[curSave] ~= nil  then
				Vehicle = table.load("Showroom/" .. CarDir[curSave].name)
				for line in io.lines("Handling/Vehicles/" .. VehicleIDs[Vehicle[1][1]].id .. ".sc") do
						table.insert(VehicleHandling, tonumber(line))
				end
				if table.getn(Vehicle) <= 27 then
					table.insert( Vehicle, 3, {txt = VehicleIDs[Vehicle[1][1]][2], max = 0})
					table.insert( Vehicle, 22, {val = VehicleHandling[11], min = 100, max = 250000, inc = 50})
				end
				VehicleHandling = nil
				Load = false
				LoadedPic[1] = Image.load(VehicleIDs[Vehicle[1][1]][1])
				LoadedPic[2] = Image.load(Garages[Vehicle[2][1]][1])
			end
			
			
		elseif Save == true then
			if pad:cross() and pad:cross() ~= oldpad:cross() then

				for d = 1, table.getn(CarDir) do
					if  tonumber(string.sub(CarDir[d].name, string.len(CarDir[d].name)-5,string.len(CarDir[d].name)-5)) == curSave then
						System.removeFile("Showroom/" .. CarDir[d].name)
					end
				end

				table.save(Vehicle, "Showroom/(" .. curSave .. ") " .. VehicleIDs[Vehicle[1][1]][2] .. " [" .. VehicleIDs[Vehicle[1][1]].id .. "].vms")

				Save = false 				
			end
		end
	elseif Import == true and Start == true then

		if Plate == nil then
			Plate = Image.load("Images/plate.png")
			Port = Image.load("Images/port.png")
		end

		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:fillRect( 8, 20, 215, 74, SelectColor)
		Image:blit( 0, 0, Port)

		--Display of Import Menu
		for c = 1,3 do
			if Handling[c+(curFile-1)] ~= nil then
				Image:blit( 10, (10*c)+(70*c)-57.5, Plate)
				printCentered( Plain, 116, 80*c, Handling[c+(curFile-1)][1], red)
			end
		end

		if pad:up() and pad:up() ~= oldpad:up() then
			curFile = curFile - 1
		end
		if pad:down() and pad:down() ~= oldpad:down() then
			curFile = curFile + 1
		end

		if curFile > table.getn(Handling) then
			curFile = 1
		end
		if curFile < 1 then
			curFile = table.getn(Handling)
		end

		if pad:circle() and pad:circle() ~= oldpad:circle() then
			curFile = 1
			Handling = {}
			Import = false
			Plate = nil
			Port = nil
			collectgarbage()
		end


		if pad:cross() and pad:cross() ~= oldpad:cross() then


			Vehicle[8].val = tonumber(Handling[curFile][9])
			Vehicle[9].val = tonumber(Handling[curFile][10])
			Vehicle[10].val = tonumber(Handling[curFile][11])

			if Handling[curFile][16] == "R" then
				Vehicle[11][1] = 1
			elseif Handling[curFile][16] == "F" then
				Vehicle[11][1] = 2
			elseif Handling[curFile][16] == "4" then
				Vehicle[11][1] = 3				
			end
			if Handling[curFile][17] == "P" then
				Vehicle[12][1] = 1
			elseif Handling[curFile][17] == "D" then
				Vehicle[12][1] = 2
			elseif Handling[curFile][17] == "E" then
				Vehicle[12][1] = 3
			end
			Vehicle[13][1] = tonumber(Handling[curFile][12])

			Vehicle[14].val = tonumber(Handling[curFile][25])
			Vehicle[15].val = tonumber(Handling[curFile][26])
			Vehicle[16].val = tonumber(Handling[curFile][23])
			Vehicle[17].val = tonumber(Handling[curFile][22])
			Vehicle[18].val = tonumber(Handling[curFile][27])
			Vehicle[19].val = tonumber(Handling[curFile][28])

			Vehicle[20].val = tonumber(Handling[curFile][21])
			Vehicle[21].val = tonumber(Handling[curFile][2])
			Vehicle[22].val = tonumber(Handling[curFile][5])
			Vehicle[23].val = tonumber(Handling[curFile][6])
			Vehicle[24].val = tonumber(Handling[curFile][7])


--[[
			VICE CITY
			Vehicle[7].val = tonumber(Handling[curFile][10])
			Vehicle[8].val = tonumber(Handling[curFile][11])
			Vehicle[9].val = tonumber(Handling[curFile][12])

			Vehicle[10].val = Handling[curFile][16]
			Vehicle[11].val = Handling[curFile][17]
			Vehicle[12].val = Handling[curFile][13]

			Vehicle[13].val = tonumber(Handling[curFile][27])
			Vehicle[14].val = tonumber(Handling[curFile][28])
			Vehicle[15].val = tonumber(Handling[curFile][23])
			Vehicle[16].val = tonumber(Handling[curFile][22])
			Vehicle[17].val = tonumber(Handling[curFile][29])
			Vehicle[18].val = tonumber(Handling[curFile][30])

			Vehicle[19].val = tonumber(Handling[curFile][21])
			Vehicle[20].val = tonumber(Handling[curFile][2])
			Vehicle[21].val = tonumber(Handling[curFile][6])
			Vehicle[22].val = tonumber(Handling[curFile][7])
			Vehicle[23].val = tonumber(Handling[curFile][8])
]]--
			Import = false

			curFile = 1
			Handling = {}

			Plate = nil
			Port = nil
			collectgarbage()

		end

	
	elseif Export == true and Start == true then

		if Plate == nil then
			Plate = Image.load("Images/plate.png")
			Port = Image.load("Images/port.png")
		end

		Image:fillRect(0, 0, 480, 272, MainColor)
		Image:fillRect( 8, 20, 215, 74, SelectColor)
		Image:blit( 0, 0, Port)


		for c = 1,3 do
			if CheatDir[c+(curFile-1)] ~= nil then
				Image:blit( 10, (10*c)+(70*c)-57.5, Plate)
				printCentered( Plain, 116, 80*c, string.sub(string.gsub( string.gsub( CheatDir[c+(curFile-1)].name, ".TXT", ""), ".txt", ""), 1, 15), red)
			end
		end

		if pad:up() and pad:up() ~= oldpad:up() then
			curFile = curFile - 1
		end
		if pad:down() and pad:down() ~= oldpad:down() then
			curFile = curFile + 1
		end

		if curFile > table.getn(CheatDir) then
			curFile = table.getn(CheatDir)
		end
		if curFile < 1 then
			curFile = 1
		end

		if pad:circle() and pad:circle() ~= oldpad:circle() then
			curFile = 1
			Export = false
			Plate = nil
			Port = nil
			collectgarbage()
		end

		if pad:cross() and pad:cross() ~= oldpad:cross() then
			
			if System.listDirectory("ms0:/cheats/vcs/") ~= nil then
				CheatFile = io.open("ms0:/cheats/vcs/" .. CheatDir[curFile].name, "a")	
			else	
				CheatFile = io.open("./Cheats/" .. CheatDir[curFile].name, "a")			
			end	

				if Vehicle[3].txt ~= "" then
					CheatFile:write("\r\n\r\n#cheat " .. Vehicle[3].txt .. " at " .. Garages[Vehicle[2][1]][2])
				else
					CheatFile:write("\r\n\r\n#cheat Pimped " .. VehicleIDs[Vehicle[1][1]][2] .. " at " .. Garages[Vehicle[2][1]][2])
				end

				CheatFile:write("\r\n //Created By Sunshine Customs")
				CheatFile:write("\r\n //Sunshine Customs Created By emcp")
				CheatFile:write("\r\n //Addresses Found By Vette")

				if Garages[Vehicle[2][1]][2] ~= "None" then
					CheatFile:write("\r\n //Basics")
					CheatFile:write("\r\n setint(" .. Garages[Vehicle[2][1]][3] .. ", " .. VehicleIDs[Vehicle[1][1]].id .. "); //Car Id")
					CheatFile:write("\r\n setchar(" .. Garages[Vehicle[2][1]][3] .. "+0x24, " ..  Vehicle[4].r  .. "," .. Vehicle[4].g .. "," .. Vehicle[4].b .. ", 255); //Color 1")
					CheatFile:write("\r\n setchar(" .. Garages[Vehicle[2][1]][3] .. "+0x28, " ..  Vehicle[5].r  .. "," .. Vehicle[5].g .. "," .. Vehicle[5].b .. ", 255); //Color2")
				end
				if Vehicle[3].txt ~= VehicleIDs[Vehicle[1][1]][2] or Vehicle[3].txt ~= "" then
					CheatFile:write("\r\n setshort(" .. VehicleIDs[Vehicle[1][1]].name .. ", 1, " .. CheatText(Vehicle[3].txt) .. " 0); ")
				end
			
				CheatFile:write("\r\n //Wheels")
				if VehicleIDs[Vehicle[1][1]].tyre ~= nil  then
					CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].tyre .. ", " .. Vehicle[7].val .. ", " .. Vehicle[7].val .. "); //wheel size")
				end
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x6c, " .. Vehicle[8].val .. "); //Traction Multiplier")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xc4, " .. Vehicle[9].val .. "); //Traction Loss")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x70, " .. Vehicle[10].val .. "); //Traction Bias")
			
				CheatFile:write("\r\n //Engine")
				CheatFile:write("\r\n setchar(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x5c, \'" .. Drive[Vehicle[11][1]][2] .. "\', \'" .. Engine[Vehicle[12][1]][2] .. "\', " .. Gears[Vehicle[13][1]][2] .. "); // Drive type / Engine type / Gears")

				CheatFile:write("\r\n //Suspension")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x7c, " .. Vehicle[14].val .. "); //Suspension Upper Limit")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x80, " .. Vehicle[15].val .. "); //Suspension Lower Limit")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x78, " .. Vehicle[16].val .. "); //Suspension Damping Level")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x74, " .. Vehicle[17].val .. "); //Suspension Force Level")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x84, " .. Vehicle[18].val .. "); //Suspension Bias")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x88, " .. Vehicle[19].val .. "); //Anti-Dive Multiplier")

				CheatFile:write("\r\n //Handling")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x68, " .. Vehicle[20].val .. "); //Steering Lock")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xbc, " .. Vehicle[21].val .. "); //Vehilce Mass")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xc0, " .. Vehicle[22].val .. "); //Turn Mass")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xa0, " .. Vehicle[23].val .. "); //Centre of Mass - X")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xa4, " .. Vehicle[24].val .. "); //Centre of Mass - Y")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xa8, " .. Vehicle[25].val .. "); //Centre of Mass - Z")
					
				if  Vehicle[26].val ==  Vehicle[26].on then
					CheatFile:write("\r\n //Effects")	
					CheatFile:write("\r\n //Exhaust")
					CheatFile:write("\r\n setchar(0x09569B94,  " .. Vehicle[28].r .. ", " ..  Vehicle[28].g .. ", " ..  Vehicle[2].b .. ");")
					CheatFile:write("\r\n setchar(0x09569B90,  0x4);")
				end				
				if VehicleIDs[Vehicle[1][1]].neon ~= nil then
					if  Vehicle[27].val ==  Vehicle[27].on then
						CheatFile:write("\r\n //Neon")
						CheatFile:write("\r\n for(neon=0;neon<16;neon++)")
						CheatFile:write("\r\n {setchar(" .. VehicleIDs[Vehicle[1][1]].neon .. "+4*neon,  " .. Vehicle[29].r .. ", " ..  Vehicle[29].g .. ", " ..  Vehicle[29].b .. ");}")
					end
				end
				if Vehicle[6].val == Vehicle[6].on then
					CheatFile:write("\r\n //Teleport")
					CheatFile:write("\r\n teleport(" .. Garages[Vehicle[2][1]][4] .. ");")
				end

				CheatFile:write("\r\noff()\r\n")		 

			CheatFile:close()	
			Export = false	
			curFile = 1

			Plate = nil
			Port = nil
			collectgarbage()
		end

	elseif Options == true and Start == true then

		Image:fillRect(0, 0, 480, 272, MainColor)

		if pad:up() and pad:up() ~= oldpad:up() then
			curOp = curOp-1
		end
		if pad:down() and pad:down() ~= oldpad:down() then
			curOp = curOp+1
		end

		if curOp > 8 then
			curOp = 1
		end
		if curOp < 1 then
			curOp = 8
		end
 

		if pad:circle() and pad:circle() ~= oldpad:circle() or  pad:select() and pad:select() ~= oldpad:select() then

			if curOp == 8 then
				MainColor = Color.new(65, 192, 215)
				--MainFader:clear(Color.new(65, 192, 215, 20))
				SideFader:clear(Color.new(204, 204, 204, 100))
				SelectColor = Color.new(217, 217, 75)
				UnSelectColor = Color.new(0, 0, 0)
				BarBgColor = Color.new(226, 226, 226)
				BarColor = Color.new(0, 0, 255)
				MenuSelectorColor = Color.new(204, 204, 204)
			end

			if curOp ~= 8 then	
				MainColor = Color.new(myColors[MainCol][1], myColors[MainCol][2], myColors[MainCol][3])
				--MainFader:clear(Color.new(myColors[MainCol][1], myColors[MainCol][2], myColors[MainCol][3]))
				SideFader:clear(Color.new(myColors[SideCol][1], myColors[SideCol][2], myColors[SideCol][3], 100))
				UnSelectColor = Color.new(myColors[UnSelCol][1], myColors[UnSelCol][2], myColors[UnSelCol][3])
				SelectColor = Color.new(myColors[SelCol][1], myColors[SelCol][2], myColors[SelCol][3])
				BarBgColor = Color.new(myColors[BarBgCol][1], myColors[BarBgCol][2], myColors[BarBgCol][3])
				BarColor = Color.new(myColors[BarCol][1], myColors[BarCol][2], myColors[BarCol][3])
				MenuSelectorColor = Color.new(myColors[MenuSelCol][1], myColors[MenuSelCol][2], myColors[MenuSelCol][3])
			end
		end

		if pad:circle() and pad:circle() ~= oldpad:circle() then
			if curOp == 8 then
				OptionSet[1] = {65, 192, 215}
				OptionSet[2] = {204, 204, 204, 100}
				OptionSet[3] = {217, 217, 75}
				OptionSet[4] = {0, 0, 0}
				OptionSet[5] = {226, 226, 226}
				OptionSet[6] = {0, 0, 255}
				OptionSet[7] = {204, 204, 204}
			end

			if curOp ~= 8 then
				OptionSet[1] = {myColors[MainCol][1], myColors[MainCol][2], myColors[MainCol][3]}
				OptionSet[2] = {myColors[SideCol][1], myColors[SideCol][2], myColors[SideCol][3]}
				OptionSet[3] = {myColors[UnSelCol][1], myColors[UnSelCol][2], myColors[UnSelCol][3]}
				OptionSet[4] = {myColors[SelCol][1], myColors[SelCol][2], myColors[SelCol][3]}
				OptionSet[5] = {myColors[BarBgCol][1], myColors[BarBgCol][2], myColors[BarBgCol][3]}
				OptionSet[6] = {myColors[BarCol][1], myColors[BarCol][2], myColors[BarCol][3]}
				OptionSet[7] = {myColors[MenuSelCol][1], myColors[MenuSelCol][2], myColors[MenuSelCol][3]}
			end

			table.save(OptionSet, "Settings.cfg")
		end

		if pad:circle() and pad:circle() ~= oldpad:circle() or pad:start() and pad:start() ~= oldpad:start() or  pad:select() and pad:select() ~= oldpad:select()  then
			Options = false
			pause = true
			curOp = 1
		end


		if curOp == 1 then
			Image:fontPrint(Plain, 10, 30, "Main Color : ", SelectColor)
			Image:fillRect(300, 15, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				MainCol = MainCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				MainCol = MainCol-1
			end

			if MainCol > table.getn(myColors) then
				MainCol = 1
			end
			if MainCol < 1 then
				MainCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 30, "Main Color : ", UnSelectColor)
			Image:fillRect(300, 15, 22, 22, UnSelectColor)
		end
		if curOp == 2 then
			Image:fontPrint(Plain, 10, 60, "Side Color : ", SelectColor)
			Image:fillRect(300, 45, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				SideCol = SideCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				SideCol = SideCol-1
			end

			if SideCol > table.getn(myColors) then
				SideCol = 1
			end
			if SideCol < 1 then
				SideCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 60, "Side Color : ", UnSelectColor)	
			Image:fillRect(300, 45, 22, 22, UnSelectColor)
		end
		if curOp == 3 then
			Image:fontPrint(Plain, 10, 90, "Unselected Color : ", SelectColor)
			Image:fillRect(300, 75, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				UnSelCol = UnSelCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				UnSelCol = UnSelCol-1
			end

			if UnSelCol > table.getn(myColors) then
				UnSelCol = 1
			end
			if UnSelCol < 1 then
				UnSelCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 90, "Unselected Color : ", UnSelectColor)
			Image:fillRect(300, 75, 22, 22, UnSelectColor)
		end
		if curOp == 4 then
			Image:fontPrint(Plain, 10, 120, "Selected Color : ", SelectColor)
			Image:fillRect(300, 105, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				SelCol = SelCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				SelCol = SelCol-1
			end

			if SelCol > table.getn(myColors) then
				SelCol = 1
			end
			if SelCol < 1 then
				SelCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 120, "Selected Color : ", UnSelectColor)
			Image:fillRect(300, 105, 22, 22, UnSelectColor)
		end
		if curOp == 5 then
			Image:fontPrint(Plain, 10, 150, "Bar Background Color : ", SelectColor)
			Image:fillRect(300, 135, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				BarBgCol = BarBgCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				BarBgCol = BarBgCol-1
			end

			if BarBgCol > table.getn(myColors) then
				BarBgCol = 1
			end
			if BarBgCol < 1 then
				BarBgCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 150, "Bar Background Color : ", UnSelectColor)
			Image:fillRect(300, 135, 22, 22, UnSelectColor)
		end
		if curOp == 6 then
			Image:fontPrint(Plain, 10, 180, "Bar Color : ", SelectColor)
			Image:fillRect(300, 165, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				BarCol = BarCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				BarCol = BarCol-1
			end

			if BarCol > table.getn(myColors) then
				BarCol = 1
			end
			if BarCol < 1 then
				BarCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 180, "Bar Color : ", UnSelectColor)
			Image:fillRect(300, 165, 22, 22, UnSelectColor)
		end
		if curOp == 7 then
			Image:fontPrint(Plain, 10, 210, "Menu Selector Color : ", SelectColor)
			Image:fillRect(300, 195, 22, 22, SelectColor)

			if pad:right() and pad:right() ~= oldpad:right() then
				MenuSelCol = MenuSelCol+1
			end
			if pad:left() and pad:left() ~= oldpad:left() then
				MenuSelCol = MenuSelCol-1
			end

			if MenuSelCol > table.getn(myColors) then
				MenuSelCol = 1
			end
			if MenuSelCol < 1 then
				MenuSelCol = table.getn(myColors)
			end
		else
			Image:fontPrint(Plain, 10, 210, "Menu Selector Color : ", UnSelectColor)
			Image:fillRect(300, 195, 22, 22, UnSelectColor)
		end
		if curOp == 8 then
			Image:fontPrint(Plain, 10, 260, "Default Settings", SelectColor)
		else
			Image:fontPrint(Plain, 10, 260, "Default Settings", UnSelectColor)
		end

		Image:fillRect(302, 17, 18, 18, Color.new( myColors[MainCol][1], myColors[MainCol][2], myColors[MainCol][3]))
		Image:fillRect(302, 47, 18, 18, Color.new( myColors[SideCol][1], myColors[SideCol][2], myColors[SideCol][3]))
	
		Image:fillRect(302, 77, 18, 18, Color.new( myColors[UnSelCol][1], myColors[UnSelCol][2], myColors[UnSelCol][3]))
		Image:fillRect(302, 107, 18, 18, Color.new( myColors[SelCol][1], myColors[SelCol][2], myColors[SelCol][3]))

		Image:fillRect(302, 137, 18, 18, Color.new( myColors[BarBgCol][1], myColors[BarBgCol][2], myColors[BarBgCol][3]))
		Image:fillRect(302, 167, 18, 18, Color.new( myColors[BarCol][1], myColors[BarCol][2], myColors[BarCol][3]))

		Image:fillRect(302, 197, 18, 18, Color.new( myColors[MenuSelCol][1], myColors[MenuSelCol][2], myColors[MenuSelCol][3]))

		Plain:setPixelSizes( 0, 12)
		Image:fontPrint(Plain, 300, 260, "Press Circle To Save", UnSelectColor)
		Image:fontPrint(Plain, 300, 270, "Start To Exit or Select To Preview", UnSelectColor)
		Plain:setPixelSizes( 0, 20)

	elseif USB == true and Start == true then
		
		Image:fillRect(0, 0, 480, 272, MainColor)

		Image:fontPrint(Plain, 10, 30, "USB Activated", UnSelectColor)
		System.usbDiskModeActivate()

		Image:fontPrint(Plain, 10, 260, "Press Circle To Return", UnSelectColor)

		if pad:circle() and pad:circle() ~= oldpad:circle() then
			USB = false
			pause = true

			System.usbDiskModeDeactivate()
		end
	else
		Plain:setPixelSizes( 0, 12)

         		--Gets Number Of Values To Change
		NoValues = table.getn(Vehicle)

         		--Gets Number Of Values To Change On A Page
		NoValuesPerPage = table.getn(Vehicle[curValue])


		--Gets Number Of Values To Change
		NoPages = table.getn(Pages)

		--Pauses And Unpauses 
		if pad:start() and pad:start() ~= oldpad:start() and pause == false and Start == true and Save == false and Load == false and DoOSK == false then
			pause = true
		end

		if pad:square() and Start == true and DoPalette == false and DoOSK == false then
			Help = true
		else
			Help = false
		end

  	        --Switches Options
		if DoPalette == false and DoOSK == false and Help == false and Start == true then

			if pad:up() then
				curValue = curValue-1
			end
			if pad:down() then
				curValue = curValue+1
			end


			if curValue > Pages[curPage].max then
				curValue = Pages[curPage].min
			end
			if curValue < Pages[curPage].min then
				curValue = Pages[curPage].max
			end

			if pad:r() and pad:r() ~= oldpad:r() then
				curPage = curPage+1	
	
				if curPage > NoPages then
					curPage = 1
				end

				curValue = Pages[curPage].min

				if Backgrounds[curPage] ~= nil then
					BGImage = Image.load(Backgrounds[curPage])
				else
					BGImage = nil
				end
			end
			if pad:l() and pad:l() ~= oldpad:l() then
				curPage = curPage-1

				if curPage < 1 then
					curPage = NoPages
				end

				curValue = Pages[curPage].min

				if Backgrounds[curPage] ~= nil then
					BGImage = Image.load(Backgrounds[curPage])
				else
					BGImage = nil
				end
			end
			
	
		          --Increases The Value Of The Current Bar
			if Vehicle[curValue].max ~= nil and Vehicle[curValue].txt == nil  and Help == false then
				if pad:right() and pad:cross() then
					--Vehicle[curValue].val = Vehicle[curValue].val+(((Vehicle[curValue].max-Vehicle[curValue].min)/100)*10)
					Vehicle[curValue].val = Vehicle[curValue].val+(Vehicle[curValue].inc*10)
				elseif pad:right() then
					--Vehicle[curValue].val = Vehicle[curValue].val+((Vehicle[curValue].max-Vehicle[curValue].min)/100)
					Vehicle[curValue].val = Vehicle[curValue].val+Vehicle[curValue].inc
				end

				if pad:left() and pad:cross() then
					--Vehicle[curValue].val = Vehicle[curValue].val-(((Vehicle[curValue].max-Vehicle[curValue].min)/100)*10)
					Vehicle[curValue].val = Vehicle[curValue].val-(Vehicle[curValue].inc*10)
				elseif pad:left() then
					--Vehicle[curValue].val = Vehicle[curValue].val-((Vehicle[curValue].max-Vehicle[curValue].min)/100)
					Vehicle[curValue].val = Vehicle[curValue].val-Vehicle[curValue].inc
				end

				if Vehicle[curValue].val > Vehicle[curValue].max then
					Vehicle[curValue].val = Vehicle[curValue].max
				end
				if Vehicle[curValue].val < Vehicle[curValue].min then
					Vehicle[curValue].val = Vehicle[curValue].min
				end	
			elseif Vehicle[curValue].r ~= nil and Help == false then
				
				if pad:cross() and pad:cross() ~= oldpad:cross() and DoPalette == false then
					DoPalette = true
					PaletteBG = Image.load("Images/backgrounds/Palette.png")
				end

			elseif Vehicle[curValue].on ~= nil and Help == false then
			--Changes The Value Of The Current Checkbox	
				if pad:cross() and pad:cross() ~= oldpad:cross() and Vehicle[curValue].val == Vehicle[curValue].off then
					Vehicle[curValue].val = Vehicle[curValue].on
				elseif pad:cross() and pad:cross() ~= oldpad:cross() and Vehicle[curValue].val == Vehicle[curValue].on then
					Vehicle[curValue].val = Vehicle[curValue].off
				end
			elseif Vehicle[curValue].txt ~= nil then
				if pad:cross() and pad:cross() ~= oldpad:cross() then
					DoOSK = true
				end
			end

			if pad:triangle() and pad:triangle() ~= oldpad:triangle() and curValue == 1 then
				
				for line in io.lines("Handling/Vehicles/" .. VehicleIDs[Vehicle[1][1]].id .. ".sc") do
						table.insert(VehicleHandling, tonumber(line))
				end
				 
				Vehicle[3].txt = VehicleIDs[Vehicle[1][1]][2]

				if VehicleIDs[Vehicle[1][1]].tyre ~= nil then
					Vehicle[7].val = VehicleHandling[19]
				end

				Vehicle[8].val = VehicleHandling[9]
				Vehicle[9].val = VehicleHandling[7]
				Vehicle[10].val = VehicleHandling[8]

				if VehicleHandling[16] == 82 then
					Vehicle[11][1] = 1
				elseif VehicleHandling[16] == 70 then
					Vehicle[11][1] = 2
				elseif VehicleHandling[16] == 52 then
					Vehicle[11][1] = 3		
				end

				if VehicleHandling[17] == 80 then
					Vehicle[12][1] = 1
				elseif VehicleHandling[17] == 68 then
					Vehicle[12][1] = 2
				elseif VehicleHandling[17] ==69 then
					Vehicle[12][1] = 3	
				end

				Vehicle[13][1] = VehicleHandling[18]

				Vehicle[14].val = VehicleHandling[3]
				Vehicle[15].val = VehicleHandling[4]
				Vehicle[16].val = VehicleHandling[2]
				Vehicle[17].val = VehicleHandling[1]
				Vehicle[18].val = VehicleHandling[5]
				Vehicle[19].val = VehicleHandling[6]

				Vehicle[20].val = VehicleHandling[15]
				Vehicle[21].val = VehicleHandling[10]
				Vehicle[22].val = VehicleHandling[11]
				Vehicle[23].val = VehicleHandling[12]
				Vehicle[24].val = VehicleHandling[13]
				Vehicle[25].val = VehicleHandling[14]

				VehicleHandling = {}

			end
		
		end
 	         --Fills Background	
		Image:blit( 0, 0, SideBar, true)
		Image:blit(0,0,SideFader, true)

		Image:fillRect(81, 0, 399, 272, MainColor)
		if BGImage ~= nil then
			Image:blit( 81+((399/2)-(BGImage:width()/2)), (272/2)-(BGImage:height()/2), BGImage, true)
		end
		Image:blit(81,0,MainFader, true)

		--Shows Page
		Image:fillRect(0, (20*curPage)-20+1, 81, 30, black)
		Image:fillRect(0, (20*curPage)-20+4, 78, 24, MenuSelectorColor)
	
		for a =1,NoPages do
			if curPage < 14 then
				Image:fontPrint(Plain, 5, 20*a, Pages[a][1], UnSelectColor)
			end		
		end	

		--[[
			DrawPic( 103.75, 50, "Vehicle", "Choose Your Vehicle", VehicleIDs, 1)
			DrawBar( 100, 50, "Bar 1",  "This Is Just  test Bar 1", 5)	
			DrawCheck( 100, 150, "pimp my nos", "This Is Just  test check 1", 6)
			DrawText( 100, 200, "Check 2", "This Is Just  test check 2", NOS, 7)
			DrawPalette( 100, 70, "Exhaust Smoke", "Exhaust Smoke Color  (Leave For Default)", 23)
		]]--

		if curPage == 1 then
			DrawPic( 103.75, 50, "Vehicle", "Choose Your Vehicle", VehicleIDs, 1)
			DrawPic( 303.25, 50, "Garage", "Choose Your Garage", Garages, 2)
			DrawOSK( 243.5, 170, "Vehicle Name", "The Name Of Your Vehicle", 3)
			DrawPalette( 243.5, 200, "Base Color", "This Is The Main Color Of Your Vehilce", 4)
			DrawPalette( 243.5, 230, "Stripe Color", "This Is The Stripe Color Of Your Vehilce", 5)
			DrawCheck( 245, 265, "Teleport", "If Checked Neon Will Be Enabled", 6)
		end

		if curPage == 2 then
				DrawBar( 100, 50, "Tyre Size",  "The size of the wheels on your vehicle... Set this too high and your vehicle will be undriveable...", 7)
			DrawBar( 100, 100, "Traction Multiplier",  "The cornering grip of the vehicle as a multiplier of the tyre surface friction...", 8)
			DrawBar( 100, 150, "Traction Loss",  "The accelerating/braking grip of the vehicle as a multiplier of the tyre surface friction...", 9)
			DrawBar( 100, 200, "Traction Bias",  "The ratio of front axle grip to rear axle grip... Higher values will shift the grip forwards...", 10)
		end
		if curPage == 3 then
			DrawText(100, 50, "Drive Type", "None", Drive, 11)
			DrawText(100, 70, "Engine Type", "None", Engine, 12)
			DrawText(100, 90, "Gears", "None", Gears, 13)
		end
		if curPage == 4 then
			DrawBar( 100, 50, "Suspension Upper Limit",  "The maximum height your suspension can go to... Changing it to high values could cause undesired effects on your car...", 14)
			DrawBar( 100, 100, "Suspension Lower Limit",  "This controls your car's ride height. Set it to lower numbers to raise it higher... -1 is about the highest you should raise a car before it gets to hard to stabilize. Using -0.01 will make the car a lowrider...", 15)
			DrawBar( 100, 150, "Suspension Damping Level",  "How much give the suspension has... If your car is leaning to much or not enough change this to help fix it...", 16)
			DrawBar( 100, 200, "Suspension Force Level",  "How hard the suspension pushes on the vehicle... You can use this to give the suspension a very weak strength which will make the car drop a little lower, or you can use it to make the cars suspension stronger causing the wheels to tilt slightly, and raise the car....", 17)
			DrawBar( 281, 50, "Suspension Bias",  "Ratio of suspension force applied at the front compared to the rear of the vehicle...", 18)
			DrawBar( 281, 100, "Anti-Dive Multiplier",  "The amount the vehicle leans at it's front and back when accelerating and reversing...", 19)
		end
		if curPage == 5 then
			DrawBar( 100, 50, "Steering Lock",  "How far the wheels are able to turn on your car... Setting this to a negative number will simulate rear wheel steering...", 20)
			DrawBar( 100, 100, "Vehicle Mass",  "The weight of your vehicle... Make it too high and the car will bounce around as if high gravity was on...", 21)
			DrawBar( 100, 150, "Turn Mass",  "The weight in which the vehicle leans on, when turning. Givin it a shuttle or crazy steering", 22)
			DrawBar( 281, 50, "Centre of Mass - X",  "The X co-ordinate for the centre of your vehicles overall weight. Changing this setting will move the centre of mass to the left or right of the vehicle...", 23)
			DrawBar( 281, 100, "Centre of Mass - Y",  "The Y co-ordinate for the centre of your vehicles overall weight. Changing this setting will move the centre of mass to the front or back of the vehicle...", 24)
			DrawBar( 281, 150, "Centre of Mass - Z",  "The Z co-ordinate for the centre of your vehicles overall weight. Changing this setting will move the centre of mass up or down..", 25)
		end
		if curPage == 6 then

	
			DrawCheck( 100, 50, "Exhaust Smoke", "If Checked Exhaust Smoke Will Be Enabled", 26)
			DrawCheck( 100, 70, "Neon", "If Checked Neon Will Be Enabled", 27)
			if Vehicle[26].val ==  Vehicle[26].on  then
				DrawPalette( 100, 90, "Exhaust Smoke", "Exhaust Smoke Color  (Leave For Default)", 28)
			end
			if VehicleIDs[Vehicle[1][1]].neon ~= nil  then
				if  Vehicle[27].val ==  Vehicle[27].on then
					DrawPalette( 100, 120, "Neon", "Neon/Shadow Color (Leave For Default)", 29)
				end
			end
		end

	if DoOSK == true then

		if OSKImg == nil then
			OSKImg = Image.load("Images/osk.png")
		end

		Image:blit( 0, 0, OSKFader)
		Image:blit( 0, 0, OSKImg)
		Image:blit( OSK.XY[OSK.Row][2][OSK.Key], OSK.XY[OSK.Row][1], OSKSel)

		Image:fontPrint( Plain, 40, 36, Vehicle[curValue].txt)

		if pad:up() then
			OSK.Row = OSK.Row - 1
		end
		if pad:down() then
			OSK.Row = OSK.Row + 1
		end
		if pad:right() then
			OSK.Key = OSK.Key + 1
		end
		if pad:left() then
			OSK.Key = OSK.Key - 1
		end

		if OSK.Row > table.getn(OSK.Keys) then
			OSK.Row = 1
		end
		if OSK.Row < 1 then
			OSK.Row = table.getn(OSK.Keys)
		end
		if OSK.Key < 1 then
			OSK.Key = table.getn(OSK.Keys[OSK.Row])
		end
		if OSK.Key > table.getn(OSK.Keys[OSK.Row]) then
			OSK.Key = 1
		end

		if pad:cross() and Plain:getTextSize(Vehicle[curValue].txt .. string.lower(OSK.Keys[OSK.Row][OSK.Key]))["width"] <= 400 then
				Vehicle[curValue].txt = Vehicle[curValue].txt .. string.lower(OSK.Keys[OSK.Row][OSK.Key])
		end
		if pad:square() and Plain:getTextSize(Vehicle[curValue].txt .. OSK.Keys[OSK.Row][OSK.Key])["width"] <= 400 then
				Vehicle[curValue].txt = Vehicle[curValue].txt .. OSK.Keys[OSK.Row][OSK.Key]
		end

		if pad:triangle() then
				Vehicle[curValue].txt = string.sub( Vehicle[curValue].txt, 1, string.len(Vehicle[curValue].txt)-1)
		end

		if pad:r() and Plain:getTextSize(Vehicle[curValue].txt .. OSK.Keys[OSK.Row][OSK.Key])["width"] <= 400 then
				Vehicle[curValue].txt = Vehicle[curValue].txt .. " "
		end

		if pad:circle() then
				DoOSK = false
				OSKImg = nil
				collectgarbage()
		end
	end

	end


	if Start == false then

		if StartScreen ~= nil then
			if StartScreen:time() >= 0 and StartScreen:time() < 500  then
				CreditSplash = Image.load("Images/Credits/zambia.png")	
			elseif StartScreen:time() >= 6000 and StartScreen:time() < 6500 then
				CreditSplash = Image.load("Images/Credits/sites.png")
			elseif StartScreen:time() >= 9000 and StartScreen:time() < 9500 then
				CreditSplash = Image.load("Images/Credits/emcp.png")	
			elseif StartScreen:time() >= 12000 and StartScreen:time() < 12500 then
				CreditSplash = Image.load("Images/Credits/vette.png")	
			elseif StartScreen:time() >= 15000 and StartScreen:time() < 15500 then
				CreditSplash = Image.load("Images/Credits/waterbottle.png")	
			elseif StartScreen:time() >= 18000 and StartScreen:time() < 18500 then
				CreditSplash = Image.load("Images/Credits/others.png")
			elseif StartScreen:time() >= 21000 and StartScreen:time() < 21500 then
				StartScreen = nil
			elseif StartScreen:time() >= 6000 and pad:cross() and pad:cross() ~= oldpad:cross() then									StartScreen = nil
			end		

			Image:blit(0, 0, CreditSplash)	
	

		elseif StartScreen == nil then

			if CreditSplash ~= nil then
				CreditSplash = nil
				collectgarbage()
			end


			if pad:start() and pad:start() ~= oldpad:start() then
				BGImage = Image.load(Backgrounds[curPage])
				Plain:setPixelSizes( 0, 12)
				Start = true
				collectgarbage()
			end
			Image:fillRect(0, 0, 480, 272, MainColor)
			Plain:setPixelSizes( 0, 20)
			printCentered(Plain, 240, 250, "Press Start To Begin", black)
			Image:blit(0, 0, StartScreenPic)

		end

	end


--Continues Loop And Flips The Screen
screen.waitVblankStart()
screen.flip()
oldpad = pad
end