--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)



PaletteBG = Image.load("Images/backgrounds/Palette.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))

Helpbg = Image.load("Images/help.png")

--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"},
{ "Images/Vehicles/171.png", "Admiral", id = 171, vms = "0x962eb20", tyre = "0x935E438", neon = "0x0972EFF0"},
{ "Images/Vehicles/172.png", "Cheetah", id = 172, vms = "0x962ea40", tyre = "0x935E6D8", neon = "0x0972EFF0"},
--{ "Images/Vehicles/173.png", "Little Willie", id = 173, neon = "0x09730070"},
{ "Images/Vehicles/174.png", "Baggage Handler", id = 174, vms = "0x962ec00", tyre = "0x935EC18", neon = "0x0972EFF0"},
{ "Images/Vehicles/175.png", "Pheonix", id = 175, vms = "0x96334A0", tyre = "0x936C358", neon = "0x0972EFF0"},
{ "Images/Vehicles/176.png", "Perennial", id = 176, vms = "0x962ece0", tyre = "0x935F158", neon = "0x0972EFF0"},
{ "Images/Vehicles/177.png", "Blista Compact", id = 177, vms = "0x962edc0", tyre = "0x935F3F8", neon = "0x0972EFF0"},
{ "Images/Vehicles/178.png", "BMX", id = 178, vms = "0x962f060", neon = "0x097272d0"},
{ "Images/Vehicles/179.png", "BMX-Girl", id = 179, vms = "0x962f300", neon = "0x097272d0"},
{ "Images/Vehicles/180.png", "Bobcat", id = 180, vms = "0x962f140", tyre = "0x935FBD8", neon = "0x0972EFF0"},
{ "Images/Vehicles/181.png", "Bulldozzer", id = 181, vms = "0x962ef80", tyre = "0x935FE78", neon = "0x0972EFF0"},
{ "Images/Vehicles/182.png", "Burrito", id = 182, vms = "0x962f220", tyre = "0x9360118", neon = "0x0972EFF0"},
{ "Images/Vehicles/183.png", "Cabbie", id = 183, vms = "0x962eea0", tyre = "0x93603B8", neon = "0x0972EFF0"},
{ "Images/Vehicles/184.png", "Caddy", id = 184, vms = "0x962f3e0", tyre = "0x9360658", neon = "0x0972EFF0"},
{ "Images/Vehicles/186.png", "Polaris V8", id = 186, vms = "0x962f4c0", tyre = "0x9360B98", neon = "0x0972EFF0"},
{ "Images/Vehicles/187.png", "Deluxo", id = 187, vms = "0x962f680", tyre = "0x9360E38", neon = "0x0972EFF0"},
--{ "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"},
{ "Images/Vehicles/191.png", "VCPD Wintergreen", id = 191, vms = "0x962fa00", neon = "0x097272d0"},
{ "Images/Vehicles/192.png", "Esperanto", id = 192, vms = "0x962fbc0", tyre = "0x9361B58", neon = "0x0972EFF0"},
{ "Images/Vehicles/193.png", "FBI Washington", id = 193, vms = "0x962fca0", tyre = "0x9361DF8", neon = "0x0972EFF0"},
{ "Images/Vehicles/194.png", "Fire Truck", id = 194, vms = "0x962fae0", tyre = "0x9362098", neon = "0x0972EFF0"},
{ "Images/Vehicles/195.png", "Grendale", id = 195, vms = "0x962fd80", tyre = "0x9362338", neon = "0x0972EFF0"},
{ "Images/Vehicles/196.png", "Greenwood", id = 196, vms = "0x962fe60", tyre = "0x93625D8", neon = "0x0972EFF0"},
{ "Images/Vehicles/197.png", "Hermes", id = 197, vms = "0x962ff40", tyre = "0x9362878", neon = "0x0972EFF0"},
{ "Images/Vehicles/198.png", "Bovver '64", id = 198, vms = "0x9630100", neon = "0x0972EFF0"},
{ "Images/Vehicles/199.png", "Idaho", id = 199, vms = "0x9630020", tyre = "0x9362DB8", neon = "0x0972EFF0"},
{ "Images/Vehicles/200.png", "Landstalker", id = 200, vms = "0x96301e0", tyre = "0x9363058", neon = "0x0972EFF0"},
{ "Images/Vehicles/201.png", "Manana", id = 201, vms = "0x96302c0", tyre = "0x93632F8", neon = "0x0972EFF0"},
{ "Images/Vehicles/202.png", "Ventoso", id = 202, vms = "0x96303a0", neon = "0x097272d0"},
{ "Images/Vehicles/203.png", "Oceanic", id = 203, vms = "0x9630560", tyre = "0x9363838", neon = "0x0972EFF0"},
{ "Images/Vehicles/204.png", "Police Cheetah", id = 204, vms = "0x9630480", tyre = "0x9363AD8", neon = "0x0972EFF0"},
{ "Images/Vehicles/205.png", "Sanchez", id = 205, vms = "0x9630640", neon = "0x097272d0"},
{ "Images/Vehicles/206.png", "Stallion", id = 206, vms = "0x9630800", tyre = "0x9364018", neon = "0x0972EFF0"},
{ "Images/Vehicles/207.png", "Police Cruiser", id = 207, vms = "0x96308e0", tyre = "0x93642B8", neon = "0x0972EFF0"},
{ "Images/Vehicles/208.png", "Domestobot", id = 208, vms = "0x9630720", tyre = "0x9364558", neon = "0x0972EFF0"},
{ "Images/Vehicles/209.png", "Patriot", id = 209, vms = "0x96309c0", tyre = "0x93647F8", neon = "0x0972EFF0"},
{ "Images/Vehicles/210.png", "Pony", id = 210, vms = "0x9630aa0", tyre = "0x9364A98", neon = "0x0972EFF0"},
{ "Images/Vehicles/211.png", "Sentinel", id = 211, vms = "0x9630b80", tyre = "0x9364D38", neon = "0x0972EFF0"},
{ "Images/Vehicles/212.png", "PCJ 600", id = 212, vms = "0x9630c60", neon = "0x097272d0"},
--{ "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"},
{ "Images/Vehicles/217.png", "Walton", id = 217, vms = "0x96310c0", tyre = "0x9365CF8", neon = "0x0972EFF0"},
{ "Images/Vehicles/218.png", "Barracks OL 2", id = 218, vms = "0x96311a0", tyre = "0x9365F98", neon = "0x0972EFF0"},
--{ "Images/Vehicles/219.png", "Predator", id = 219},
{ "Images/Vehicles/220.png", "Flatbed", id = 220, vms = "0x9631440", tyre = "0x93664D8", neon = "0x0972EFF0"},
{ "Images/Vehicles/221.png", "Barracks OL", id = 221, vms = "0x9630fe0", tyre = "0x9366778", neon = "0x0972EFF0"},
--{ "Images/Vehicles/222.png", "Biplane", id = 222},
{ "Images/Vehicles/223.png", "Moonbeam", id = 223, vms = "0x9631740", tyre = "0x9366CB8", neon = "0x0972EFF0"},
{ "Images/Vehicles/224.png", "Rumpo", id = 224, vms = "0x9631820", tyre = "0x9366F58", neon = "0x0972EFF0"},
--{ "Images/Vehicles/225.png", "Yola", id = 225, neon = "0x0972EFF0"},
{ "Images/Vehicles/226.png", "Taxi", id = 226, vms = "0x9631ba0", tyre = "0x9367498", neon = "0x0972EFF0"},
{ "Images/Vehicles/227.png", "Ambulance", id = 227, vms = "0x9631660", tyre = "0x9367738", neon = "0x0972EFF0"},
{ "Images/Vehicles/228.png", "Stretch", id = 228, vms = "0x96319e0", tyre = "0x93679D8", neon = "0x0972EFF0"},
{ "Images/Vehicles/229.png", "Faggio", id = 229, vms = "0x9631c80", neon = "0x097272d0"},
{ "Images/Vehicles/230.png", "ATV", id = 230, vms = "0x9631d60", tyre = "0x9367f18", neon = "0x0972EFF0"},
{ "Images/Vehicles/231.png", "Biker Angel", id = 231, vms = "0x9631f60", neon = "0x097272d0"},
{ "Images/Vehicles/232.png", "Freeway", id = 232, vms = "0x9631e40", neon = "0x097272d0"},
--{ "Images/Vehicles/233.png", "Jetski", id = 233},
{ "Images/Vehicles/234.png", "Enforcer", id = 234, vms = "0x9631ac0", tyre = "0x9368998", neon = "0x0972EFF0"},
{ "Images/Vehicles/235.png", "Boxville", id = 235, vms = "0x96323c0", tyre = "0x9368C38", neon = "0x0972EFF0"},
{ "Images/Vehicles/236.png", "Benson", id = 236, vms = "0x96322e0", tyre = "0x9368ED8", neon = "0x0972EFF0"},
{ "Images/Vehicles/237.png", "Coach", id = 237, vms = "0x9632120", tyre = "0x9369178", neon = "0x0972EFF0"},
{ "Images/Vehicles/238.png", "Mule", id = 238, vms = "0x9632200", tyre = "0x9369418", neon = "0x0972EFF0"},
{ "Images/Vehicles/239.png", "Voodoo", id = 239, vms = "0x96324a0", tyre = "0x93696B8", neon = "0x0972EFF0"},
{ "Images/Vehicles/240.png", "Securicar", id = 240, vms = "ox9632580", tyre = "0x9369958", neon = "0x0972EFF0"},
{ "Images/Vehicles/241.png", "Trashmaster", id = 241, vms = "0x9632660", tyre = "0x9369BF8", neon = "0x0972EFF0"},
{ "Images/Vehicles/243.png", "Yankee", id = 243, vms = "0x9632820", tyre = "0x936A138", neon = "0x0972EFF0"},
{ "Images/Vehicles/244.png", "Mr Whoopie", id = 244, vms = "0x9632900", tyre = "0x936A3D8", neon = "0x0972EFF0"},
{ "Images/Vehicles/245.png", "Sandking", id = 245, vms = "0x96329e0", tyre = "0x936A678", neon = "0x0972EFF0"},
{ "Images/Vehicles/246.png", "Rhino", id = 246, vms = "0x9632ac0", tyre = "0x936A91A", neon = "0x0972EFF0"},
--{ "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"},
{ "Images/Vehicles/252.png", "StreetFighter", id = 252, vms = "0x9633000", neon = "0x097272d0"},
{ "Images/Vehicles/253.png", "Virgo", id = 253, vms = "0x96332e0", tyre = "0x936BB78", neon = "0x0972EFF0"},
{ "Images/Vehicles/254.png", "Stinger", id = 254, vms = "0x9633120", tyre = "0x936BE18", neon = "0x0972EFF0"},
{ "Images/Vehicles/255.png", "BF Injection", id = 255, vms = "0x96333c0", tyre = "0x936C0B8", neon = "0x0972EFF0"},
{ "Images/Vehicles/256.png", "Pheonix", id = 256, vms = "0x96334a0", tyre = "0x936C358", neon = "0x0972EFF0"},
--{ "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"},
--{ "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"},
{ "Images/Vehicles/266.png", "Comet", id = 266, vms = "0x96340a0", tyre = "0x936DD98", neon = "0x0972EFF0"},
{ "Images/Vehicles/267.png", "Cuban Hermes", id = 267, vms = "0x9633d20", tyre = "0x936E038", neon = "0x0972EFF0"},
{ "Images/Vehicles/268.png", "FBI Rancher", id = 268, vms = "0x9633ee0", tyre = "0x936E2D8", neon = "0x0972EFF0"},
{ "Images/Vehicles/269.png", "Gang Rancher", id = 269, vms = "0x9633fc0", tyre = "0x936E578", neon = "0x0972EFF0"},
{ "Images/Vehicles/270.png", "Infernus", id = 270, vms = "0x9634180", tyre = "0x936E818", neon = "0x0972EFF0"},
{ "Images/Vehicles/271.png", "Regina", id = 271, vms = "0x9634260", tyre = "0x936EAB8", neon = "0x0972EFF0"},
{ "Images/Vehicles/272.png", "Sabre", id = 272, vms = "0x9634340", tyre = "0x936ED58", neon = "0x0972EFF0"},
{ "Images/Vehicles/273.png", "Sabre Turbo", id = 273, vms = "0x9634420", tyre = "0x936EFF8", neon = "0x0972EFF0"},
{ "Images/Vehicles/274.png", "Sentinel XS", id = 274, vms = "0x9634500", tyre = "0x936F298", neon = "0x0972EFF0"},
--{ "Images/Vehicles/275.png", "Hunter", id = 275, neon = "0x09730070"},
{ "Images/Vehicles/276.png", "Washington", id = 276, vms = "0x9634800", tyre = "0x936F7D8", neon = "0x0972EFF0"},
--{ "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/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/The Clymenus Suite.png", "The Clymenus Suite", "0x8C73B30", " 268.31, -174.98, 11.50"}
}

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
Export = false

curSave = 1
curFile = 1
FilePage = 0

--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

--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
]]--

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

{val = 1, min = 0.40, max = 2.40},--Tyre Size
{val = 1, min = 0, max = 2},--Traction Multiplier
{val = 0.75, min = 0.5, max = 1},--Traction loss
{val = 0.45, min = 0.3, max = 0.6},--Traction Bias

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

{val = 0.5, min = 0, max = 1},--Suspension Upper Limit
{val = -0.5, min = -1, max = 0},--Suspension Lower Limit
{val = 0.25, min = 0, max = 0.5},--Suspension Damping Level
{val = 1.25, min = 0, max = 2.5},--Suspension Force Level
{val = 0.5, min = 0, max = 1},--Suspension Bias
{val = 0.5, min = 0, max = 1},--Anti-Dive Multiplier

{val = 25, min = 0, max = 50},--Steering Lock
{val = 5000, min = 1000, max = 10000},--Vehilce Mass
{val = 0, min = -0.5, max = 0.5},--Centre of Mass - X
{val = 0, min = -0.5, max = 0.5},--Centre of Mass - Y
{val = 0, min = -0.5, max = 0.5},--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 = 5},
{"Wheels", min = 6, max = 9},
{"Engine", min = 10, max = 12},
{"Suspension", min = 13, max = 18},
{"Handling", min = 19, max = 23},
{"Effects", min = 24, max = 28}
}

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"}
}



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 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 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() and pad:right() ~= oldpad: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() and pad:left() ~= oldpad: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 .. " : " .. dis .. "%", UnSelectColor)

       	   --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 > 7 then
			SelPause = 1
		end
		if SelPause < 1 then
			SelPause = 7
		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

		printCentered(Plain, 240, 90, "Showroom", grey)

		if SelPause == 2 then
	 		printCentered(Plain, 240, 110, "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, 110, "Load", UnSelectColor)
		end

		if SelPause == 3 then
	 		printCentered(Plain, 240, 130, "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, 130, "Save", UnSelectColor) 
		end
	
		if SelPause == 4 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("./")
				end
				table.remove(CheatDir, 1)
				table.remove(CheatDir, 1)
			end
		else
	 		printCentered(Plain, 240, 150, "Export", UnSelectColor) 
		end

		if SelPause == 5 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 == 6 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 == 7 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:circle() and pad:circle() ~= oldpad:circle() then
				DoPalette = false
			end
			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))

			Image:fontPrint(Plain, 250, 200, "Square - Save Color To Palette", UnSelectColor)
			Image:fontPrint(Plain, 250, 220, "Cross - Use Selected Color", UnSelectColor)
			Image:fontPrint(Plain, 250, 240, "Triangle - Delete Selected Color", UnSelectColor)
			Image:fontPrint(Plain, 250, 260, "Circle - Exit And Use Selected Color", UnSelectColor)
	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)
				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 Export == true and Start == true then
		Image:fillRect(0, 0, 480, 272, MainColor)

		for c = 1,table.getn(CheatDir) do
			if c ~= curFile then
				Image:fontPrint(Plain, 10, (FilePage+c*20), CheatDir[c].name, UnSelectColor)
			end
		end
		Image:fontPrint(Plain, 10, (FilePage+curFile*20), CheatDir[curFile].name, SelectColor)

		for i = 1,10 do
			if curFile > i*14-1 and curFile < i*14 + 14 then
				 FilePage = -259*i 
			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 curFile < 14 then
			FilePage = 0
		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(CheatDir[curFile].name, "a")			
			end	

				CheatFile:write("\r\n\r\n#cheat Pimped " .. VehicleIDs[Vehicle[1][1]][2] .. " at " .. Garages[Vehicle[2][1]][2])

				CheatFile:write("\r\n //Created By Vice Mod Shop")
				CheatFile:write("\r\n //Vice Mod Shop Created By emcp")
				CheatFile:write("\r\n //Addresses Found By Vette")

				CheatFile:write("\r\n //Basics")
				CheatFile:write("\r\n setint(" .. Garages[Vehicle[2][1]][3] .. ", " .. VehicleIDs[Vehicle[1][1]].id .. ");")
				CheatFile:write("\r\n setchar(" .. Garages[Vehicle[2][1]][3] .. "+0x24, " ..  Vehicle[3].r  .. "," .. Vehicle[3].g .. "," .. Vehicle[3].b .. ", 255);")
				CheatFile:write("\r\n setchar(" .. Garages[Vehicle[2][1]][3] .. "+0x28, " ..  Vehicle[4].r  .. "," .. Vehicle[4].g .. "," .. Vehicle[4].b .. ", 255);")
			
				CheatFile:write("\r\n //Wheels")
				if VehicleIDs[Vehicle[1][1]].tyre ~= nil  then
					CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].tyre .. ", " .. Vehicle[6].val .. ", " .. Vehicle[6].val .. ");")
				end
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x6c, " .. Vehicle[7].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xc4, " .. Vehicle[8].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x70, " .. Vehicle[9].val .. ");")
			
				CheatFile:write("\r\n //Engine")
				CheatFile:write("\r\n setchar(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x5c, '" .. Drive[Vehicle[10][1]][2] .. "', '" .. Engine[Vehicle[11][1]][2] .. "', " .. Gears[Vehicle[12][1]][2] .. ");")

				CheatFile:write("\r\n //Suspension")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x7c, " .. Vehicle[13].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x80, " .. Vehicle[14].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x78, " .. Vehicle[15].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x74, " .. Vehicle[16].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x84, " .. Vehicle[17].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x88, " .. Vehicle[18].val .. ");")

				CheatFile:write("\r\n //Handling")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0x68, " .. Vehicle[19].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xbc, " .. Vehicle[20].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xa0, " .. Vehicle[21].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xa4, " .. Vehicle[22].val .. ");")
				CheatFile:write("\r\n setfloat(" .. VehicleIDs[Vehicle[1][1]].vms .. "+0xa8, " .. Vehicle[23].val .. ");")
		
					

				CheatFile:write("\r\n //Effects")				
				if  Vehicle[24].val ==  Vehicle[24].on then
					CheatFile:write("\r\n //Exhaust")
					CheatFile:write("\r\n setchar(0x09569B94,  " .. Vehicle[26].r .. ", " ..  Vehicle[26].g .. ", " ..  Vehicle[26].b .. ");")
					CheatFile:write("\r\n setchar(0x09569B90,  0x4);")
				end				
				if VehicleIDs[Vehicle[1][1]].neon ~= nil then
					if  Vehicle[25].val ==  Vehicle[25].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[27].r .. ", " ..  Vehicle[27].g .. ", " ..  Vehicle[27].b .. ");}")
					end
				end
				if Vehicle[5].val == Vehicle[5].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	
		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 then
			pause = true
		end

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

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

			if pad:up() and pad:up() ~= oldpad:up() then
				curValue = curValue-1
			end
			if pad:down() and pad:down() ~= oldpad: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 Help == false then
				if pad:right() and pad:cross() then
					Vehicle[curValue].val = Vehicle[curValue].val+(((Vehicle[curValue].max-Vehicle[curValue].min)/100)*10)
				elseif pad:right() then
					Vehicle[curValue].val = Vehicle[curValue].val+((Vehicle[curValue].max-Vehicle[curValue].min)/100)
				end

				if pad:left() and pad:cross() then
					Vehicle[curValue].val = Vehicle[curValue].val-(((Vehicle[curValue].max-Vehicle[curValue].min)/100)*10)
				elseif pad:left() then
					Vehicle[curValue].val = Vehicle[curValue].val-((Vehicle[curValue].max-Vehicle[curValue].min)/100)
				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
				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
			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)
			DrawPalette( 243.5, 200, "Base Color", "This Is The Main Color Of Your Vehilce", 3)
			DrawPalette( 243.5, 230, "Stripe Color", "This Is The Stripe Color Of Your Vehilce", 4)
			DrawCheck( 245, 265, "Teleport", "If Checked Neon Will Be Enabled", 5)
		end

		if curPage == 2 then
			if VehicleIDs[Vehicle[1][1]].tyre ~= nil  then
				DrawBar( 100, 50, "Tyre Size",  "The size of the wheels on your vehicle... Set this too high and your vehicle will be undriveable...", 6)
			end
			DrawBar( 100, 100, "Traction Multiplier",  "The cornering grip of the vehicle as a multiplier of the tyre surface friction...", 7)
			DrawBar( 100, 150, "Traction Loss",  "The accelerating/braking grip of the vehicle as a multiplier of the tyre surface friction...", 8)
			DrawBar( 100, 200, "Traction Bias",  "The ratio of front axle grip to rear axle grip... Higher values will shift the grip forwards...", 9)
		end
		if curPage == 3 then
			DrawText(100, 50, "Drive Type", "None", Drive, 10)
			DrawText(100, 70, "Engine Type", "None", Engine, 11)
			DrawText(100, 90, "Gears", "None", Gears, 12)
		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...", 13)
			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...", 14)
			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...", 15)
			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....", 16)
			DrawBar( 281, 50, "Suspension Bias",  "Ratio of suspension force applied at the front compared to the rear of the vehicle...", 17)
			DrawBar( 281, 100, "Anti-Dive Multiplier",  "The amount the vehicle leans at it's front and back when accelerating and reversing...", 18)
		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...", 19)
			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...", 20)
			DrawBar( 100, 150, "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...", 21)
			DrawBar( 100, 200, "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...", 22)
			DrawBar( 281, 50, "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..", 23)
		end
		if curPage == 6 then

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


	if Start == false then
		if StartScreen ~= nil then
			if StartScreen:time() >= 0 and StartScreen:time() < 400  then
				CreditSplash = Image.load("Images/Credits/zambia.png")	
			elseif StartScreen:time() >= 6000 and StartScreen:time() < 6400 then
				CreditSplash = Image.load("Images/Credits/sites.png")
			elseif StartScreen:time() >= 9000 and StartScreen:time() < 9400 then
				CreditSplash = Image.load("Images/Credits/emcp.png")	
			elseif StartScreen:time() >= 12000 and StartScreen:time() < 12400 then
				CreditSplash = Image.load("Images/Credits/freestyle.png")	
			elseif StartScreen:time() >= 15000 and StartScreen:time() < 15400 then
				CreditSplash = Image.load("Images/Credits/vette.png")	
			elseif StartScreen:time() >= 18000 and StartScreen:time() < 18400 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